Search in sources :

Example 1 with EI

use of ca.uhn.hl7v2.model.v25.datatype.EI in project openmrs-core by openmrs.

the class ORUR01Handler method getForm.

/**
 * needs to find a Form based on information in MSH-21. example: 16^AMRS.ELD.FORMID
 *
 * @param msh
 * @return
 * @should pass if return value is null when uuid and id is null
 * @should pass if return value is not null when uuid or id is not null
 * @throws HL7Exception
 */
public Form getForm(MSH msh) throws HL7Exception {
    String uuid = null;
    String id = null;
    for (EI identifier : msh.getMessageProfileIdentifier()) {
        if (identifier != null && identifier.getNamespaceID() != null) {
            String identifierType = identifier.getNamespaceID().getValue();
            if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_UUID)) {
                uuid = identifier.getEntityIdentifier().getValue();
            } else if (OpenmrsUtil.nullSafeEquals(identifierType, HL7Constants.HL7_FORM_ID)) {
                id = identifier.getEntityIdentifier().getValue();
            } else {
                log.warn("Form identifier type of " + identifierType + " unknown to ORU R01 processor.");
            }
        }
    }
    Form form = null;
    if (uuid == null && id == null) {
        return form;
    }
    // prefer uuid over id
    if (uuid != null) {
        form = Context.getFormService().getFormByUuid(uuid);
    }
    // if uuid did not work ...
    if (id != null) {
        try {
            Integer formId = Integer.parseInt(id);
            form = Context.getFormService().getForm(formId);
        } catch (NumberFormatException e) {
            throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.parseFormId"), e);
        }
    }
    return form;
}
Also used : EI(ca.uhn.hl7v2.model.v25.datatype.EI) Form(org.openmrs.Form) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Aggregations

HL7Exception (ca.uhn.hl7v2.HL7Exception)1 EI (ca.uhn.hl7v2.model.v25.datatype.EI)1 Form (org.openmrs.Form)1