Search in sources :

Example 31 with PatientIdentifier

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

the class PatientServiceTest method voidPatient_shouldVoidAllPatientIdentifiersAssociatedWithGivenPatient.

/**
 * @see PatientService#voidPatient(Patient,String)
 */
@Test
public void voidPatient_shouldVoidAllPatientIdentifiersAssociatedWithGivenPatient() throws Exception {
    Patient patient = Context.getPatientService().getPatient(2);
    Patient voidedPatient = Context.getPatientService().voidPatient(patient, "Void for testing");
    for (PatientIdentifier patientIdentifier : voidedPatient.getIdentifiers()) {
        Assert.assertTrue(patientIdentifier.getVoided());
        Assert.assertNotNull(patientIdentifier.getVoidedBy());
        Assert.assertNotNull(patientIdentifier.getVoidReason());
        Assert.assertNotNull(patientIdentifier.getDateVoided());
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 32 with PatientIdentifier

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

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

the class PatientDAOTest method getPatients_shouldNotGetExcessPatientsOnIdentifierAndAttributeMatch.

/**
 * @see HibernatePatientDAO#getPatients(String, Integer, Integer)
 */
@Test
public void getPatients_shouldNotGetExcessPatientsOnIdentifierAndAttributeMatch() {
    globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATTRIBUTE_SEARCH_MATCH_ANYWHERE);
    Patient patient = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("Senior", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    updateSearchIndex();
    List<Patient> patients = dao.getPatients("Senior", 0, null);
    Assert.assertEquals(patient, patients.get(0));
    Assert.assertEquals(3, patients.size());
    List<Patient> first_patient = dao.getPatients("Senior", 0, 1);
    Assert.assertEquals(patient, first_patient.get(0));
    Assert.assertEquals(1, first_patient.size());
    List<Patient> two_patients_only = dao.getPatients("Senior", 0, 2);
    Assert.assertEquals(2, two_patients_only.size());
    List<Patient> second_patient = dao.getPatients("Senior", 1, 1);
    Assert.assertEquals(1, second_patient.size());
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 34 with PatientIdentifier

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

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

the class PatientDAOTest method getPatients_shouldGetNewPatientByIdentifierStartMatch.

@Test
public void getPatients_shouldGetNewPatientByIdentifierStartMatch() {
    String oldPropertyValue = globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START);
    Patient patient = patientService.getPatient(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("OM292", patientService.getPatientIdentifierType(5), Context.getLocationService().getLocation(1));
    patient.addIdentifier(patientIdentifier);
    patientService.savePatient(patient);
    updateSearchIndex();
    // Check for partial identifier match
    List<Patient> patients = dao.getPatients("OM", false, 0, null);
    Assert.assertEquals(1, patients.size());
    Assert.assertEquals("OM292", patients.get(0).getPatientIdentifier(5).toString());
    if (oldPropertyValue != null) {
        globalPropertiesTestHelper.setGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE, oldPropertyValue);
    } else {
        globalPropertiesTestHelper.purgeGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_MATCH_MODE);
    }
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)103 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)59 PatientIdentifierType (org.openmrs.PatientIdentifierType)51 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)26 PersonName (org.openmrs.PersonName)19 Date (java.util.Date)15 PersonAddress (org.openmrs.PersonAddress)10 ArrayList (java.util.ArrayList)9 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 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 Concept (org.openmrs.Concept)3