Search in sources :

Example 56 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType 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 57 with PatientIdentifierType

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

the class LegacyMasterPatientIndexSetup method setupConnectionToMasterPatientIndex.

public static void setupConnectionToMasterPatientIndex(RuntimeProperties customProperties) {
    String url = customProperties.getLacollineServerUrl();
    String username = customProperties.getLacollineUsername();
    String password = customProperties.getLacollinePassword();
    if (url == null || username == null || password == null) {
        log.warn("Not configuring link to Lacolline server (url, username, and password are required)");
        return;
    }
    Map<String, PatientIdentifierType> identifierTypeMap = new HashMap<String, PatientIdentifierType>();
    identifierTypeMap.put("a541af1e-105c-40bf-b345-ba1fd6a59b85", MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.ZL_EMR_ID.uuid()));
    // TODO create PatientIdentifierType for Lacolline KE dossier number
    identifierTypeMap.put("e66645eb-03a8-4991-b4ce-e87318e37566", MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.EXTERNAL_DOSSIER_NUMBER.uuid()));
    // TODO create PatientIdentifierType for Lacolline dental dossier number
    Map<String, Location> locationMap = new HashMap<String, Location>();
    locationMap.put("23e7bb0d-51f9-4d5f-b34b-2fbbfeea1960", Context.getLocationService().getLocationByUuid(MirebalaisConstants.LACOLLINE_LOCATION_UUID));
    Map<String, PersonAttributeType> attributeTypeMap = new HashMap<String, PersonAttributeType>();
    attributeTypeMap.put("340d04c4-0370-102d-b0e3-001ec94a0cc1", MetadataUtils.existing(PersonAttributeType.class, HaitiPersonAttributeTypes.TELEPHONE_NUMBER.uuid()));
    RemoteServerConfiguration config = new RemoteServerConfiguration();
    config.setUrl(url);
    config.setUsername(username);
    config.setPassword(password);
    config.setIdentifierTypeMap(identifierTypeMap);
    config.setLocationMap(locationMap);
    config.setAttributeTypeMap(attributeTypeMap);
    Context.getService(ImportPatientFromWebService.class).registerRemoteServer("lacolline", config);
}
Also used : RemoteServerConfiguration(org.openmrs.module.importpatientfromws.api.RemoteServerConfiguration) HashMap(java.util.HashMap) PersonAttributeType(org.openmrs.PersonAttributeType) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) ImportPatientFromWebService(org.openmrs.module.importpatientfromws.api.ImportPatientFromWebService)

Example 58 with PatientIdentifierType

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

the class PaperRecordServiceIT method shouldCreateTwoDifferentDossierNumbers.

@Test
@DirtiesContext
public void shouldCreateTwoDifferentDossierNumbers() throws Exception {
    authenticate();
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierTypeByUuid("e66645eb-03a8-4991-b4ce-e87318e37566");
    when(paperRecordProperties.getPaperRecordIdentifierType()).thenReturn(patientIdentifierType);
    Location location = new Location(15);
    LocationTag locationTag = new LocationTag(15);
    locationTag.setName("tag");
    location.addTag(locationTag);
    when(paperRecordProperties.getMedicalRecordLocationLocationTag()).thenReturn(locationTag);
    PaperRecord paperRecord1 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
    assertTrue(paperRecord1.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
    PaperRecord paperRecord2 = ((PaperRecordServiceImpl) paperRecordService).createPaperRecord(new Patient(), location);
    assertTrue(paperRecord2.getPatientIdentifier().getIdentifier().matches("A\\d{6}"));
    assertThat(paperRecord1.getPatientIdentifier().getIdentifier(), not(paperRecord2.getPatientIdentifier().getIdentifier()));
}
Also used : LocationTag(org.openmrs.LocationTag) PaperRecord(org.openmrs.module.paperrecord.PaperRecord) Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) PaperRecordServiceImpl(org.openmrs.module.paperrecord.PaperRecordServiceImpl) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 59 with PatientIdentifierType

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

Example 60 with PatientIdentifierType

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

the class VitalsListPageController method get.

public String get(PageModel model, UiUtils ui, @SpringBean("encounterService") EncounterService encounterService, @SpringBean("patientService") PatientService patientService, @SpringBean Config config) throws IOException {
    // TODO restrict by location at some point if necessary
    ResourceFactory resourceFactory = ResourceFactory.getInstance();
    Map<Patient, Encounter> patientsWithCheckInEncounter = new LinkedHashMap<Patient, Encounter>();
    // all patients that have a check-in encounter today, but no vitals encounter
    List<Encounter> checkInEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(Metadata.lookupEncounterType(PihEmrConfigConstants.ENCOUNTERTYPE_CHECK_IN_UUID)), null, null, null, false);
    List<Encounter> vitalsEncounters = encounterService.getEncounters(null, null, new DateMidnight().toDate(), null, null, Collections.singletonList(Metadata.lookupEncounterType(PihEmrConfigConstants.ENCOUNTERTYPE_VITALS_UUID)), null, null, null, false);
    for (Encounter encounter : checkInEncounters) {
        // sanity check on visit
        if (encounter.getVisit() != null) {
            // we check that the patient isn't already in the list instead of just inserting again because we want to keep the earliest date
            if (!patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
                patientsWithCheckInEncounter.put(encounter.getPatient(), encounter);
            }
        }
    }
    for (Encounter encounter : vitalsEncounters) {
        if (patientsWithCheckInEncounter.containsKey(encounter.getPatient())) {
            patientsWithCheckInEncounter.remove(encounter.getPatient());
        }
    }
    String formPath = PihCoreUtil.getFormResource("vitals.xml");
    SimpleObject vitalsListBreadcrumb = SimpleObject.create("label", ui.message("pihcore.vitalsList.title"), "link", ui.pageLink("pihcore", "vitals/vitalsList"));
    PatientIdentifierType dossierNumberType = patientService.getPatientIdentifierTypeByUuid(ZlConfigConstants.PATIENTIDENTIFIERTYPE_DOSSIERNUMBER_UUID);
    // used to determine whether or not we display a link to the patient in the results list
    model.addAttribute("patientWithCheckInEncounter", patientsWithCheckInEncounter);
    model.addAttribute("mothersFirstName", Metadata.getMothersFirstNameAttributeType());
    model.addAttribute("dossierIdentifierName", dossierNumberType == null ? null : dossierNumberType.getName());
    model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(vitalsListBreadcrumb)));
    model.addAttribute("formPath", formPath);
    return null;
}
Also used : SimpleObject(org.openmrs.ui.framework.SimpleObject) DateMidnight(org.joda.time.DateMidnight) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ResourceFactory(org.openmrs.ui.framework.resource.ResourceFactory) PatientIdentifierType(org.openmrs.PatientIdentifierType) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PatientIdentifierType (org.openmrs.PatientIdentifierType)131 Test (org.junit.Test)99 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)88 PatientIdentifier (org.openmrs.PatientIdentifier)56 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)53 Patient (org.openmrs.Patient)37 Location (org.openmrs.Location)29 ArrayList (java.util.ArrayList)20 BindException (org.springframework.validation.BindException)17 Errors (org.springframework.validation.Errors)14 Date (java.util.Date)13 PersonName (org.openmrs.PersonName)13 User (org.openmrs.User)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Concept (org.openmrs.Concept)6 Person (org.openmrs.Person)5 HashMap (java.util.HashMap)4 PersonAddress (org.openmrs.PersonAddress)4 PatientServiceTest (org.openmrs.api.PatientServiceTest)4 HL7Exception (ca.uhn.hl7v2.HL7Exception)3