use of ca.uhn.hl7v2.model.v25.message.ADT_A05 in project openmrs-core by openmrs.
the class ADTA28Handler method processADT_A28.
private Message processADT_A28(ADT_A05 adt) throws HL7Exception {
// validate HL7 version
validate(adt);
// extract segments for convenient use below
MSH msh = getMSH(adt);
PID pid = getPID(adt);
// Obtain message control id (unique ID for message from sending
// application). Eventually avoid replaying the same message.
String messageControlId = msh.getMessageControlID().getValue();
log.debug("Found HL7 message in inbound queue with control id = " + messageControlId);
// Add creator of the patient to application
String sendingApp = msh.getSendingApplication().getComponent(0).toString();
log.debug("SendingApplication = " + sendingApp);
// Search for the patient
Integer patientId = findPatientId(pid);
// Create new patient if the patient id doesn't exist yet
if (patientId == null) {
log.info("Creating new patient in response to ADT_A28 " + messageControlId);
Patient patient = createPatient(pid, sendingApp);
if (patient == null) {
throw new HL7Exception("Couldn't create Patient object from PID");
}
Context.getPatientService().savePatient(patient);
} else {
log.info("Ignoring ADT_A28 message because patient (" + patientId + ") already exists.");
}
return adt;
}
use of ca.uhn.hl7v2.model.v25.message.ADT_A05 in project openmrs-core by openmrs.
the class ADTA28Handler method processMessage.
/**
* Processes an ADT A28 event message
*/
@Override
public Message processMessage(Message message) throws ApplicationException {
log.debug("Processing ADT_A28 message");
if (!(message instanceof ADT_A05)) {
throw new ApplicationException("Invalid message sent to ADT_A28 handler");
}
Message response;
try {
ADT_A05 adt = (ADT_A05) message;
response = processADT_A28(adt);
} catch (ClassCastException e) {
log.error("Error casting " + message.getClass().getName() + " to ADT_A28", e);
throw new ApplicationException("Invalid message type for handler");
} catch (HL7Exception e) {
log.error("Error while processing ADT_A28 message", e);
throw new ApplicationException(e);
}
log.debug("Finished processing ADT_A28 message");
return response;
}
Aggregations