use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldThrowAnAPIExceptionWhenOneOfTheRequiredFieldsIsNull.
@Test(expected = APIException.class)
public void savePatientIdentifier_shouldThrowAnAPIExceptionWhenOneOfTheRequiredFieldsIsNull() throws Exception {
PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
patientIdentifier.setIdentifier(null);
patientService.savePatientIdentifier(patientIdentifier);
}
use of org.openmrs.PatientIdentifier 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);
}
use of org.openmrs.PatientIdentifier 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));
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method getPatients_shouldFindAPatientsWithAMatchingIdentifierWithNoDigits.
/**
* @see PatientService#getPatients(String,Integer,Integer)
*/
@Test
public void getPatients_shouldFindAPatientsWithAMatchingIdentifierWithNoDigits() throws Exception {
final String identifier = "XYZ";
Patient patient = patientService.getPatient(2);
Assert.assertEquals(0, patientService.getPatients(identifier, (Integer) null, (Integer) null).size());
PatientIdentifier pId = new PatientIdentifier(identifier, patientService.getPatientIdentifierType(5), locationService.getLocation(1));
patient.addIdentifier(pId);
patientService.savePatient(patient);
updateSearchIndex();
Assert.assertEquals(1, patientService.getPatients(identifier).size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method mergePatients_shouldCopyNonvoidedIdentifiersToPreferredPatient.
/**
* @see PatientService#mergePatients(Patient, Patient)
*/
@Test
public void mergePatients_shouldCopyNonvoidedIdentifiersToPreferredPatient() throws Exception {
Patient preferred = patientService.getPatient(7);
Patient notPreferred = patientService.getPatient(8);
PatientIdentifier nonvoidedPI = null;
PatientIdentifier voidedPI = null;
for (PatientIdentifier patientIdentifier : notPreferred.getIdentifiers()) {
if (patientIdentifier.getIdentifier().equals("7TU-8")) {
nonvoidedPI = patientIdentifier;
}
if (patientIdentifier.getIdentifier().equals("ABC123")) {
voidedPI = patientIdentifier;
}
}
patientService.mergePatients(preferred, notPreferred);
Assert.assertNotNull(nonvoidedPI);
Assert.assertTrue(contains(new ArrayList<>(preferred.getIdentifiers()), nonvoidedPI.getIdentifier()));
Assert.assertNotNull(voidedPI);
Assert.assertFalse(contains(new ArrayList<>(preferred.getIdentifiers()), voidedPI.getIdentifier()));
}
Aggregations