Search in sources :

Example 91 with PatientIdentifierType

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

the class PatientServiceTest method savePatientIdentifierType_shouldUpdateExistingType.

/**
 * @see PatientService#savePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void savePatientIdentifierType_shouldUpdateExistingType() throws Exception {
    PatientIdentifierType type = patientService.getPatientIdentifierType(1);
    type.setName("SOME NEW NAME");
    patientService.savePatientIdentifierType(type);
    PatientIdentifierType newerPatientIdentifierType = patientService.getPatientIdentifierType(1);
    assertEquals("SOME NEW NAME", newerPatientIdentifierType.getName());
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 92 with PatientIdentifierType

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

the class PatientDAOTest method getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypesThatAreNotRequired.

/**
 * @see PatientDAO#getPatientIdentifierTypes(String, String, Boolean, Boolean)
 */
@Test
public void getPatientIdentifierTypes_shouldReturnNonRetiredPatientIdentifierTypesThatAreNotRequired() {
    PatientIdentifierType nonRetiredNonRequired1 = dao.getPatientIdentifierType(1);
    PatientIdentifierType nonRetiredNonRequired2 = dao.getPatientIdentifierType(2);
    PatientIdentifierType nonRetiredNonRequired3 = dao.getPatientIdentifierType(5);
    List<PatientIdentifierType> patientIdentifierTypes = dao.getPatientIdentifierTypes(null, null, false, null);
    Assert.assertEquals(patientIdentifierTypes.size(), 3);
    Assert.assertTrue(patientIdentifierTypes.contains(nonRetiredNonRequired1));
    Assert.assertTrue(patientIdentifierTypes.contains(nonRetiredNonRequired2));
    Assert.assertTrue(patientIdentifierTypes.contains(nonRetiredNonRequired3));
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 93 with PatientIdentifierType

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

the class PatientServiceTest method mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers.

/**
 * @see PatientService#mergePatients(Patient,Patient)
 */
@Test
public void mergePatients_shouldNotCopyOverDuplicatePatientIdentifiers() throws Exception {
    List<Location> locations = Context.getLocationService().getAllLocations();
    Assert.assertTrue(CollectionUtils.isNotEmpty(locations));
    // check if we have patient identifiers already
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getPatientIdentifierType(5);
    Assert.assertNotNull(patientIdentifierType);
    // retrieve preferred patient and set gender
    Patient preferred = patientService.getPatient(999);
    // create new identifier for the preferred patient
    PatientIdentifier preferredIdentifier = new PatientIdentifier();
    preferredIdentifier.setIdentifier("9999-4");
    preferredIdentifier.setIdentifierType(patientIdentifierType);
    preferredIdentifier.setLocation(locations.get(0));
    preferred.addIdentifier(preferredIdentifier);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    // merge with not preferred
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    // create identifier with the same values for the non preferred patient
    PatientIdentifier nonPreferredIdentifier = new PatientIdentifier();
    nonPreferredIdentifier.setIdentifier("9999-4");
    nonPreferredIdentifier.setIdentifierType(patientIdentifierType);
    nonPreferredIdentifier.setLocation(locations.get(0));
    notPreferred.addIdentifier(nonPreferredIdentifier);
    patientService.savePatient(notPreferred);
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    // should not copy the duplicate identifier to the winner
    Assert.assertEquals(notPreferred.getIdentifiers().size() - 1, audit.getPersonMergeLogData().getCreatedIdentifiers().size());
}
Also used : PersonName(org.openmrs.PersonName) Patient(org.openmrs.Patient) PersonMergeLog(org.openmrs.person.PersonMergeLog) 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 94 with PatientIdentifierType

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

the class PatientServiceTest method savePatientIdentifierType_shouldThrowErrorWhenTryingToSaveAPatientIdentifierTypeWhilePatientIdentifierTypesAreLocked.

@Test(expected = PatientIdentifierTypeLockedException.class)
public void savePatientIdentifierType_shouldThrowErrorWhenTryingToSaveAPatientIdentifierTypeWhilePatientIdentifierTypesAreLocked() throws Exception {
    PatientService ps = Context.getPatientService();
    createPatientIdentifierTypeLockedGPAndSetValue("true");
    PatientIdentifierType pit = ps.getPatientIdentifierType(1);
    pit.setDescription("test");
    ps.savePatientIdentifierType(pit);
}
Also used : PatientIdentifierType(org.openmrs.PatientIdentifierType) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) PatientServiceImplTest(org.openmrs.api.impl.PatientServiceImplTest) Test(org.junit.Test)

Example 95 with PatientIdentifierType

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

the class PatientServiceTest method unretirePatientIdentifierType_shouldReturnUnretiredPatientIdentifierType.

/**
 * @see PatientService#unretirePatientIdentifierType(PatientIdentifierType)
 */
@Test
public void unretirePatientIdentifierType_shouldReturnUnretiredPatientIdentifierType() throws Exception {
    PatientIdentifierType identifierType = Context.getPatientService().getPatientIdentifierType(4);
    Assert.assertTrue(identifierType.getRetired());
    Assert.assertNotNull(identifierType.getRetiredBy());
    Assert.assertNotNull(identifierType.getRetireReason());
    Assert.assertNotNull(identifierType.getDateRetired());
    PatientIdentifierType unretiredIdentifierType = Context.getPatientService().unretirePatientIdentifierType(identifierType);
    Assert.assertFalse(unretiredIdentifierType.getRetired());
    Assert.assertNull(unretiredIdentifierType.getRetiredBy());
    Assert.assertNull(unretiredIdentifierType.getRetireReason());
    Assert.assertNull(unretiredIdentifierType.getDateRetired());
}
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