Search in sources :

Example 51 with PatientIdentifier

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

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

the class WristbandTemplateTest method testEstimatedBirthDate.

@Test
public void testEstimatedBirthDate() {
    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());
    patient.setBirthdateEstimated(true);
    PatientIdentifier primaryIdentifier = new PatientIdentifier();
    primaryIdentifier.setIdentifier("ZL1234");
    primaryIdentifier.setIdentifierType(primaryIdentifierType);
    primaryIdentifier.setVoided(false);
    patient.addIdentifier(primaryIdentifier);
    PatientIdentifier paperRecordIdentifier = new PatientIdentifier();
    paperRecordIdentifier.setIdentifier("A00005");
    paperRecordIdentifier.setIdentifierType(paperRecordIdentifierType);
    paperRecordIdentifier.setVoided(false);
    patient.addIdentifier(paperRecordIdentifier);
    PersonName name = new PersonName();
    name.setGivenName("Ringo");
    name.setFamilyName("Starr");
    patient.addName(name);
    String output = wristbandTemplate.generateWristband(patient, new Location());
    assertThat(output, containsString("^FO160,200^FB2150,1,0,L,0^AU^FD1940^FS"));
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DateTime(org.joda.time.DateTime) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) Test(org.junit.Test)

Example 53 with PatientIdentifier

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

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

the class ZplLabLabelTemplateTest method shouldGenerateLabel.

@Test
public void shouldGenerateLabel() {
    Patient patient = new Patient();
    PersonName name = new PersonName();
    name.setGivenName("Mark");
    name.setFamilyName("Goodrich");
    patient.addName(name);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("YXB123");
    patientIdentifier.setIdentifierType(primaryIdentifierType);
    patient.addIdentifier(patientIdentifier);
    String data = template.generateLabel(patient);
    String expectedDate = new SimpleDateFormat("dd MMM yyyy hh:mm aaa").format(new Date());
    assertThat(data, is("^XA^CI28^PW650^MTT^FO30,20^ARN^FDMark Goodrich ^FS^FO30,50^ATN^BY2,2,50^BCN^FDYXB123^FS^FO300,110^ARN^FD" + expectedDate + "^FS^XZ"));
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) SimpleDateFormat(java.text.SimpleDateFormat) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Test(org.junit.Test)

Example 55 with PatientIdentifier

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

the class DrugOrdersPageController method get.

public void get(PageModel model, UiUtils ui, @InjectBeans PatientDomainWrapper patientDomainWrapper, @RequestParam(required = false, value = "patient") Patient patient, @RequestParam(required = false, value = "hivemrId") String hivemrId, @SpringBean("conceptService") ConceptService conceptService, @SpringBean("patientService") PatientService patientService, @SpringBean("orderService") OrderService orderService, @SpringBean("obsService") ObsService obsService) throws IOException {
    if (patient == null) {
        PatientIdentifierType hivemrV1 = patientService.getPatientIdentifierTypeByUuid(ZlConfigConstants.PATIENTIDENTIFIERTYPE_HIVEMRV1_UUID);
        List<PatientIdentifier> idList = patientService.getPatientIdentifiers(hivemrId, Arrays.asList(hivemrV1), null, null, null);
        if (idList.isEmpty()) {
            throw new IllegalArgumentException("No patients found with identifier: " + hivemrId);
        }
        if (idList.size() > 1) {
            throw new IllegalArgumentException(idList.size() + " patients found with identifier: " + hivemrId);
        }
        patient = idList.get(0).getPatient();
    }
    // Get all of the drug orders for the patient
    List<DrugOrder> drugOrders = new ArrayList<>();
    for (Order order : orderService.getAllOrdersByPatient(patient)) {
        order = HibernateUtil.getRealObjectFromProxy(order);
        if (order instanceof DrugOrder && BooleanUtils.isNotTrue(order.getVoided())) {
            DrugOrder drugOrder = (DrugOrder) order;
            drugOrders.add(drugOrder);
        }
    }
    // Sort these drug orders in chronological order
    Collections.sort(drugOrders, (d1, d2) -> {
        // Get all of the previous orders for d1.  If any are d2, then d1 is later
        for (Order d1Prev = d1.getPreviousOrder(); d1Prev != null; d1Prev = d1Prev.getPreviousOrder()) {
            if (d1Prev.equals(d2)) {
                return 1;
            }
        }
        // Get all of the previous orders for d2.  If any are d1, then d2 is later
        for (Order d2Prev = d2.getPreviousOrder(); d2Prev != null; d2Prev = d2Prev.getPreviousOrder()) {
            if (d2Prev.equals(d1)) {
                return -1;
            }
        }
        // If neither is a revision of the other, then compare based on effective start date
        int dateCompare = d1.getEffectiveStartDate().compareTo(d2.getEffectiveStartDate());
        if (dateCompare != 0) {
            return dateCompare;
        }
        // If they are still the same, then order based on end date
        int ret = OpenmrsUtil.compareWithNullAsLatest(d1.getEffectiveStopDate(), d2.getEffectiveStopDate());
        if (ret == 0) {
            // Finally, order based on orderId
            ret = d1.getOrderId().compareTo(d2.getOrderId());
        }
        return ret;
    });
    /*
            TODO: For now we will organize these by order reason, as this is the way they are being migrated in
            from the HIV EMR.  Once we have established concept sets for organizing orderables by areas we can adjust
            to organize in that way.  We'll keep our model generic (based on string category names) to allow for this
            We also remove the discontinue orders and associate them back with the orders they discontinue in a map so that
            we can organize them together in a single row.
         */
    List<Concept> categories = new ArrayList<>();
    // HIV
    categories.add(conceptService.getConceptByUuid("138405AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    // TB
    categories.add(conceptService.getConceptByUuid("3ccca7cc-26fe-102b-80cb-0017a47871b2"));
    // PTME
    categories.add(conceptService.getConceptByUuid("160538AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    // Prophylaxis
    categories.add(conceptService.getConceptByUuid("1691AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
    List<DrugOrder> activeOrders = new ArrayList<>();
    List<DrugOrder> completedOrders = new ArrayList<>();
    Map<String, List<DrugOrder>> activeOrdersByCategory = new LinkedHashMap<>();
    Map<String, List<DrugOrder>> completedOrdersByCategory = new LinkedHashMap<>();
    Map<DrugOrder, DrugOrder> ordersToDiscontinueOrders = new HashMap<>();
    for (Concept category : categories) {
        activeOrdersByCategory.put(category.getDisplayString(), new ArrayList<>());
        completedOrdersByCategory.put(category.getDisplayString(), new ArrayList<>());
    }
    activeOrdersByCategory.put("", new ArrayList<>());
    completedOrdersByCategory.put("", new ArrayList<>());
    for (DrugOrder d : drugOrders) {
        if (d.getAction() == Order.Action.DISCONTINUE) {
            ordersToDiscontinueOrders.put((DrugOrder) d.getPreviousOrder(), d);
        } else {
            String category = "";
            if (d.getOrderReason() != null && categories.contains(d.getOrderReason())) {
                category = d.getOrderReason().getDisplayString();
            }
            if (d.isActive()) {
                activeOrders.add(d);
                activeOrdersByCategory.get(category).add(d);
            } else {
                completedOrders.add(d);
                completedOrdersByCategory.get(category).add(d);
            }
        }
    }
    // In the legacy HIV EMR, we supported entering notes/comments about a patient's medications.  Include those here.
    Concept medicationComments = conceptService.getConceptByMapping("10637", "PIH");
    List<Obs> medicationCommentObs = obsService.getObservationsByPersonAndConcept(patient, medicationComments);
    medicationCommentObs.sort((obs, t1) -> t1.getObsDatetime().compareTo(obs.getObsDatetime()));
    patientDomainWrapper.setPatient(patient);
    model.addAttribute("patient", patientDomainWrapper);
    model.addAttribute("drugOrders", drugOrders);
    model.addAttribute("categories", categories);
    model.addAttribute("activeOrders", activeOrders);
    model.addAttribute("completedOrders", completedOrders);
    model.addAttribute("activeOrdersByCategory", activeOrdersByCategory);
    model.addAttribute("completedOrdersByCategory", completedOrdersByCategory);
    model.addAttribute("ordersToDiscontinueOrders", ordersToDiscontinueOrders);
    model.addAttribute("medicationCommentObs", medicationCommentObs);
}
Also used : DrugOrder(org.openmrs.DrugOrder) Order(org.openmrs.Order) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) PatientIdentifier(org.openmrs.PatientIdentifier) LinkedHashMap(java.util.LinkedHashMap) DrugOrder(org.openmrs.DrugOrder) ArrayList(java.util.ArrayList) List(java.util.List) PatientIdentifierType(org.openmrs.PatientIdentifierType)

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