private PatientAllergy getFromList(List<PatientAllergy> currentAllergies,IfPatientAllergyVo allergyFromMsg) { for (PatientAllergy patientAllergy : currentAllergies) { if(patientAllergy!=null &&patientAllergy.getAllergen()!=null &&patientAllergy.getAllergen().getId()!=null &&patientAllergy.getSourceofInformation()!=null &&allergyFromMsg!=null &&allergyFromMsg.getAllergen()!=null &&allergyFromMsg.getAllergen().getBoId()!=null &&allergyFromMsg.getSourceofInformation()!=null &&patientAllergy.getAllergen().getId().equals(allergyFromMsg.getAllergen().getBoId()) &&patientAllergy.getSourceofInformation().getId()==allergyFromMsg.getSourceofInformation().getID()) { return patientAllergy; } } return null; }
public Boolean updatePASAllergies(PatientRefVo patient,IfPatientAllergyVoCollection allergiesFromMsg) throws StaleObjectException { DomainFactory factory = getDomainFactory(); if(patient==null||allergiesFromMsg==null) //http://jira/browse/WDEV-17335 return null; List<PatientAllergy> currentAllergies = listPatientAllergies(patient, false); if(allergiesFromMsg.size()==0) //set all allergies that have PAS as sourrce of information set them to be not currently active { inactivatePASAllergies(currentAllergies,factory); } else { for (IfPatientAllergyVo msgAllergy : allergiesFromMsg) { PatientAllergy alle = getFromList(currentAllergies,msgAllergy); if(alle==null) { alle = IfPatientAllergyVoAssembler.extractPatientAllergy(factory, msgAllergy); alle.setPatient((Patient)factory.getDomainObject(Patient.class, patient.getID_Patient())); alle.setAllergenDescription(alle.getAllergen().getAllergenName()); factory.save(alle); } else if(alle.isIsCurrentlyActiveAllergy()==null //if it is null or different in the BO ||(alle.isIsCurrentlyActiveAllergy()!=null &&msgAllergy.getIsCurrentlyActiveAllergyIsNotNull() &&(!alle.isIsCurrentlyActiveAllergy().equals(msgAllergy.getIsCurrentlyActiveAllergy())))) { alle.setIsCurrentlyActiveAllergy(msgAllergy.getIsCurrentlyActiveAllergy()); factory.save(alle); } } updatePatientNoAllergyInfo(patient); //http://jira/browse/WDEV-17262 } return null; }