Search in sources :

Example 41 with PersonName

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

the class PatientServiceTest method savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified.

/**
 * @see PatientService#savePatient(Patient)
 */
@Test
public void savePatient_shouldSetThePreferredNameAddressAndIdentifierIfNoneIsSpecified() throws Exception {
    Patient patient = new Patient();
    patient.setGender("M");
    PatientIdentifier identifier = new PatientIdentifier("QWERTY", patientService.getPatientIdentifierType(2), locationService.getLocation(1));
    patient.addIdentifier(identifier);
    PersonName name = new PersonName("givenName", "middleName", "familyName");
    patient.addName(name);
    PersonAddress address = new PersonAddress();
    address.setAddress1("some address");
    patient.addAddress(address);
    Context.getPatientService().savePatient(patient);
    Assert.assertTrue(identifier.getPreferred());
    Assert.assertTrue(name.getPreferred());
    Assert.assertTrue(address.getPreferred());
}
Also used : PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 42 with PersonName

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

the class PatientServiceTest method shouldCreatePatient.

@Test
public void shouldCreatePatient() throws Exception {
    executeDataSet(CREATE_PATIENT_XML);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    // patient.removeAddress(pAddress);
    patient.setBirthdateEstimated(true);
    patient.setBirthdate(new Date());
    patient.setBirthdateEstimated(true);
    patient.setDeathDate(new Date());
    patient.setCauseOfDeath(new Concept());
    patient.setGender("male");
    List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes();
    assertNotNull(patientIdTypes);
    PatientIdentifier patientIdentifier = new PatientIdentifier();
    patientIdentifier.setIdentifier("123-0");
    patientIdentifier.setIdentifierType(patientIdTypes.get(0));
    patientIdentifier.setLocation(new Location(1));
    patientIdentifier.setPreferred(true);
    Set<PatientIdentifier> patientIdentifiers = new LinkedHashSet<>();
    patientIdentifiers.add(patientIdentifier);
    patient.setIdentifiers(patientIdentifiers);
    patientService.savePatient(patient);
    Patient createdPatient = patientService.getPatient(patient.getPatientId());
    assertNotNull(createdPatient);
    assertNotNull(createdPatient.getPatientId());
    Patient createdPatientById = patientService.getPatient(createdPatient.getPatientId());
    assertNotNull(createdPatientById);
}
Also used : Concept(org.openmrs.Concept) LinkedHashSet(java.util.LinkedHashSet) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) Date(java.util.Date) 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 43 with PersonName

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

the class PatientServiceTest method mergePatients_shouldAuditPriorDateOfBirthEstimated.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldAuditPriorDateOfBirthEstimated() throws Exception {
    // retrieve preferred patient and set a date of birth
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    Patient preferred = patientService.getPatient(999);
    preferred.setBirthdate(cDate.getTime());
    preferred.setBirthdateEstimated(true);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertTrue("prior estimated date of birth was not audited", audit.getPersonMergeLogData().isPriorDateOfBirthEstimated());
}
Also used : PersonName(org.openmrs.PersonName) GregorianCalendar(java.util.GregorianCalendar) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 44 with PersonName

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

the class PatientServiceTest method mergePatients_shouldCopyNonvoidedNamesToPreferredPatient.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldCopyNonvoidedNamesToPreferredPatient() throws Exception {
    Patient preferred = patientService.getPatient(7);
    Patient notPreferred = patientService.getPatient(8);
    patientService.mergePatients(preferred, notPreferred);
    // make sure one of their addresses has the first name of "Anet"
    boolean found = false;
    for (PersonName pn : preferred.getNames()) {
        if (pn.getGivenName().equals("Anet")) {
            found = true;
        }
    }
    Assert.assertTrue("odd, user 7 didn't get user 8's names", found);
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 45 with PersonName

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

Aggregations

PersonName (org.openmrs.PersonName)115 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)57 Patient (org.openmrs.Patient)46 Person (org.openmrs.Person)41 Date (java.util.Date)29 PatientIdentifier (org.openmrs.PatientIdentifier)24 PersonAddress (org.openmrs.PersonAddress)20 User (org.openmrs.User)19 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)17 Location (org.openmrs.Location)13 PatientIdentifierType (org.openmrs.PatientIdentifierType)13 ArrayList (java.util.ArrayList)9 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)8 PersonMergeLog (org.openmrs.person.PersonMergeLog)8 PersonAttribute (org.openmrs.PersonAttribute)7 PatientAndMatchQuality (org.openmrs.module.registrationcore.api.search.PatientAndMatchQuality)7 BindException (org.springframework.validation.BindException)7 Provider (org.openmrs.Provider)6 Errors (org.springframework.validation.Errors)6