Search in sources :

Example 31 with PatientIdentifierType

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

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

the class PatientServiceTest method isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatients.

/**
 * Regression test for http://dev.openmrs.org/ticket/790
 *
 * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier)
 */
@Test
public void isIdentifierInUseByAnotherPatient_shouldIgnoreVoidedPatients() throws Exception {
    {
        // patient 999 should be voided and have a non-voided identifier of
        // XYZ
        Patient p = patientService.getPatient(999);
        Assert.assertNotNull(p);
        Assert.assertTrue(p.getVoided());
        boolean found = false;
        for (PatientIdentifier id : p.getIdentifiers()) {
            if (id.getIdentifier().equals("XYZ") && id.getIdentifierType().getId() == 2) {
                found = true;
                break;
            }
        }
        Assert.assertTrue(found);
    }
    PatientIdentifierType pit = patientService.getPatientIdentifierType(2);
    PatientIdentifier patientIdentifier = new PatientIdentifier("XYZ", pit, null);
    Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(patientIdentifier));
}
Also used : Patient(org.openmrs.Patient) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 33 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierTypes_shouldFetchNonRequiredPatientIdentifierTypesWhenGivenRequiredIsFalse.

/**
 * @see PatientService#getPatientIdentifierTypes(String,String,Boolean,Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldFetchNonRequiredPatientIdentifierTypesWhenGivenRequiredIsFalse() throws Exception {
    executeDataSet("org/openmrs/api/include/PatientServiceTest-createPatientIdentifierType.xml");
    List<PatientIdentifierType> patientIdentifierTypes = Context.getPatientService().getPatientIdentifierTypes(null, null, false, null);
    Assert.assertTrue(!patientIdentifierTypes.isEmpty());
    for (PatientIdentifierType patientIdentifierType : patientIdentifierTypes) {
        Assert.assertFalse(patientIdentifierType.getRequired());
    }
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 34 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierTypeByName_shouldReturnNullWhenPatientIdentifierTypeWithGivenNameDoesNotExist.

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

Example 35 with PatientIdentifierType

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

the class PatientServiceTest method getPatientIdentifierType_shouldReturnNullWhenPatientIdentifierIdentifierDoesNotExist.

/**
 * @see PatientService#getPatientIdentifierType(Integer)
 */
@Test
public void getPatientIdentifierType_shouldReturnNullWhenPatientIdentifierIdentifierDoesNotExist() throws Exception {
    PatientIdentifierType identifierType = Context.getPatientService().getPatientIdentifierType(10000);
    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