package com.integer.oncomed.entity; import com.haulmont.chile.core.annotations.MetaProperty; import com.haulmont.chile.core.annotations.NamePattern; import com.haulmont.cuba.core.entity.annotation.OnDelete; import com.haulmont.cuba.core.global.DeletePolicy; import com.integer.oncomed.utils.DateAdapter; import javax.persistence.*; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Date; import java.util.List; //@XmlType(propOrder = {"id","operationDate","surgeon","anesthesist","anesthesy","code", // "description","surgicalOperationType","surgicalTreatment"},name = "surgicalOperation") @Entity(name = "oncomed$SurgicalOperation") @Table(name = "ONCOMED_SURGICAL_OPERATION") @NamePattern("%s|opName") @XmlRootElement(name = "SurgicalOperation") @XmlAccessorType(XmlAccessType.NONE) public class SurgicalOperation extends Treatment { @XmlElementWrapper @XmlElement(name = "surgicalComplications") public List getSurgicalComplications() { return surgicalComplications; } public void setSurgicalComplications(List surgicalComplications) { this.surgicalComplications = surgicalComplications; } @OneToMany(mappedBy = "surgicalOperation", fetch = FetchType.EAGER) @OnDelete(DeletePolicy.CASCADE) protected List surgicalComplications; @Temporal(TemporalType.TIMESTAMP) @Column(name = "OPERATION_DATE") protected Date operationDate; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "SURGEON_ID") protected Doctor surgeon; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ANESTHESIST_ID") protected Doctor anesthesist; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ANESTHESY_ID") protected DictionaryValue anesthesy; @Column(name = "CODE") protected String code; @Column(name = "DESCRIPTION") protected String description; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "SURGICAL_OPERATION_TYPE_ID") protected SurgicalOperationType surgicalOperationType; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "SURGICAL_TREATMENT_ID") protected SurgicalTreatment surgicalTreatment; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "ASSISTANT_ID") protected Doctor assistant; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "SPECIAL_EQUIPMENT") protected DictionaryValue specialEquipment; @Column(name = "ISMAIN") protected Boolean isMain; @Transient protected String opName; @Column(name = "special_app") protected String specialApp; public SurgicalOperation() { } public SurgicalOperation(SurgicalTreatment surgicalTreatment) { this.surgicalTreatment = surgicalTreatment; } public String getSpecialApp() { return specialApp; } public void setSpecialApp(String specialApp) { this.specialApp = specialApp; } @MetaProperty public String getOpName() { return this.getSurgicalOperationType() != null ? this.getSurgicalOperationType().getName() : ""; } @XmlElement(name = "anesthesist") public Doctor getAnesthesist() { return anesthesist; } public void setAnesthesist(Doctor anesthesist) { this.anesthesist = anesthesist; } public SurgicalTreatment getSurgicalTreatment() { return surgicalTreatment; } public void setSurgicalTreatment(SurgicalTreatment surgicalTreatment) { this.surgicalTreatment = surgicalTreatment; } @XmlElement(name = "operationDate") @XmlJavaTypeAdapter(DateAdapter.class) public Date getOperationDate() { return operationDate; } public void setOperationDate(Date operationDate) { this.operationDate = operationDate; } @XmlElement(name = "surgeon") public Doctor getSurgeon() { return surgeon; } public void setSurgeon(Doctor surgeon) { this.surgeon = surgeon; } @XmlElement(name = "code") public String getCode() { return code; } public void setCode(String code) { this.code = code; } @XmlElement(name = "description") public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } @XmlElement(name = "surgicalOperationType") public SurgicalOperationType getSurgicalOperationType() { return surgicalOperationType; } public void setSurgicalOperationType(SurgicalOperationType surgicalOperationType) { this.surgicalOperationType = surgicalOperationType; } @XmlElement(name = "anesthesy") public DictionaryValue getAnesthesy() { return anesthesy; } public void setAnesthesy(DictionaryValue anesthesy) { this.anesthesy = anesthesy; } @XmlElement(name = "assistant") public Doctor getAssistant() { return assistant; } public void setAssistant(Doctor assistant) { this.assistant = assistant; } public int compareTo(Object obj) { if (obj.getClass().equals(RadiationTreatment.class)) { if (this.getOperationDate().before(((RadiationTreatment) obj).getStartDate())) return -1; else return (this.getOperationDate().after((((RadiationTreatment) obj).getStartDate()))) ? 1 : 0; } else if (obj.getClass().equals(SurgicalOperation.class)) { if (this.getOperationDate().before(((SurgicalOperation) obj).getOperationDate())) return -1; else return (this.getOperationDate().after((((SurgicalOperation) obj).getOperationDate()))) ? 1 : 0; } else if (this.getOperationDate().before(((DrugUsage) obj).getStartDate())) return -1; else return (this.getOperationDate().after((((DrugUsage) obj).getStartDate()))) ? 1 : 0; } public DictionaryValue getSpecialEquipment() { return specialEquipment; } public void setSpecialEquipment(DictionaryValue specialEquipment) { this.specialEquipment = specialEquipment; } @XmlElement(name = "isMain") public Boolean getIsMain() { return isMain; } public void setIsMain(Boolean isMain) { this.isMain = isMain; } }