Search in sources :

Example 11 with HL7Exception

use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.

the class ProcessHL7InQueueTask method execute.

/**
 * Process the next form entry in the database and then remove the form entry from the database.
 */
@Override
public void execute() {
    Context.openSession();
    try {
        log.debug("Processing HL7 queue ... ");
        processor.processHL7InQueue();
    } catch (HL7Exception e) {
        log.error("Error running hl7 in queue task", e);
        throw new APIException("Hl7inQueue.error.running", null, e);
    } finally {
        Context.closeSession();
    }
}
Also used : APIException(org.openmrs.api.APIException) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 12 with HL7Exception

use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.

the class ORUR01Handler method createEncounter.

/**
 * This method does not call the database to create the encounter row. The encounter is only
 * created after all obs have been attached to it Creates an encounter pojo to be attached
 * later. This method does not create an encounterId
 *
 * @param msh
 * @param patient
 * @param pv1
 * @param orc
 * @return
 * @throws HL7Exception
 */
private Encounter createEncounter(MSH msh, Patient patient, PV1 pv1, ORC orc) throws HL7Exception {
    // the encounter we will return
    Encounter encounter;
    // look for the encounter id in PV1-19
    CX visitNumber = pv1.getVisitNumber();
    Integer encounterId = null;
    try {
        encounterId = Integer.valueOf(visitNumber.getIDNumber().getValue());
    } catch (NumberFormatException e) {
    // pass
    }
    // the database
    if (encounterId != null) {
        encounter = Context.getEncounterService().getEncounter(encounterId);
    } else {
        // if no encounter_id was passed in, this is a new
        // encounter, create the object
        encounter = new Encounter();
        Date encounterDate = getEncounterDate(pv1);
        Provider provider = getProvider(pv1);
        Location location = getLocation(pv1);
        Form form = getForm(msh);
        EncounterType encounterType = getEncounterType(msh, form);
        User enterer = getEnterer(orc);
        // Date dateEntered = getDateEntered(orc); // ignore this since we have no place in the data model to store it
        encounter.setEncounterDatetime(encounterDate);
        if (unknownRole == null) {
            unknownRole = Context.getEncounterService().getEncounterRoleByUuid(EncounterRole.UNKNOWN_ENCOUNTER_ROLE_UUID);
        }
        encounter.setProvider(unknownRole, provider);
        encounter.setPatient(patient);
        encounter.setLocation(location);
        encounter.setForm(form);
        encounter.setEncounterType(encounterType);
        encounter.setCreator(enterer);
        encounter.setDateCreated(new Date());
    }
    return encounter;
}
Also used : User(org.openmrs.User) CX(ca.uhn.hl7v2.model.v25.datatype.CX) Form(org.openmrs.Form) Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Provider(org.openmrs.Provider) Location(org.openmrs.Location)

Example 13 with HL7Exception

use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.

the class ORUR01Handler method getDatetime.

/**
 * Return a java date object for the given TS
 *
 * @param ts TS to parse
 * @return date object or null
 * @throws HL7Exception
 */
private Date getDatetime(TS ts) throws HL7Exception {
    Date datetime = null;
    DTM value = ts.getTime();
    if (value.getYear() == 0 || value.getValue() == null) {
        return null;
    }
    try {
        datetime = getDate(value.getYear(), value.getMonth(), value.getDay(), value.getHour(), value.getMinute(), value.getSecond());
    } catch (DataTypeException e) {
    }
    return datetime;
}
Also used : DataTypeException(ca.uhn.hl7v2.model.DataTypeException) DTM(ca.uhn.hl7v2.model.v25.datatype.DTM) Date(java.util.Date)

Example 14 with HL7Exception

use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.

the class ORUR01Handler method getEnterer.

private User getEnterer(ORC orc) throws HL7Exception {
    XCN hl7Enterer = orc.getEnteredBy(0);
    Integer entererId = Context.getHL7Service().resolveUserId(hl7Enterer);
    if (entererId == null) {
        throw new HL7Exception(Context.getMessageSourceService().getMessage("ORUR01.error.UnresolvedEnterer"));
    }
    User enterer = new User();
    enterer.setUserId(entererId);
    return enterer;
}
Also used : XCN(ca.uhn.hl7v2.model.v25.datatype.XCN) User(org.openmrs.User) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 15 with HL7Exception

use of ca.uhn.hl7v2.HL7Exception in project openmrs-core by openmrs.

the class ORUR01Handler method getProvider.

private Provider getProvider(PV1 pv1) throws HL7Exception {
    XCN hl7Provider = pv1.getAttendingDoctor(0);
    Provider provider = null;
    String id = hl7Provider.getIDNumber().getValue();
    String assignAuth = hl7Provider.getAssigningAuthority().getUniversalID().getValue();
    String type = hl7Provider.getAssigningAuthority().getUniversalIDType().getValue();
    String errorMessage;
    if (StringUtils.hasText(id)) {
        String specificErrorMsg = "";
        if (OpenmrsUtil.nullSafeEquals("L", type)) {
            if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_ID.equalsIgnoreCase(assignAuth)) {
                try {
                    provider = Context.getProviderService().getProvider(Integer.valueOf(id));
                } catch (NumberFormatException e) {
                // ignore
                }
                specificErrorMsg = "with provider Id";
            } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_IDENTIFIER.equalsIgnoreCase(assignAuth)) {
                provider = Context.getProviderService().getProviderByIdentifier(id);
                specificErrorMsg = "with provider identifier";
            } else if (HL7Constants.PROVIDER_ASSIGNING_AUTH_PROV_UUID.equalsIgnoreCase(assignAuth)) {
                provider = Context.getProviderService().getProviderByUuid(id);
                specificErrorMsg = "with provider uuid";
            }
        } else {
            try {
                Person person = Context.getPersonService().getPerson(Integer.valueOf(id));
                Collection<Provider> providers = Context.getProviderService().getProvidersByPerson(person);
                if (!providers.isEmpty()) {
                    provider = providers.iterator().next();
                }
            } catch (NumberFormatException e) {
            // ignore
            }
            specificErrorMsg = "associated to a person with person id";
        }
        errorMessage = "Could not resolve provider " + specificErrorMsg + ":" + id;
    } else {
        errorMessage = "No unique identifier was found for the provider";
    }
    if (provider == null) {
        throw new HL7Exception(errorMessage);
    }
    return provider;
}
Also used : XCN(ca.uhn.hl7v2.model.v25.datatype.XCN) HL7Exception(ca.uhn.hl7v2.HL7Exception) Person(org.openmrs.Person) Provider(org.openmrs.Provider)

Aggregations

Message (ca.uhn.hl7v2.model.Message)36 HL7Exception (ca.uhn.hl7v2.HL7Exception)34 Test (org.junit.Test)24 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)24 ORU_R01 (ca.uhn.hl7v2.model.v25.message.ORU_R01)22 NK1 (ca.uhn.hl7v2.model.v25.segment.NK1)16 ORUR01Handler (org.openmrs.hl7.handler.ORUR01Handler)15 Person (org.openmrs.Person)11 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)10 CX (ca.uhn.hl7v2.model.v25.datatype.CX)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Patient (org.openmrs.Patient)7 APIException (org.openmrs.api.APIException)7 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)7 Segment (ca.uhn.hl7v2.model.Segment)6 Structure (ca.uhn.hl7v2.model.Structure)6 Type (ca.uhn.hl7v2.model.Type)6 PID (ca.uhn.hl7v2.model.v25.segment.PID)6 EncodingNotSupportedException (ca.uhn.hl7v2.parser.EncodingNotSupportedException)6