use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldUpdateAnExistingPatientIdentifier.
@Test
public void savePatientIdentifier_shouldUpdateAnExistingPatientIdentifier() throws Exception {
PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
patientIdentifier.setIdentifier("NEW-ID");
PatientIdentifier updatedPatientIdentifier = patientService.savePatientIdentifier(patientIdentifier);
Assert.assertNotNull(updatedPatientIdentifier);
Assert.assertEquals("NEW-ID", updatedPatientIdentifier.getIdentifier());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsNotUsed.
/**
* @see PatientService#savePatientIdentifier(PatientIdentifier)
*/
@Test
public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsNotUsed() {
PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
patientIdentifier.setLocation(null);
patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
patientService.savePatientIdentifier(patientIdentifier);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit.
/**
* @see PatientService#getPatients(String, String, java.util.List, boolean)
*/
@Test
public void getPatients_shouldSupportPatternUsingLastDigitAsCheckDigit() throws Exception {
Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_SEARCH_PATTERN, "@SEARCH@,0@SEARCH@,@SEARCH-1@-@CHECKDIGIT@,0@SEARCH-1@-@CHECKDIGIT@"));
// "^(0*@SEARCH-1@-@CHECKDIGIT@)$"));
PatientIdentifier identifier = new PatientIdentifier("1234-4", new PatientIdentifierType(1), new Location(1));
identifier.setCreator(new User(1));
identifier.setDateCreated(new Date());
Patient patient = Context.getPatientService().getPatient(2);
patient.addIdentifier(identifier);
Context.getPatientService().savePatient(patient);
updateSearchIndex();
assertEquals(1, Context.getPatientService().getPatients("12344").size());
assertEquals(1, Context.getPatientService().getPatients("1234-4").size());
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsRequired.
/**
* @see PatientService#savePatientIdentifier(PatientIdentifier)
*/
@Test(expected = ValidationException.class)
public void savePatientIdentifier_shouldAllowLocationToBeNullWhenLocationBehaviourIsRequired() {
PatientIdentifier patientIdentifier = patientService.getPatientIdentifier(7);
patientIdentifier.setLocation(null);
patientIdentifier.getIdentifierType().setLocationBehavior(PatientIdentifierType.LocationBehavior.REQUIRED);
patientService.savePatientIdentifier(patientIdentifier);
}
use of org.openmrs.PatientIdentifier in project openmrs-core by openmrs.
the class PatientServiceTest method checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank.
/**
* @see PatientService#checkPatientIdentifiers(Patient)
*/
@Test
public void checkPatientIdentifiers_shouldRemovePatientIdentifierGivenItIsBlank() throws Exception {
// given
Patient patient = new Patient();
PatientIdentifier blankPatientIdentifier = new PatientIdentifier();
blankPatientIdentifier.setIdentifier("");
blankPatientIdentifier.setIdentifierType(new PatientIdentifierType(21345));
blankPatientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0));
patient.addIdentifier(blankPatientIdentifier);
assertEquals(1, patient.getIdentifiers().size());
try {
// when
Context.getPatientService().checkPatientIdentifiers(patient);
// then
fail("should throw BlankIdentifierException");
} catch (BlankIdentifierException e) {
assertEquals(0, patient.getIdentifiers().size());
}
}
Aggregations