Search in sources :

Example 36 with PatientIdentifierType

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

the class PatientServiceTest method checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers.

/**
 * @see PatientService#checkPatientIdentifiers(Patient)
 */
@Test(expected = DuplicateIdentifierException.class)
public void checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers() throws Exception {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    // Identifier #1
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setIdentifier("123456789");
    patientIdentifier1.setLocation(new Location(2));
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    // Identifier #2
    PatientIdentifier patientIdentifier2 = new PatientIdentifier();
    patientIdentifier2.setIdentifier("123456789");
    patientIdentifier2.setIdentifierType(patientIdentifierType);
    patientIdentifier2.setLocation(new Location(2));
    patient.addIdentifier(patientIdentifier2);
    patientService.checkPatientIdentifiers(patient);
}
Also used : Patient(org.openmrs.Patient) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 37 with PatientIdentifierType

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

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

the class PatientDAOTest method getAllPatientIdentifierTypes_shouldReturnOrdered.

/**
 * @see PatientDAO#getAllPatientIdentifierTypes(boolean)
 */
@Test
public void getAllPatientIdentifierTypes_shouldReturnOrdered() {
    // given
    // non retired, non required
    PatientIdentifierType patientIdentifierType1 = dao.getPatientIdentifierType(1);
    // non retired, required
    PatientIdentifierType patientIdentifierType2 = dao.getPatientIdentifierType(2);
    patientIdentifierType2.setRequired(true);
    dao.savePatientIdentifierType(patientIdentifierType2);
    // retired
    PatientIdentifierType patientIdentifierType4 = dao.getPatientIdentifierType(4);
    // non retired, non required
    PatientIdentifierType patientIdentifierType5 = dao.getPatientIdentifierType(5);
    // when
    List<PatientIdentifierType> all = dao.getAllPatientIdentifierTypes(true);
    // then
    Assert.assertArrayEquals(new Object[] { patientIdentifierType2, patientIdentifierType1, patientIdentifierType5, patientIdentifierType4 }, all.toArray());
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 39 with PatientIdentifierType

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

the class PatientDAOTest method getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypesThatAreRequired.

/**
 * @see PatientDAO#getPatientIdentifierTypes(String, String, Boolean, Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypesThatAreRequired() {
    PatientIdentifierType nonRetiredRequired = dao.getPatientIdentifierType(4);
    nonRetiredRequired.setRetired(false);
    nonRetiredRequired.setRequired(true);
    dao.savePatientIdentifierType(nonRetiredRequired);
    List<PatientIdentifierType> patientIdentifierTypes = dao.getPatientIdentifierTypes(null, null, true, null);
    Assert.assertEquals(patientIdentifierTypes.size(), 1);
    Assert.assertEquals(nonRetiredRequired, patientIdentifierTypes.get(0));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 40 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierTypeByName_shouldNotReturnPatientIdentifierTypeThatPartiallyMatchesGivenName.

/**
 * @see PatientService#getPatientIdentifierTypeByName(String)
 */
@Test
public void getPatientIdentifierTypeByName_shouldNotReturnPatientIdentifierTypeThatPartiallyMatchesGivenName() throws Exception {
    PatientIdentifierType identifierType = Context.getPatientService().getPatientIdentifierTypeByName("OpenMRS");
    Assert.assertNull(identifierType);
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

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