Search in sources :

Example 26 with PersonAddress

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

the class WristbandTemplateTest method testWristBandTemplate.

@Test
public void testWristBandTemplate() {
    Date today = new Date();
    visitLocation.setName("Hôpital Universitaire de Mirebalais");
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setBirthdate(new DateTime(1940, 7, 7, 5, 5, 5).toDate());
    PatientIdentifier primaryIdentifier = new PatientIdentifier();
    primaryIdentifier.setIdentifier("ZL1234");
    primaryIdentifier.setIdentifierType(primaryIdentifierType);
    primaryIdentifier.setVoided(false);
    patient.addIdentifier(primaryIdentifier);
    PatientIdentifier paperRecordIdentifier = new PatientIdentifier();
    paperRecordIdentifier.setIdentifier("A000005");
    paperRecordIdentifier.setIdentifierType(paperRecordIdentifierType);
    paperRecordIdentifier.setVoided(false);
    paperRecordIdentifier.setLocation(visitLocation);
    patient.addIdentifier(paperRecordIdentifier);
    PersonAddress address = new PersonAddress();
    address.setAddress2("Avant Eglise Chretienne des perlerlerin de la siant tete de moliere");
    address.setAddress1("Saut D'Eau");
    address.setAddress3("1ere Riviere Canot");
    address.setCityVillage("Saut d'Eau");
    address.setStateProvince("Centre");
    patient.addAddress(address);
    PersonName name = new PersonName();
    name.setGivenName("Ringo");
    name.setFamilyName("Starr");
    patient.addName(name);
    when(messageSourceService.getMessage("coreapps.ageYears", Collections.singletonList(patient.getAge()).toArray(), locale)).thenReturn(patient.getAge() + " an(s)");
    String output = wristbandTemplate.generateWristband(patient, visitLocation);
    assertThat(output, containsString("^XA^CI28^MTD^FWB"));
    assertThat(output, containsString("^FO050,200^FB2150,1,0,L,0^AS^FDHôpital Universitaire de Mirebalais " + df.format(today) + "^FS"));
    assertThat(output, containsString("^FO100,200^FB2150,1,0,L,0^AU^FDRingo Starr^FS"));
    assertThat(output, containsString("^FO160,200^FB2150,1,0,L,0^AU^FD07 juil. 1940^FS"));
    assertThat(output, containsString("^FO160,200^FB1850,1,0,L,0^AT^FD" + patient.getAge() + " an(s)^FS"));
    assertThat(output, containsString("^FO160,200^FB1650,1,0,L,0^AU^FDMasculin  A 000005^FS"));
    assertThat(output, containsString("^FO220,200^FB2150,1,0,L,0^AS^FDAvant Eglise Chretienne des perlerlerin de la siant tete de moliere^FS"));
    assertThat(output, containsString("^FO270,200^FB2150,1,0,L,0^AS^FDSaut D'Eau, 1ere Riviere Canot, Saut d'Eau, Centre^FS"));
    assertThat(output, containsString("^FO100,2400^AT^BY4^BC,150,N^FDZL1234^XZ"));
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Date(java.util.Date) DateTime(org.joda.time.DateTime) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test)

Example 27 with PersonAddress

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

the class ZlEmrIdCardPrinter method getAddressLines.

/**
 * @return the address lines in the format that it should be displayed on the id cards
 */
protected List<String> getAddressLines(Patient patient) {
    PersonAddress address = patient.getPersonAddress();
    if (address == null) {
        return null;
    }
    List<String> addressLines = new ArrayList<String>();
    if (AddressSupport.getInstance().getDefaultLayoutTemplate() != null && AddressSupport.getInstance().getDefaultLayoutTemplate().getLines() != null) {
        for (List<Map<String, String>> line : AddressSupport.getInstance().getDefaultLayoutTemplate().getLines()) {
            // now iterate through all the tokens in the line and build the string to print
            StringBuilder output = new StringBuilder();
            for (Map<String, String> token : line) {
                // find all the tokens on this line, and then add them to that output line
                if (token.get("isToken").equals(AddressSupport.getInstance().getDefaultLayoutTemplate().getLayoutToken())) {
                    try {
                        String propertyValue = (String) PropertyUtils.getProperty(address, token.get("codeName"));
                        if (StringUtils.isNotBlank(propertyValue)) {
                            if (output.length() > 0) {
                                output.append(", ");
                            }
                            output.append(propertyValue);
                        }
                    } catch (Exception e) {
                        log.error("Invalid address property of " + token.get("codeName") + " configured in address layout template", e);
                    }
                }
            }
            if (StringUtils.isNotBlank(output.toString())) {
                addressLines.add(output.toString());
            }
        }
    } else {
        log.error("Address template not properly configured");
    }
    return addressLines;
}
Also used : PersonAddress(org.openmrs.PersonAddress) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException)

Example 28 with PersonAddress

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

the class BaseReportTest method address.

protected PatientBuilder address(PatientBuilder pb, List<AddressComponent> addressComponents, String... values) {
    PersonAddress a = new PersonAddress();
    int index = 0;
    for (AddressComponent property : addressComponents) {
        ReflectionUtil.setPropertyValue(a, property.getField().getName(), values[index]);
        index++;
    }
    return pb.address(a);
}
Also used : PersonAddress(org.openmrs.PersonAddress) AddressComponent(org.openmrs.module.pihcore.deploy.bundle.AddressComponent)

Example 29 with PersonAddress

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

the class WristbandTemplateTest method testWristBandTemplate.

@Test
public void testWristBandTemplate() {
    Date today = new Date();
    visitLocation.setName("Mirebalais");
    Patient patient = new Patient();
    patient.setGender("M");
    patient.setBirthdate(new DateTime(1940, 7, 7, 5, 5, 5).toDate());
    PatientIdentifier primaryIdentifier = new PatientIdentifier();
    primaryIdentifier.setIdentifier("ZL1234");
    primaryIdentifier.setIdentifierType(primaryIdentifierType);
    primaryIdentifier.setVoided(false);
    patient.addIdentifier(primaryIdentifier);
    PatientIdentifier paperRecordIdentifier = new PatientIdentifier();
    paperRecordIdentifier.setIdentifier("A000005");
    paperRecordIdentifier.setIdentifierType(paperRecordIdentifierType);
    paperRecordIdentifier.setVoided(false);
    paperRecordIdentifier.setLocation(visitLocation);
    patient.addIdentifier(paperRecordIdentifier);
    PersonAddress address = new PersonAddress();
    address.setAddress2("Avant Eglise Chretienne des perlerlerin de la siant tete de moliere");
    address.setAddress1("Saut D'Eau");
    address.setAddress3("1ere Riviere Canot");
    address.setCityVillage("Saut d'Eau");
    address.setStateProvince("Centre");
    patient.addAddress(address);
    PersonName name = new PersonName();
    name.setGivenName("Ringo");
    name.setFamilyName("Starr");
    patient.addName(name);
    when(messageSourceService.getMessage("coreapps.ageYears", Collections.singletonList(patient.getAge()).toArray(), locale)).thenReturn(patient.getAge() + " an(s)");
    String output = wristbandTemplate.generateWristband(patient, visitLocation);
    assertThat(output, containsString("^XA^CI28^MTD^FWB"));
    assertThat(output, containsString("^FO050,200^FB2150,1,0,L,0^AS^FDMirebalais " + df.format(today) + "^FS"));
    assertThat(output, containsString("^FO100,200^FB2150,1,0,L,0^AU^FDRingo Starr^FS"));
    assertThat(output, containsString("^FO160,200^FB2150,1,0,L,0^AU^FD07 juil. 1940^FS"));
    assertThat(output, containsString("^FO160,200^FB1850,1,0,L,0^AT^FD" + patient.getAge() + " an(s)^FS"));
    assertThat(output, containsString("^FO160,200^FB1650,1,0,L,0^AU^FDMasculin  A 000005^FS"));
    assertThat(output, containsString("^FO220,200^FB2150,1,0,L,0^AS^FDAvant Eglise Chretienne des perlerlerin de la siant tete de moliere^FS"));
    assertThat(output, containsString("^FO270,200^FB2150,1,0,L,0^AS^FDSaut D'Eau, 1ere Riviere Canot, Saut d'Eau, Centre^FS"));
    assertThat(output, containsString("^FO100,2400^AT^BY4^BC,150,N^FDZL1234^XZ"));
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Date(java.util.Date) DateTime(org.joda.time.DateTime) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test)

Example 30 with PersonAddress

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

the class ZlEmrIdCardPrinter method getAddressLines.

/**
 * @return the address lines in the format that it should be displayed on the id cards
 */
protected List<String> getAddressLines(Patient patient) {
    PersonAddress address = patient.getPersonAddress();
    if (address == null) {
        return null;
    }
    List<String> addressLines = new ArrayList<String>();
    if (AddressSupport.getInstance().getDefaultLayoutTemplate() != null && AddressSupport.getInstance().getDefaultLayoutTemplate().getLines() != null) {
        for (List<Map<String, String>> line : AddressSupport.getInstance().getDefaultLayoutTemplate().getLines()) {
            // now iterate through all the tokens in the line and build the string to print
            StringBuilder output = new StringBuilder();
            for (Map<String, String> token : line) {
                // find all the tokens on this line, and then add them to that output line
                if (token.get("isToken").equals(AddressSupport.getInstance().getDefaultLayoutTemplate().getLayoutToken())) {
                    try {
                        String propertyValue = (String) PropertyUtils.getProperty(address, token.get("codeName"));
                        if (StringUtils.isNotBlank(propertyValue)) {
                            if (output.length() > 0) {
                                output.append(", ");
                            }
                            output.append(propertyValue);
                        }
                    } catch (Exception e) {
                        log.error("Invalid address property of " + token.get("codeName") + " configured in address layout template", e);
                    }
                }
            }
            if (StringUtils.isNotBlank(output.toString())) {
                addressLines.add(output.toString());
            }
        }
    } else {
        log.error("Address template not properly configured");
    }
    return addressLines;
}
Also used : PersonAddress(org.openmrs.PersonAddress) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) UnableToPrintException(org.openmrs.module.printer.UnableToPrintException)

Aggregations

PersonAddress (org.openmrs.PersonAddress)49 Test (org.junit.Test)32 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)26 PersonName (org.openmrs.PersonName)20 Patient (org.openmrs.Patient)18 BindException (org.springframework.validation.BindException)13 Errors (org.springframework.validation.Errors)13 Date (java.util.Date)12 PatientIdentifier (org.openmrs.PatientIdentifier)12 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)9 Person (org.openmrs.Person)6 Calendar (java.util.Calendar)5 Location (org.openmrs.Location)5 PatientIdentifierType (org.openmrs.PatientIdentifierType)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)3 DateTime (org.joda.time.DateTime)3 Concept (org.openmrs.Concept)3 PersonAttribute (org.openmrs.PersonAttribute)3 DateFormat (java.text.DateFormat)2