/** * Impl for TTO HL7 messages you finds the current I/P care context for the patient in the message (Note there will always be one open(no end/discharge date) I/P care context), then the MedicationDetails record for the care context and replace the TTO coll */ public void setPatientCareContextTTORecord(ims.clinical.vo.PatientTTOIfVo patientTTOs) { if(patientTTOs==null) throw new DomainRuntimeException("Message details are null, cannot process message"); if(patientTTOs.getPatient()==null) throw new DomainRuntimeException("Patient details are null, cannot process message"); DomainFactory factory = getDomainFactory(); CareContext careContext = getOpenInPatientCareContext(patientTTOs.getPatient()); if (careContext==null) throw new DomainRuntimeException("Open inpatient care context cannot be found for patient"); MedicationDetails md = getMedicationDetailsFromCareContext(careContext); if (md==null) throw new DomainRuntimeException("Failed to get or create Medication Details record"); md.getTTAs().clear(); md.getAdmissionMedicationChanges().clear(); Set<?> ttoFromMessage=TTODetailsIFVoAssembler.extractTTAMedicationSet(factory,patientTTOs.getTTOs() ); md.getTTAs().addAll(ttoFromMessage); Set<?> medChanges=AdmissionMedicationChangesVoAssembler.extractAdmissionMedicationChangesSet(factory, patientTTOs.getMedicationChanges()); md.getAdmissionMedicationChanges().addAll(medChanges); try { factory.save(md); } catch(StaleObjectException soe) { throw new DomainRuntimeException(soe); } }