Red Hat Application Migration Toolkit
package com.mpdmal.cloudental.entities; import com.mpdmal.cloudental.entities.Activity; import com.mpdmal.cloudental.entities.Address; import com.mpdmal.cloudental.entities.Contactinfo; import com.mpdmal.cloudental.entities.Dentist; import com.mpdmal.cloudental.entities.Medicalhistory; import com.mpdmal.cloudental.entities.Patienthistory; import com.mpdmal.cloudental.entities.Patienttooth; import com.mpdmal.cloudental.entities.base.DBEntity; import com.mpdmal.cloudental.util.CloudentUtils; import com.mpdmal.cloudental.util.CloudentUtils.AddressType; import com.mpdmal.cloudental.util.CloudentUtils.ContactInfoType; import com.mpdmal.cloudental.util.exception.base.CloudentException; import java.io.Serializable; import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import javax.persistence.CascadeType; 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.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotEmpty; @Entity public class Patient extends DBEntity implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue( strategy = GenerationType.IDENTITY ) private Integer id; private String comments; @NotNull @Temporal(TemporalType.TIMESTAMP) private Date created; @NotNull @NotEmpty private String name; @NotNull @NotEmpty private String surname; @NotNull @OneToOne( cascade = {CascadeType.ALL}, mappedBy = "patient", fetch = FetchType.LAZY ) private Medicalhistory medicalhistory; @NotNull @OneToOne( cascade = {CascadeType.ALL}, mappedBy = "patient" ) private Patienthistory dentalhistory; @NotNull @ManyToOne @JoinColumn( name = "dentistid" ) private Dentist dentist; @OneToMany( cascade = {CascadeType.ALL}, mappedBy = "patient", fetch = FetchType.LAZY ) private Set addresses; @OneToMany( cascade = {CascadeType.ALL}, mappedBy = "patient", fetch = FetchType.LAZY ) private Set contactinfo; @OneToMany( cascade = {CascadeType.ALL}, mappedBy = "patient", fetch = FetchType.LAZY ) private Set teeth; public Date getCreated() { return this.created; } public Integer getId() { return this.id; } public String getComments() { return this.comments; } public String getName() { return this.name; } public String getSurname() { return this.surname; } public Dentist getDentist() { return this.dentist; } public Medicalhistory getMedicalhistory() { return this.medicalhistory; } public Patienthistory getDentalHistory() { return this.dentalhistory; } public Set getAddresses() { return this.addresses; } public Set getContactInfo() { return this.contactinfo; } public Set getTeeth() { return this.teeth; } public void setId(Integer id) { this.id = id; } public void setComments(String comments) { this.comments = comments; } public void setCreated(Date created) { this.created = created; } public void setName(String name) { this.name = name; } public void setSurname(String surname) { this.surname = surname; } public void setDentist(Dentist dentist) { this.dentist = dentist; } public void setMedicalhistory(Medicalhistory medicalhistory) { this.medicalhistory = medicalhistory; } public void setDentalhistory(Patienthistory dentalhistory) { dentalhistory.setPatient(this); this.dentalhistory = dentalhistory; } public void setAddresses(Set adrs) { if(this.addresses == null) { this.addresses = new HashSet(); } else { this.addresses.clear(); } Iterator var2 = adrs.iterator(); while(var2.hasNext()) { Address address = (Address)var2.next(); this.addAddress(address); } } public void addAddress(Address adrs) { if(this.addresses == null) { this.addresses = new HashSet(); } Iterator var2 = this.addresses.iterator(); Address address; do { if(!var2.hasNext()) { this.addresses.add(adrs); return; } address = (Address)var2.next(); } while(address.getId().getAdrstype() != adrs.getId().getAdrstype() || !address.getCity().equals(adrs.getCity()) || !address.getCountry().equals(adrs.getCountry()) || !address.getNumber().equals(adrs.getNumber()) || !address.getPostalcode().equals(adrs.getPostalcode()) || !address.getStreet().equals(adrs.getStreet())); CloudentUtils.logWarning("Address already exists, wont add:" + adrs.getStreet()); } public void setContactInfo(Set cnt) { if(this.contactinfo == null) { this.contactinfo = new HashSet(); } else { this.contactinfo.clear(); } Iterator var2 = cnt.iterator(); while(var2.hasNext()) { Contactinfo contactinfo = (Contactinfo)var2.next(); this.addContactInfo(contactinfo); } } public void addContactInfo(Contactinfo cnt) { if(this.contactinfo == null) { this.contactinfo = new HashSet(); } cnt.setPatient(this); this.contactinfo.add(cnt); } public void updateContactInfo(Contactinfo cnt) { Iterator var2 = this.contactinfo.iterator(); Contactinfo info; do { if(!var2.hasNext()) { return; } info = (Contactinfo)var2.next(); } while(!info.getId().getInfotype().equals(cnt.getId().getInfotype())); info.setId(cnt.getId()); info.setInfo(cnt.getInfo()); } public void setTeeth(Set teeth) { if(this.teeth != null) { this.teeth.clear(); } Iterator var2 = teeth.iterator(); while(var2.hasNext()) { Patienttooth patienttooth = (Patienttooth)var2.next(); this.addTooth(patienttooth); } } public void addTooth(Patienttooth tooth) { if(this.teeth == null) { this.teeth = new HashSet(); } tooth.setPatient(this); this.teeth.add(tooth); } public Contactinfo getFax() { return this.getCinfo(ContactInfoType.FAX.getValue()); } public Contactinfo getEmail() { return this.getCinfo(ContactInfoType.EMAIL.getValue()); } public Contactinfo getHomeNumber() { return this.getCinfo(ContactInfoType.HOME.getValue()); } public Contactinfo getOfficeNumber() { return this.getCinfo(ContactInfoType.OFFICE.getValue()); } public Contactinfo getMobileNumber() { return this.getCinfo(ContactInfoType.MOBILE.getValue()); } public Address getOfficeAddress() { return this.getAddress(AddressType.OFFICE.getValue()); } public Address getBillingAddress() { return this.getAddress(AddressType.BILLING.getValue()); } public Address getHomeAddress() { return this.getAddress(AddressType.HOME.getValue()); } public String getXML() { StringBuilder ans = new StringBuilder("<patient></patient>"); ans.insert(ans.indexOf("</patient"), "<id>" + this.id + "</id>"); ans.insert(ans.indexOf("</patient"), "<name>" + this.name + "</name>"); ans.insert(ans.indexOf("</patient"), "<surname>" + this.surname + "</surname>"); ans.insert(ans.indexOf("</patient"), "<created>" + this.created + "</created>"); ans.insert(ans.indexOf("</patient"), "<comments>" + this.comments + "</comments>"); ans.insert(ans.indexOf("</patient"), "<contactinfo>"); Iterator var2 = this.contactinfo.iterator(); while(var2.hasNext()) { Contactinfo tooth = (Contactinfo)var2.next(); ans.insert(ans.indexOf("</patient"), tooth.getXML()); } var2 = this.addresses.iterator(); while(var2.hasNext()) { Address tooth1 = (Address)var2.next(); ans.insert(ans.indexOf("</patient"), tooth1.getXML()); } ans.insert(ans.indexOf("</patient"), "</contactinfo>"); ans.insert(ans.indexOf("</patient"), this.medicalhistory.getXML()); ans.insert(ans.indexOf("</patient"), "<mouth>"); var2 = this.teeth.iterator(); while(var2.hasNext()) { Patienttooth tooth2 = (Patienttooth)var2.next(); ans.insert(ans.indexOf("</patient"), tooth2.getXML()); } ans.insert(ans.indexOf("</patient"), "</mouth>"); ans.insert(ans.indexOf("</patient"), this.dentalhistory.getXML()); return ans.toString(); } public String unboxPatient() { String ans = this.id + " " + this.name + " " + this.surname; Iterator var2 = this.dentalhistory.getActivities().iterator(); Activity act; do { if(!var2.hasNext()) { return ans; } act = (Activity)var2.next(); } while(!act.getDescription().equals("def act| cdent")); return ans + " " + act.getId(); } public static Patient boxPatient(String value) throws CloudentException { Patient ans = new Patient(); String[] vals = value.split(" "); ans.setId(Integer.valueOf(Integer.parseInt(vals[0]))); ans.setName(vals[1]); ans.setSurname(vals[2]); if(vals.length == 4) { Patienthistory ph = new Patienthistory(); Activity activity = new Activity(); activity.setId(Integer.valueOf(Integer.parseInt(vals[3]))); ph.addActivity(activity); ans.setDentalhistory(ph); } return ans; } private Address getAddress(int type) { Iterator var2 = this.addresses.iterator(); Address adrs; do { if(!var2.hasNext()) { return null; } adrs = (Address)var2.next(); } while(adrs.getId().getAdrstype().intValue() != type); return adrs; } private Contactinfo getCinfo(int type) { Iterator var2 = this.contactinfo.iterator(); Contactinfo cinfo; do { if(!var2.hasNext()) { return null; } cinfo = (Contactinfo)var2.next(); } while(cinfo.getId().getInfotype().intValue() != type); return cinfo; } public String getUIFriendlyString() { return this.name + " " + this.surname; } }