Search in sources :

Example 1 with DLD

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

the class ORUR01Handler method updateHealthCenter.

private void updateHealthCenter(Patient patient, PV1 pv1) {
    // Update patient's location if it has changed
    if (log.isDebugEnabled()) {
        log.debug("Checking for discharge to location");
    }
    DLD dld = pv1.getDischargedToLocation();
    log.debug("DLD = " + dld);
    if (dld == null) {
        return;
    }
    IS hl7DischargeToLocation = dld.getDischargeLocation();
    log.debug("is = " + hl7DischargeToLocation);
    if (hl7DischargeToLocation == null) {
        return;
    }
    String dischargeToLocation = hl7DischargeToLocation.getValue();
    log.debug("dischargeToLocation = " + dischargeToLocation);
    if (dischargeToLocation != null && dischargeToLocation.length() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Patient discharged to " + dischargeToLocation);
        }
        // delimiter
        for (int i = 0; i < dischargeToLocation.length(); i++) {
            char ch = dischargeToLocation.charAt(i);
            if (ch == '&' || ch == '^') {
                dischargeToLocation = dischargeToLocation.substring(0, i);
                break;
            }
        }
        Integer newLocationId = Integer.parseInt(dischargeToLocation);
        // Hydrate a full patient object from patient object containing only
        // identifier
        patient = Context.getPatientService().getPatient(patient.getPatientId());
        PersonAttributeType healthCenterAttrType = Context.getPersonService().getPersonAttributeTypeByName("Health Center");
        if (healthCenterAttrType == null) {
            log.error("A person attribute type with name 'Health Center' is not defined but patient " + patient.getPatientId() + " is trying to change their health center to " + newLocationId);
            return;
        }
        PersonAttribute currentHealthCenter = patient.getAttribute("Health Center");
        if (currentHealthCenter == null || !newLocationId.toString().equals(currentHealthCenter.getValue())) {
            PersonAttribute newHealthCenter = new PersonAttribute(healthCenterAttrType, newLocationId.toString());
            log.debug("Updating patient's location from " + currentHealthCenter + " to " + newLocationId);
            // add attribute (and void old if there is one)
            patient.addAttribute(newHealthCenter);
            // save the patient and their new attribute
            Context.getPatientService().savePatient(patient);
        }
    }
    log.debug("finished discharge to location method");
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) IS(ca.uhn.hl7v2.model.v25.datatype.IS) DLD(ca.uhn.hl7v2.model.v25.datatype.DLD) PersonAttribute(org.openmrs.PersonAttribute)

Aggregations

DLD (ca.uhn.hl7v2.model.v25.datatype.DLD)1 IS (ca.uhn.hl7v2.model.v25.datatype.IS)1 PersonAttribute (org.openmrs.PersonAttribute)1 PersonAttributeType (org.openmrs.PersonAttributeType)1