Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
/*
* PayableService.java
* Copyright (c) 2017 Veterans Affairs.
*/
package gov.va.oneconsult.seoc.api.model;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.springframework.format.annotation.DateTimeFormat;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import gov.va.oneconsult.seoc.api.util.ApiUtil;
import gov.va.oneconsult.seoc.api.validation.ValidCodeRequired;
/**
* Description: Service model object for the table Service.
*
* @author AbleVets
*/
@Entity
@Table(name = "service")
@JsonIgnoreProperties(value = { "seoc", "CS" })
@JsonPropertyOrder({ "id", "description", "frequency", "frequencyType", "visits", "codedBy",
"codedTimestamp", "codeRequired", "clinicalServices", "billingCodes" })
public final class PayableService
{
/**
* Id field of Service Table. Auto generated. Guaranteed not null.
*/
@Id
@Column(name = "id")
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@JsonProperty("id")
private int id;
/**
* Description Field of Service table. Null values allowed.
*/
@JsonProperty("description")
@Column(name = "description")
@Size(max = 2000, message = "Description should not exceed 2000 characters")
private String description;
/**
* Integer value of frequency. Null values allowed.
*/
@JsonProperty("frequency")
@Column(name = "frequency")
private Integer frequency;
/**
* Type of frequency defined in the frequency variable. Null values allowed.
*/
@JsonProperty("frequencyType")
@Column(name = "frequencytype")
private String frequencyType;
/**
* Integer value of auth visits. Null values allowed.
*/
@JsonProperty("visits")
@Column(name = "visits")
private Integer visits;
/**
* Defines the codeRequired value. Default value is false.
*/
@Column(name = "coderequired")
@JsonProperty("codeRequired")
@ValidCodeRequired
private String codeRequired;
/**
* Defined codedBy value for the Service. Null values allowed.
*/
@JsonProperty("codedBy")
@Column(name = "codedby")
private String codedBy;
/**
* Time stamp of coded value. Null values allowed.
*/
@Column(name = "codedtimestamp")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "MM-dd-yyyy")
@JsonProperty("codedTimestamp")
@DateTimeFormat(pattern = "MM-dd-yyyy")
private Date codedTimestamp;
/**
* {@link ClinicalService} value associated with the Service
*/
@JsonProperty("clinicalServices")
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.DETACH })
@JoinTable(name = "serviceclinicalservice", joinColumns = @JoinColumn(name = "serviceid", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "clinicalserviceid", referencedColumnName = "id"))
@Valid
private Set<ClinicalService> clinicalServices;
/**
* {@link Seoc} seoc associated with the Service object.
*/
@JsonProperty("seoc")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seocid")
@JsonIgnore
private Seoc seoc;
/**
* List of {@link BillingCode} values associated with the Service
*/
@JsonProperty("billingCodes")
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.DETACH })
@JoinTable(name = "servicebillingcode", joinColumns = @JoinColumn(name = "serviceid", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "billingcodeid", referencedColumnName = "id"))
@OrderBy("id ASC")
@Valid
private Set<BillingCode> billingCodes;
@JsonIgnore
@Transient
private Set<String> serviceHptcs;
/**
* Default constructor
*/
public PayableService()
{
}
/**
* Parameterized private constructor
* @param description
* @param frequency
* @param frequencyType
* @param visits
* @param codeRequired
* @param codedBy
* @param codedTimestamp
* @param clinicalService
* @param billingCodes
*/
private PayableService(String description, Integer frequency, String frequencyType, Integer visits,
String codeRequired, String codedBy, Date codedTimestamp, Set<ClinicalService> clinicalServices,
Set<BillingCode> billingCodes)
{
this.description = description;
this.frequency = frequency;
this.frequencyType = frequencyType;
this.visits = visits;
this.codeRequired = codeRequired;
this.codedBy = codedBy;
this.codedTimestamp = codedTimestamp;
this.clinicalServices = clinicalServices;
this.billingCodes = billingCodes;
}
/**
* Description: Deep clone of PayableService instance.
* @param noDeactivatedBillingCodes - when true, deactivated billingCodes will not be included in the cloned PayableService
* @return PayableService
*/
public PayableService deepClone(Boolean noDeactivatedBillingCodes)
{
Set<BillingCode> thatBillingCodes = new HashSet<BillingCode>();
Set<BillingCode> thisBillingCodes = this.getBillingCodes();
if(thisBillingCodes!=null && !thisBillingCodes.isEmpty())
{
thisBillingCodes.forEach(bc -> {
Boolean deactivated = bc.getDeactivated();
if (!(Boolean.TRUE.equals(noDeactivatedBillingCodes) && Boolean.TRUE.equals(deactivated))) {
thatBillingCodes.add(bc);
}
});
}
Set<ClinicalService> thatCliServices = new HashSet<ClinicalService>();
Set<ClinicalService> thisCliServices = this.getClinicalServices();
if(thisCliServices!=null && !thisCliServices.isEmpty())
{
thisCliServices.forEach(cs -> {
Boolean discontinued = cs.getDiscontinued();
if (discontinued == null || !discontinued) {
thatCliServices.add(cs);
}
});
}
PayableService thisService = new PayableService(this.description, this.frequency, this.frequencyType, this.visits,
this.codeRequired, this.codedBy, this.codedTimestamp, thatCliServices, thatBillingCodes);
return thisService;
}
/**
* Description: Deep clone of PayableService instance.
* @return PayableService
*/
public PayableService deepClone()
{
return deepClone(false);
}
/**
* @return id
*/
public int getId()
{
return id;
}
/**
* @param id
*/
public void setId(int id)
{
this.id = id;
}
/**
* @return description
*/
public String getDescription()
{
return description;
}
/**
* @param description
*/
public void setDescription(String description)
{
this.description = description;
}
/**
* @return frequency
*/
public Integer getFrequency()
{
return frequency;
}
/**
* @param frequency
*/
public void setFrequency(Integer frequency)
{
this.frequency = frequency;
}
/**
* @return frequencyType
*/
public String getFrequencyType()
{
return frequencyType;
}
/**
* @param frequencyType
*/
public void setFrequencyType(String frequencyType)
{
this.frequencyType = frequencyType;
}
/**
* @return visits
*/
public Integer getVisits()
{
return visits;
}
/**
* @param visits
*/
public void setVisits(Integer visits)
{
this.visits = visits;
}
/**
* @return codeRequired
*/
public String getCodeRequired()
{
return codeRequired;
}
/**
* @param codeRequired
*/
public void setCodeRequired(String codeRequired)
{
this.codeRequired = codeRequired;
}
/**
*
* @param compareVal - value to compare to codeRequired
* @return codeRequired equals compareVal, case-insensitive and without extra spaces
*/
public boolean codeRequiredEquals(String compareVal)
{
return codeRequired != null && codeRequired.trim().equalsIgnoreCase(compareVal.trim());
}
/**
* @return codedBy
*/
public String getCodedBy()
{
return codedBy;
}
/**
* @param codedBy
*/
public void setCodedBy(String codedBy)
{
this.codedBy = codedBy;
}
/**
* @return codedTimestamp
*/
public Date getCodedTimestamp()
{
return codedTimestamp;
}
/**
* @param codedTimestamp
*/
public void setCodedTimestamp(Date codedTimestamp)
{
this.codedTimestamp = ApiUtil.getUTCZoneDateTime(codedTimestamp);
}
/**
* @return Set<ClinicalService>
*/
public Set<ClinicalService> getClinicalServices()
{
return clinicalServices;
}
/**
* @param clinicalServices
*/
public void setClinicalServices(Set<ClinicalService> clinicalServices)
{
this.clinicalServices = clinicalServices;
}
/**
* @return seoc
*/
public Seoc getSeoc()
{
return seoc;
}
/**
* @param seoc
*/
public void setSeoc(Seoc seoc)
{
this.seoc = seoc;
}
/**
* @return billingCodes
*/
public Set<BillingCode> getBillingCodes()
{
return billingCodes;
}
/**
* @param billingCodes
*/
public void setBillingCodes(Set<BillingCode> billingCodes)
{
this.billingCodes = billingCodes;
}
/**
* Description:
* @return Set<String>
*/
public Set<String> getServiceHptcs()
{
return serviceHptcs;
}
/**
* Description:
* @param serviceHptcs
*/
public void setServiceHptcs(Set<String> serviceHptcs)
{
this.serviceHptcs = serviceHptcs;
}
/**
* Description: Remove Billing Code from the Service
* @param billingCode
*/
@Transient
public void removeBillingCode(BillingCode billingCode)
{
Set<BillingCode> billingCodes = this.getBillingCodes();
if(billingCodes==null || billingCodes.isEmpty()) {
return;
}
if(billingCodes.contains(billingCode)) {
billingCodes.remove(billingCode);
}
}
/**
* Description: If a service contains old billing code, remove old billing code and add new billing code
* @param prevBC Previous Billing Code
* @param newBC New Billing Code
*/
@Transient
public void updateBillingCode(BillingCode prevBC, BillingCode newBC)
{
Set<BillingCode> billingCodes = this.getBillingCodes();
Set<BillingCode> newBillingCodes = new HashSet<BillingCode>();
if(billingCodes==null || billingCodes.isEmpty()) {
return;
}
boolean foundBC = billingCodes.stream().anyMatch(bc -> bc.getBillingCode().equalsIgnoreCase(prevBC.getBillingCode()));
if(foundBC) {
//Filter out all billing codes which do not match with the previous billing code
newBillingCodes = billingCodes.stream().filter(bc -> !bc.getBillingCode().equalsIgnoreCase(prevBC.getBillingCode())).collect(Collectors.toSet());
newBillingCodes.add(newBC);
this.setBillingCodes(newBillingCodes);
}
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((billingCodes == null) ? 0 : billingCodes.hashCode());
result = prime * result + ((clinicalServices == null) ? 0 : clinicalServices.hashCode());
result = prime * result + ((codeRequired == null) ? 0 : codeRequired.hashCode());
result = prime * result + ((codedBy == null) ? 0 : codedBy.hashCode());
result = prime * result + ((codedTimestamp == null) ? 0 : codedTimestamp.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((frequency == null) ? 0 : frequency.hashCode());
result = prime * result + ((frequencyType == null) ? 0 : frequencyType.hashCode());
result = prime * result + id;
result = prime * result + ((seoc == null) ? 0 : seoc.getId());
result = prime * result + ((visits == null) ? 0 : visits.hashCode());
;
return result;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj)
{
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
PayableService other = (PayableService) obj;
if (billingCodes == null) {
if (other.billingCodes != null) {
return false;
}
} else if (!billingCodes.equals(other.billingCodes)) {
return false;
}
if (clinicalServices == null) {
if (other.clinicalServices != null) {
return false;
}
} else if (!clinicalServices.equals(other.clinicalServices)) {
return false;
}
if (codeRequired == null) {
if (other.codeRequired != null) {
return false;
}
} else if (!codeRequired.equals(other.codeRequired)) {
return false;
}
if (codedBy == null) {
if (other.codedBy != null) {
return false;
}
} else if (!codedBy.equals(other.codedBy)) {
return false;
}
if (codedTimestamp == null) {
if (other.codedTimestamp != null) {
return false;
}
} else if (!codedTimestamp.equals(other.codedTimestamp)) {
return false;
}
if (description == null) {
if (other.description != null) {
return false;
}
} else if (!description.equals(other.description)) {
return false;
}
if (!frequency.equals(other.frequency)) {
return false;
}
if (frequencyType == null) {
if (other.frequencyType != null) {
return false;
}
} else if (!frequencyType.equals(other.frequencyType)) {
return false;
}
if (id != other.id) {
return false;
}
if (seoc == null) {
if (other.seoc != null) {
return false;
}
} else if (!seoc.equals(other.seoc)) {
return false;
}
if (!visits.equals(other.visits)) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
@Override
public String toString()
{
return "AuthorizedService [id=" + id + ", description=" + description + ", frequency="
+ frequency + ", frequencyType=" + frequencyType + ", visits=" + visits
+ ", codeRequired=" + codeRequired + ", codedBy=" + codedBy + ", codedTimestamp="
+ codedTimestamp + ", clinicalServices=" + clinicalServices + ", billingCodes="
+ billingCodes + ", serviceHptcs =" + serviceHptcs + "]";
}
}