Search in sources :

Example 1 with ADT_A05

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;
}
Also used : MSH(ca.uhn.hl7v2.model.v25.segment.MSH) HL7Exception(ca.uhn.hl7v2.HL7Exception) Patient(org.openmrs.Patient) PID(ca.uhn.hl7v2.model.v25.segment.PID)

Example 2 with ADT_A05

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;
}
Also used : ADT_A05(ca.uhn.hl7v2.model.v25.message.ADT_A05) ApplicationException(ca.uhn.hl7v2.app.ApplicationException) Message(ca.uhn.hl7v2.model.Message) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Aggregations

HL7Exception (ca.uhn.hl7v2.HL7Exception)2 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)1 Message (ca.uhn.hl7v2.model.Message)1 ADT_A05 (ca.uhn.hl7v2.model.v25.message.ADT_A05)1 MSH (ca.uhn.hl7v2.model.v25.segment.MSH)1 PID (ca.uhn.hl7v2.model.v25.segment.PID)1 Patient (org.openmrs.Patient)1