/** * @see org.openmrs.api.PatientService#retirePatientIdentifierType(org.openmrs.PatientIdentifierType, * String) */ @Override public PatientIdentifierType retirePatientIdentifierType(PatientIdentifierType patientIdentifierType, String reason) throws APIException { checkIfPatientIdentifierTypesAreLocked(); if (reason == null || reason.length() < 1) { throw new APIException("Patient.identifier.retire.reason", (Object[]) null); } patientIdentifierType.setRetired(true); patientIdentifierType.setRetiredBy(Context.getAuthenticatedUser()); patientIdentifierType.setDateRetired(new Date()); patientIdentifierType.setRetireReason(reason); return Context.getPatientService().savePatientIdentifierType(patientIdentifierType); }
/** * @see org.openmrs.api.PatientService#unretirePatientIdentifierType(org.openmrs.PatientIdentifierType) */ @Override public PatientIdentifierType unretirePatientIdentifierType(PatientIdentifierType patientIdentifierType) throws APIException { checkIfPatientIdentifierTypesAreLocked(); patientIdentifierType.setRetired(false); patientIdentifierType.setRetiredBy(null); patientIdentifierType.setDateRetired(null); patientIdentifierType.setRetireReason(null); return Context.getPatientService().savePatientIdentifierType(patientIdentifierType); }
@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); }
/** * @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()); }
/** * @see PatientService#savePatientIdentifierType(PatientIdentifierType) */ @Test public void savePatientIdentifierType_shouldCreateNewType() throws Exception { PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName("testing"); patientIdentifierType.setDescription("desc"); patientIdentifierType.setRequired(false); patientService.savePatientIdentifierType(patientIdentifierType); PatientIdentifierType newPatientIdentifierType = patientService.getPatientIdentifierType(patientIdentifierType .getPatientIdentifierTypeId()); assertNotNull(newPatientIdentifierType); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public PatientIdentifierType save(PatientIdentifierType delegate) { return service().savePatientIdentifierType(delegate); }
/** * @see PatientService#purgePatientIdentifierType(PatientIdentifierType) */ @Test public void purgePatientIdentifierType_shouldDeleteTypeFromDatabase() throws Exception { PatientIdentifierType patientIdentifierType = new PatientIdentifierType(); patientIdentifierType.setName("testing"); patientIdentifierType.setDescription("desc"); patientIdentifierType.setRequired(false); patientService.savePatientIdentifierType(patientIdentifierType); PatientIdentifierType type = patientService.getPatientIdentifierType(patientIdentifierType.getId()); patientService.purgePatientIdentifierType(type); assertNull(patientService.getPatientIdentifierType(patientIdentifierType.getId())); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseAndIdTypeUniquenessIsSetToUnique() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.UNIQUE); patientService.savePatientIdentifierType(idType); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * @see PatientService#savePatientIdentifierType(PatientIdentifierType) */ @Test public void savePatientIdentifierType_shouldCreateNewPatientIdentifierType() throws Exception { PatientIdentifierType identifierType = new PatientIdentifierType(); identifierType.setName("test"); identifierType.setDescription("test description"); identifierType.setRequired(false); Assert.assertNull(identifierType.getPatientIdentifierTypeId()); patientService.savePatientIdentifierType(identifierType); PatientIdentifierType savedIdentifierType = patientService.getPatientIdentifierType(identifierType .getPatientIdentifierTypeId()); assertNotNull(savedIdentifierType); }
/** * @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier) */ @Test public void validateIdentifier_shouldPassIfInUseAndIdTypeUniquenessIsSetToNonUnique() { PatientService patientService = Context.getPatientService(); PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.NON_UNIQUE); patientService.savePatientIdentifierType(idType); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); PatientIdentifierValidator.validateIdentifier(pi); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnTrueIfInUseForALocationAndIdTypeUniquenessIsSetToLocation() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.LOCATION); patientService.savePatientIdentifierType(idType); PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, duplicateId.getLocation()); Assert.assertTrue(patientService.isIdentifierInUseByAnotherPatient(pi)); }
/** * @see PatientService#savePatientIdentifierType(PatientIdentifierType) */ @Test public void savePatientIdentifierType_shouldUpdateExistingPatientIdentifierType() throws Exception { PatientIdentifierType identifierType = Context.getPatientService().getAllPatientIdentifierTypes().get(0); Assert.assertNotNull(identifierType); Assert.assertNotNull(identifierType.getPatientIdentifierTypeId()); Assert.assertEquals(2, identifierType.getPatientIdentifierTypeId().intValue()); Assert.assertNotSame("test", identifierType.getName()); // Change existing patient identifier identifierType.setName("test"); identifierType.setDescription("test description"); identifierType.setRequired(false); patientService.savePatientIdentifierType(identifierType); PatientIdentifierType savedIdentifierType = patientService.getPatientIdentifierType(2); assertNotNull(savedIdentifierType); Assert.assertEquals("test", identifierType.getName()); assertTrue(savedIdentifierType.equals(identifierType)); }
/** * @see PatientService#isIdentifierInUseByAnotherPatient(PatientIdentifier) */ @Test public void isIdentifierInUseByAnotherPatient_shouldReturnFalseIfInUseForAnotherLocationAndIdUniquenessIsSetToLocation() throws Exception { PatientIdentifier duplicateId = patientService.getPatientIdentifier(1); Assert.assertNotNull(duplicateId.getLocation()); PatientIdentifierType idType = duplicateId.getIdentifierType(); idType.setUniquenessBehavior(UniquenessBehavior.LOCATION); patientService.savePatientIdentifierType(idType); Location idLocation = locationService.getLocation(2); Assert.assertNotSame(idLocation, duplicateId.getLocation());//sanity check PatientIdentifier pi = new PatientIdentifier(duplicateId.getIdentifier(), idType, idLocation); Assert.assertFalse(patientService.isIdentifierInUseByAnotherPatient(pi)); }