Search in sources :

Example 21 with PersonAttributeType

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

the class PatientDAOTest method getPatients_shouldFindPatientsEfficiently.

@Test
@Ignore("Designated for manual runs")
public void getPatients_shouldFindPatientsEfficiently() throws IOException, URISyntaxException {
    URL givenNamesIn = getClass().getResource("/org/openmrs/api/db/givenNames.csv");
    List<String> givenNames = FileUtils.readLines(new File(givenNamesIn.toURI()));
    URL familyNamesIn = getClass().getResource("/org/openmrs/api/db/familyNames.csv");
    List<String> familyNames = FileUtils.readLines(new File(familyNamesIn.toURI()));
    List<String> attributes = Arrays.asList("London", "Berlin", "Warsaw", "Paris", "Zurich", "Singapore");
    PatientIdentifierType idType = patientService.getPatientIdentifierTypeByName("Old Identification Number");
    PersonAttributeType attributeType = personService.getPersonAttributeTypeByName("Birthplace");
    attributeType.setSearchable(true);
    Context.getPersonService().savePersonAttributeType(attributeType);
    Location location = locationService.getLocation(1);
    // set the seed to have repeatable results
    Random random = new Random(100);
    List<String> generatedPatients = new ArrayList<>();
    for (int i = 0; i < 20000; i++) {
        int given = random.nextInt(givenNames.size());
        int family = random.nextInt(familyNames.size());
        int attribute = random.nextInt(attributes.size());
        generatedPatients.add((i + 1000) + " " + givenNames.get(given) + " " + familyNames.get(family) + " " + attributes.get(attribute));
        PersonName personName = new PersonName(givenNames.get(given), null, familyNames.get(family));
        Patient patient = new Patient();
        patient.setGender("m");
        patient.addIdentifier(new PatientIdentifier("" + (i + 1000), idType, location));
        patient.addName(personName);
        PersonAttribute personAttribute = new PersonAttribute();
        personAttribute.setAttributeType(attributeType);
        personAttribute.setValue(attributes.get(attribute));
        patient.addAttribute(personAttribute);
        patientService.savePatient(patient);
        if (i % 100 == 0) {
            System.out.println("Created " + i + " patients!");
            Context.flushSession();
            Context.clearSession();
        }
    }
    File file = File.createTempFile("generated-patients-", ".csv");
    FileUtils.writeLines(file, generatedPatients);
    System.out.println("Dumped generated patients to " + file.getAbsolutePath());
    long time = System.currentTimeMillis();
    updateSearchIndex();
    time = System.currentTimeMillis() - time;
    System.out.println("Indexing took " + time + " ms.");
    // get Lucene up to speed...
    patientService.getPatients("Aaaaa");
    time = System.currentTimeMillis();
    List<Patient> results = patientService.getPatients("Al");
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Al' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Al", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Al' name limited to 15 results returned in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Al Dem");
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Al Dem' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Al Dem", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Al Dem' name limited to 15 results returned in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Jack");
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Jack' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Jack", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Jack' name limited to 15 results returned in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Jack Sehgal");
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Jack Sehgal' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("Jack Sehgal", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Starts with search for 'Jack Sehgal' name limited to 15 results returned in " + time + " ms");
    Context.getAdministrationService().setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_ANYWHERE);
    time = System.currentTimeMillis();
    results = patientService.getPatients("aso");
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'aso' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("aso", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'aso' name limited to 15 results returned in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("aso os");
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'aso os' name returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("aso os", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'aso os' limited to 15 results returned in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("9243");
    time = System.currentTimeMillis() - time;
    System.out.println("Exact search for '9243' identifier returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("London");
    time = System.currentTimeMillis() - time;
    System.out.println("Exact search for 'London' attribute returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("London", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Exact search for 'London' attribute limited to 15 results returned in " + time + " ms");
    Context.getAdministrationService().setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_ANYWHERE);
    time = System.currentTimeMillis();
    results = patientService.getPatients("uric");
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'uric' attribute returned " + results.size() + " in " + time + " ms");
    time = System.currentTimeMillis();
    results = patientService.getPatients("uric", 0, 15);
    time = System.currentTimeMillis() - time;
    System.out.println("Anywhere search for 'uric' attribute limited to 15 results returned in " + time + " ms");
}
Also used : PersonName(org.openmrs.PersonName) ArrayList(java.util.ArrayList) PersonAttributeType(org.openmrs.PersonAttributeType) Patient(org.openmrs.Patient) URL(java.net.URL) PatientIdentifier(org.openmrs.PatientIdentifier) PersonAttribute(org.openmrs.PersonAttribute) Random(java.util.Random) File(java.io.File) PatientIdentifierType(org.openmrs.PatientIdentifierType) Location(org.openmrs.Location) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with PersonAttributeType

use of org.openmrs.PersonAttributeType 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 23 with PersonAttributeType

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

the class ZlEmrIdCardPrinter method getTelephoneNumber.

/**
 * @return the telephone number for the patient in the  format that it should be displayed on the id cards
 */
protected String getTelephoneNumber(Patient patient) {
    String phoneNumber = "";
    PersonAttributeType type = Metadata.getPhoneNumberAttributeType();
    PersonAttribute attr = patient.getAttribute(type);
    if (attr != null) {
        phoneNumber = StringUtils.defaultIfEmpty(attr.getValue(), "");
    }
    return phoneNumber;
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) PersonAttribute(org.openmrs.PersonAttribute)

Example 24 with PersonAttributeType

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

the class ZlEmrIdCardPrinter method getTelephoneNumber.

/**
 * @return the telephone number for the patient in the  format that it should be displayed on the id cards
 */
protected String getTelephoneNumber(Patient patient) {
    String phoneNumber = "";
    PersonAttributeType type = MetadataUtils.existing(PersonAttributeType.class, HaitiPersonAttributeTypes.TELEPHONE_NUMBER.uuid());
    PersonAttribute attr = patient.getAttribute(type);
    if (attr != null) {
        phoneNumber = StringUtils.defaultIfEmpty(attr.getValue(), "");
    }
    return phoneNumber;
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) PersonAttribute(org.openmrs.PersonAttribute)

Example 25 with PersonAttributeType

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

the class ORUR01Handler method updateHealthCenter.

private void updateHealthCenter(Patient patient, PV1 pv1) {
    // Update patient's location if it has changed
    if (log.isDebugEnabled()) {
        log.debug("Checking for discharge to location");
    }
    DLD dld = pv1.getDischargedToLocation();
    log.debug("DLD = " + dld);
    if (dld == null) {
        return;
    }
    IS hl7DischargeToLocation = dld.getDischargeLocation();
    log.debug("is = " + hl7DischargeToLocation);
    if (hl7DischargeToLocation == null) {
        return;
    }
    String dischargeToLocation = hl7DischargeToLocation.getValue();
    log.debug("dischargeToLocation = " + dischargeToLocation);
    if (dischargeToLocation != null && dischargeToLocation.length() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Patient discharged to " + dischargeToLocation);
        }
        // delimiter
        for (int i = 0; i < dischargeToLocation.length(); i++) {
            char ch = dischargeToLocation.charAt(i);
            if (ch == '&' || ch == '^') {
                dischargeToLocation = dischargeToLocation.substring(0, i);
                break;
            }
        }
        Integer newLocationId = Integer.parseInt(dischargeToLocation);
        // Hydrate a full patient object from patient object containing only
        // identifier
        patient = Context.getPatientService().getPatient(patient.getPatientId());
        PersonAttributeType healthCenterAttrType = Context.getPersonService().getPersonAttributeTypeByName("Health Center");
        if (healthCenterAttrType == null) {
            log.error("A person attribute type with name 'Health Center' is not defined but patient " + patient.getPatientId() + " is trying to change their health center to " + newLocationId);
            return;
        }
        PersonAttribute currentHealthCenter = patient.getAttribute("Health Center");
        if (currentHealthCenter == null || !newLocationId.toString().equals(currentHealthCenter.getValue())) {
            PersonAttribute newHealthCenter = new PersonAttribute(healthCenterAttrType, newLocationId.toString());
            log.debug("Updating patient's location from " + currentHealthCenter + " to " + newLocationId);
            // add attribute (and void old if there is one)
            patient.addAttribute(newHealthCenter);
            // save the patient and their new attribute
            Context.getPatientService().savePatient(patient);
        }
    }
    log.debug("finished discharge to location method");
}
Also used : PersonAttributeType(org.openmrs.PersonAttributeType) IS(ca.uhn.hl7v2.model.v25.datatype.IS) DLD(ca.uhn.hl7v2.model.v25.datatype.DLD) PersonAttribute(org.openmrs.PersonAttribute)

Aggregations

PersonAttributeType (org.openmrs.PersonAttributeType)40 Test (org.junit.Test)33 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)33 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 PersonAttribute (org.openmrs.PersonAttribute)4 Location (org.openmrs.Location)3 PatientIdentifierType (org.openmrs.PatientIdentifierType)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Patient (org.openmrs.Patient)2 ImportPatientFromWebService (org.openmrs.module.importpatientfromws.api.ImportPatientFromWebService)2 RemoteServerConfiguration (org.openmrs.module.importpatientfromws.api.RemoteServerConfiguration)2 DLD (ca.uhn.hl7v2.model.v25.datatype.DLD)1 IS (ca.uhn.hl7v2.model.v25.datatype.IS)1 File (java.io.File)1 URL (java.net.URL)1 Random (java.util.Random)1 Ignore (org.junit.Ignore)1 GlobalProperty (org.openmrs.GlobalProperty)1