Search in sources :

Example 46 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldEscapePercentageCharacterInIdentifierPhrase.

/**
 * @see PatientDAO#getPatients(String,String,List<QPatientIdentifierType;>,null)
 */
@Test
public void getPatients_shouldEscapePercentageCharacterInIdentifierPhrase() {
    Patient patient2 = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("%567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient2.addIdentifier(patientIdentifier);
    patientService.savePatient(patient2);
    // add closely matching identifier to a different patient
    Patient patient6 = patientService.getPatient(6);
    PatientIdentifier patientIdentifier6 = new PatientIdentifier("4567", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patientIdentifier6.setPreferred(true);
    patient6.addIdentifier(patientIdentifier6);
    patientService.savePatient(patient6);
    updateSearchIndex();
    // we expect only one matching patient
    int actualSize = dao.getPatients("%567", 0, null).size();
    Assert.assertEquals(1, actualSize);
    // if actually the search returned the matching patient
    Patient actualPatient = dao.getPatients("%567", 0, null).get(0);
    Assert.assertEquals(patient2, actualPatient);
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 47 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientDAOTest method getPatientIdentifiers_shouldLimitByResultsByLocation.

@Test
public void getPatientIdentifiers_shouldLimitByResultsByLocation() {
    // there is only one identifier in the test database for location 3
    Location location = Context.getLocationService().getLocation(3);
    List<PatientIdentifier> patientIdentifiers = dao.getPatientIdentifiers(null, new ArrayList<>(), Collections.singletonList(location), new ArrayList<>(), null);
    Assert.assertEquals(1, patientIdentifiers.size());
    Assert.assertEquals("12345K", patientIdentifiers.get(0).getIdentifier());
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 48 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.

the class PatientDAOTest method getPatients_shouldFindIdentifierIgnoringCase.

@Test
public void getPatients_shouldFindIdentifierIgnoringCase() {
    Patient patient = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("AS_567", patientService.getPatientIdentifierType(5), locationService.getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    updateSearchIndex();
    List<Patient> patients = patientService.getPatients("as_567");
    assertThat(patients, contains(patient));
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 49 with PatientIdentifier

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

the class ZlEmrIdCardPrinter method getIdentifier.

/**
 * @return the patient identifier in the format that it should be displayed on the id cards
 */
protected String getIdentifier(Patient patient) {
    PatientIdentifierType idType = emrApiProperties.getPrimaryIdentifierType();
    PatientIdentifier pi = patient.getPatientIdentifier(idType);
    if (pi == null || pi.isVoided()) {
        pi = patient.getPatientIdentifier();
    }
    return pi == null ? "" : pi.getIdentifier();
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 50 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)116 Test (org.junit.Test)91 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 PatientIdentifierType (org.openmrs.PatientIdentifierType)57 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)27 PersonName (org.openmrs.PersonName)24 Date (java.util.Date)19 PersonAddress (org.openmrs.PersonAddress)12 ArrayList (java.util.ArrayList)10 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3