Search in sources :

Example 1 with AddressHierarchyLevel

use of org.openmrs.module.addresshierarchy.AddressHierarchyLevel in project openmrs-module-mirebalais by PIH.

the class PatientRegistrationApp method getAddressQuestion.

public Question getAddressQuestion(Config config) {
    Question q = new Question();
    q.setId("personAddressQuestion");
    q.setLegend("registrationapp.patient.address");
    q.setHeader("registrationapp.patient.address.question");
    Field f = new Field();
    f.setType("personAddress");
    // If there are address hierarchy levels configured, use the address hierarchy widget, otherwise use the standard address widget
    List<AddressHierarchyLevel> levels = Context.getService(AddressHierarchyService.class).getAddressHierarchyLevels();
    if (levels != null && levels.size() > 0) {
        q.setDisplayTemplate(getAddressHierarchyDisplayTemplate(levels));
        f.setWidget(getAddressHierarchyWidget(levels, null, true));
    } else {
        Map<String, String> m = new HashMap<String, String>();
        m.put("providerName", "uicommons");
        m.put("fragmentId", "field/personAddress");
        f.setWidget(toObjectNode(m));
    }
    q.addField(f);
    return q;
}
Also used : AddressField(org.openmrs.module.addresshierarchy.AddressField) Field(org.openmrs.module.registrationapp.model.Field) HashMap(java.util.HashMap) Question(org.openmrs.module.registrationapp.model.Question) AddressHierarchyLevel(org.openmrs.module.addresshierarchy.AddressHierarchyLevel) AddressHierarchyService(org.openmrs.module.addresshierarchy.service.AddressHierarchyService)

Example 2 with AddressHierarchyLevel

use of org.openmrs.module.addresshierarchy.AddressHierarchyLevel in project openmrs-module-mirebalais by PIH.

the class PatientRegistrationApp method getBirthplaceQuestion.

public Question getBirthplaceQuestion(Config config) {
    Question q = new Question();
    q.setId("birthplaceLabel");
    q.setHeader("zl.registration.patient.birthplace.question");
    q.setLegend("zl.registration.patient.birthplace.label");
    if (config.getCountry().equals(ConfigDescriptor.Country.HAITI)) {
        Field f = new Field();
        // f.setFormFieldName("obsgroup.PIH:PATIENT CONTACTS CONSTRUCT.obs.PIH:ADDRESS OF PATIENT CONTACT");
        f.setLabel("zl.registration.patient.birthplace.label");
        f.setType("personAddress");
        // If there are address hierarchy levels configured, use the address hierarchy widget, otherwise use the standard address widget
        List<AddressHierarchyLevel> levels = Context.getService(AddressHierarchyService.class).getAddressHierarchyLevels();
        if (levels != null && levels.size() > 0) {
            // q.setDisplayTemplate(getAddressHierarchyDisplayTemplate(levels));
            f.setWidget(getAddressHierarchyWidget(levels, getPlaceOfBirthAddressFieldMappings(config), true));
        } else {
            Map<String, String> m = new HashMap<String, String>();
            m.put("providerName", "uicommons");
            m.put("fragmentId", "field/personAddress");
            f.setWidget(toObjectNode(m));
        }
        q.addField(f);
    } else {
        Field f = new Field();
        f.setFormFieldName("obs.PIH:PLACE OF BIRTH");
        f.setType("obs");
        f.setWidget(getTextFieldWidget(50));
        q.addField(f);
    }
    return q;
}
Also used : AddressField(org.openmrs.module.addresshierarchy.AddressField) Field(org.openmrs.module.registrationapp.model.Field) HashMap(java.util.HashMap) Question(org.openmrs.module.registrationapp.model.Question) AddressHierarchyLevel(org.openmrs.module.addresshierarchy.AddressHierarchyLevel) AddressHierarchyService(org.openmrs.module.addresshierarchy.service.AddressHierarchyService)

Example 3 with AddressHierarchyLevel

use of org.openmrs.module.addresshierarchy.AddressHierarchyLevel in project openmrs-module-mirebalais by PIH.

the class WristbandTemplate method generateWristband.

public String generateWristband(Patient patient, Location location) {
    // TODO figure out why this isn't getting autowired properly (at least for tests)
    if (addressHierarchyService == null) {
        addressHierarchyService = Context.getService(AddressHierarchyService.class);
    }
    StringBuffer data = new StringBuffer();
    data.append("^XA");
    // specify Unicode encoding
    data.append("^CI28");
    // set direct transfer type
    data.append("^MTD");
    // set orientation
    data.append("^FWB");
    // visit location & current data
    data.append("^FO050,200^FB2150,1,0,L,0^AS^FD" + adtService.getLocationThatSupportsVisits(location).getName() + " " + fullDate.format(new Date()) + "^FS");
    // patient name: for now, only printing given and family names
    String patientName = null;
    if (patient.getPersonName() != null) {
        patientName = (patient.getPersonName().getGivenName() != null ? patient.getPersonName().getGivenName() : "") + " " + (patient.getPersonName().getFamilyName() != null ? patient.getPersonName().getFamilyName() : "");
    }
    data.append("^FO100,200^FB2150,1,0,L,0^AU^FD" + patientName + "^FS");
    if (patient.getBirthdate() != null) {
        // birthdate (we only show year if birthdate is estimated
        DateFormat df = patient.getBirthdateEstimated() ? yearOnly : fullDate;
        data.append("^FO160,200^FB2150,1,0,L,0^AU^FD" + df.format(patient.getBirthdate()) + "^FS");
    }
    if (patient.getAge() != null) {
        // age
        data.append("^FO160,200^FB1850,1,0,L,0^AT^FD" + messageSourceService.getMessage("coreapps.ageYears", Collections.singletonList(patient.getAge()).toArray(), locale) + "^FS");
    }
    // gender
    data.append("^FO160,200^FB1650,1,0,L,0^AU^FD" + messageSourceService.getMessage("coreapps.gender." + patient.getGender(), null, locale) + "  ");
    // paper record identifier
    PatientIdentifier paperRecordIdentifier = getAppropriatePaperRecordIdentifierForLocation(patient, location);
    if (paperRecordIdentifier != null) {
        data.append(paperRecordIdentifier.getIdentifier().substring(0, paperRecordIdentifier.getIdentifier().length() - 6) + " " + paperRecordIdentifier.getIdentifier().substring(paperRecordIdentifier.getIdentifier().length() - 6));
    }
    data.append("^FS");
    // address (based on address hierarchy)
    PersonAddress address = patient.getPersonAddress();
    AddressHierarchyLevel level = addressHierarchyService.getBottomAddressHierarchyLevel();
    int numberOfLevels = addressHierarchyService.getAddressHierarchyLevelsCount();
    if (address != null && numberOfLevels > 0) {
        int levelCount = 1;
        if (LOWEST_LEVEL_ON_SEPARATE_LINE) {
            String lowestLevelStr = AddressHierarchyUtil.getAddressFieldValue(address, level.getAddressField());
            if (StringUtils.isNotBlank(address.getAddress2())) {
                data.append("^FO220,200^FB2150,1,0,L,0^AS^FD" + lowestLevelStr + "^FS");
            }
            levelCount++;
        }
        StringBuffer addressStr = new StringBuffer();
        while (levelCount < numberOfLevels || (!SKIP_HIGHEST_LEVEL && levelCount <= numberOfLevels) && level.getParent() != null) {
            // level.getParent() should never equal null as long as levelCount <= numberOfLevels, but just to be safe we will check
            level = level.getParent();
            String levelStr = AddressHierarchyUtil.getAddressFieldValue(address, level.getAddressField());
            if (StringUtils.isNotBlank(levelStr)) {
                addressStr.append(levelStr + ", ");
            }
            levelCount++;
        }
        if (StringUtils.isNotBlank(addressStr.toString())) {
            // trim off trailing comma and space
            addressStr.delete(addressStr.length() - 2, addressStr.length());
            data.append("^FO270,200^FB2150,1,0,L,0^AS^FD" + addressStr.toString() + "^FS");
        }
    }
    // barcode with primary identifier
    PatientIdentifier primaryIdentifier = patient.getPatientIdentifier(emrApiProperties.getPrimaryIdentifierType());
    if (primaryIdentifier != null) {
        data.append("^FO100,2400^AT^BY4^BC,150,N^FD" + primaryIdentifier.getIdentifier() + "^XZ");
    }
    return data.toString();
}
Also used : PersonAddress(org.openmrs.PersonAddress) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) AddressHierarchyService(org.openmrs.module.addresshierarchy.service.AddressHierarchyService) Date(java.util.Date) PatientIdentifier(org.openmrs.PatientIdentifier) AddressHierarchyLevel(org.openmrs.module.addresshierarchy.AddressHierarchyLevel)

Example 4 with AddressHierarchyLevel

use of org.openmrs.module.addresshierarchy.AddressHierarchyLevel in project openmrs-module-pihcore by PIH.

the class WristbandTemplateTest method setupAddressHierarchyLevels.

private void setupAddressHierarchyLevels() {
    AddressHierarchyLevel country = new AddressHierarchyLevel();
    country.setAddressField(AddressField.COUNTRY);
    AddressHierarchyLevel state = new AddressHierarchyLevel();
    state.setAddressField(AddressField.STATE_PROVINCE);
    state.setParent(country);
    AddressHierarchyLevel city = new AddressHierarchyLevel();
    city.setAddressField(AddressField.CITY_VILLAGE);
    city.setParent(state);
    AddressHierarchyLevel address3 = new AddressHierarchyLevel();
    address3.setAddressField(AddressField.ADDRESS_3);
    address3.setParent(city);
    AddressHierarchyLevel address1 = new AddressHierarchyLevel();
    address1.setAddressField(AddressField.ADDRESS_1);
    address1.setParent(address3);
    AddressHierarchyLevel address2 = new AddressHierarchyLevel();
    address2.setAddressField(AddressField.ADDRESS_2);
    address2.setParent(address1);
    when(addressHierarchyService.getBottomAddressHierarchyLevel()).thenReturn(address2);
    when(addressHierarchyService.getAddressHierarchyLevelsCount()).thenReturn(6);
}
Also used : AddressHierarchyLevel(org.openmrs.module.addresshierarchy.AddressHierarchyLevel)

Example 5 with AddressHierarchyLevel

use of org.openmrs.module.addresshierarchy.AddressHierarchyLevel in project openmrs-module-pihcore by PIH.

the class AddressBundle method updateRequiredProperty.

/**
 * Iterate through the levels and update the "required" property in case it has changed
 */
public void updateRequiredProperty() {
    AddressHierarchyService service = Context.getService(AddressHierarchyService.class);
    log.info("Installing Address Levels");
    for (AddressComponent component : getAddressComponents()) {
        AddressHierarchyLevel level = service.getAddressHierarchyLevelByAddressField(component.getField());
        if (level != null) {
            level.setRequired(component.isRequiredInHierarchy());
            service.saveAddressHierarchyLevel(level);
        } else {
            log.warn("AddressHierarchyLevel is null for AddressComponent " + component.getField());
        }
    }
}
Also used : AddressHierarchyService(org.openmrs.module.addresshierarchy.service.AddressHierarchyService) AddressHierarchyLevel(org.openmrs.module.addresshierarchy.AddressHierarchyLevel)

Aggregations

AddressHierarchyLevel (org.openmrs.module.addresshierarchy.AddressHierarchyLevel)15 AddressHierarchyService (org.openmrs.module.addresshierarchy.service.AddressHierarchyService)13 HashMap (java.util.HashMap)7 Field (org.openmrs.module.registrationapp.model.Field)7 Question (org.openmrs.module.registrationapp.model.Question)7 AddressField (org.openmrs.module.addresshierarchy.AddressField)6 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 PatientIdentifier (org.openmrs.PatientIdentifier)2 PersonAddress (org.openmrs.PersonAddress)2