/** * @see org.openmrs.api.PatientService#getAllPatientIdentifierTypes() */ @Override @Transactional(readOnly = true) public List<PatientIdentifierType> getAllPatientIdentifierTypes() throws APIException { return Context.getPatientService().getAllPatientIdentifierTypes(false); }
/** * @see PatientService#getAllPatientIdentifierTypes(boolean) */ @Test public void getAllPatientIdentifierTypes_shouldOrderAsDefaultComparator() throws Exception { List<PatientIdentifierType> list = patientService.getAllPatientIdentifierTypes(); List<PatientIdentifierType> sortedList = new ArrayList<>(list); sortedList.sort(new PatientIdentifierTypeDefaultComparator()); Assert.assertEquals(sortedList, list); }
/** * @see PatientService#getAllPatientIdentifierTypes(null) */ @Test public void getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesExcludingRetiredWhenIncludeRetiredIsFalse() throws Exception { Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes(false); for (PatientIdentifierType type : types) { if (type.getRetired()) { Assert.fail("Should not return retired patient identifier types"); } } Assert.assertEquals("Should be exactly three patient identifier types in the dataset", 3, types.size()); }
/** * @see PatientService#getAllPatientIdentifierTypes() */ @Test public void getAllPatientIdentifierTypes_shouldFetchAllNonRetiredPatientIdentifierTypes() throws Exception { Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes(); Assert.assertNotNull("Should not return null", types); for (PatientIdentifierType type : types) { if (type.getRetired()) { Assert.fail("Should not return retired patient identifier types"); } } Assert.assertEquals("Should be exactly three patient identifier types in the dataset", 3, types.size()); }
/** * @see PatientService#getAllPatientIdentifierTypes(null) */ @Test public void getAllPatientIdentifierTypes_shouldFetchPatientIdentifierTypesIncludingRetiredWhenIncludeRetiredIsTrue() throws Exception { Collection<PatientIdentifierType> types = Context.getPatientService().getAllPatientIdentifierTypes(true); boolean atLeastOneRetired = false; for (PatientIdentifierType type : types) { if (type.getRetired()) { atLeastOneRetired = true; break; } } Assert.assertTrue("There should be at least one retired patient identifier type", atLeastOneRetired); Assert.assertEquals("Should be exactly four patient identifier types", 4, types.size()); }
/** * @see PatientService#checkPatientIdentifiers(Patient) */ @Test(expected = BlankIdentifierException.class) public void checkPatientIdentifiers_shouldRemoveIdentifierAndThrowErrorWhenPatientHasBlankPatientIdentifier() throws Exception { Patient patient = new Patient(); PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0)); patient.addIdentifier(patientIdentifier); // Should throw blank identifier exception Context.getPatientService().checkPatientIdentifiers(patient); }
coremetadatas.put("concept_datatype", Context.getConceptService().getAllConceptDatatypes(true)); coremetadatas.put("concept_class", Context.getConceptService().getAllConceptClasses(true)); coremetadatas.put("patient_identifier_type", Context.getPatientService().getAllPatientIdentifierTypes(true)); coremetadatas.put("location", Context.getLocationService().getAllLocations(true)); coremetadatas.put("hl7_source", Context.getHL7Service().getAllHL7Sources());
/** * @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()); } }
/** * Gets all patient identifier types * @return the patient identifier types */ public static List<PatientIdentifierType> getPatientIdentifierTypes() { return Context.getPatientService().getAllPatientIdentifierTypes(); }
/** * @see PatientService#checkPatientIdentifiers(Patient) */ @Test public void checkPatientIdentifiers_shouldThrowErrorGivenPatientIdentifierIsInvalid() throws Exception { // given Patient patient = new Patient(); PatientIdentifier nonBlankIdentifierWithoutLocation = new PatientIdentifier(); nonBlankIdentifierWithoutLocation.setVoided(false); nonBlankIdentifierWithoutLocation.setLocation(null); nonBlankIdentifierWithoutLocation.setIdentifier("an identifier"); nonBlankIdentifierWithoutLocation.setIdentifierType(new PatientIdentifierType(21345)); nonBlankIdentifierWithoutLocation.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0)); patient.addIdentifier(nonBlankIdentifierWithoutLocation); assertEquals(1, patient.getIdentifiers().size()); try { // when Context.getPatientService().checkPatientIdentifiers(patient); // then fail("should throw PatientIdentifierException"); } catch (BlankIdentifierException e) { fail("should not throw BlankIdentifierException"); } catch (PatientIdentifierException e) { assertEquals(1, patient.getIdentifiers().size()); } }
patient.setCauseOfDeath(new Concept(1)); patient.setGender("male"); List<PatientIdentifierType> patientIdTypes = ps.getAllPatientIdentifierTypes(); assertNotNull(patientIdTypes); PatientIdentifier patientIdentifier = new PatientIdentifier();
/** * @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#checkPatientIdentifiers(Patient) */ @Test public void checkPatientIdentifiers_shouldIgnoreVoidedPatientIdentifier() throws Exception { Patient patient = new Patient(); PatientIdentifier patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0)); patientIdentifier.setLocation(new Location(1)); patientIdentifier.setVoided(true); patientIdentifier.setVoidedBy(Context.getAuthenticatedUser()); patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored"); patient.addIdentifier(patientIdentifier); // add a non-voided identifier so that the initial // "at least one nonvoided identifier" check passes patientIdentifier = new PatientIdentifier(); patientIdentifier.setIdentifier("a non empty string"); patientIdentifier.setIdentifierType(Context.getPatientService().getAllPatientIdentifierTypes(false).get(0)); patientIdentifier.setLocation(new Location(1)); patientIdentifier.setVoided(false); patientIdentifier.setVoidedBy(Context.getAuthenticatedUser()); patientIdentifier.setVoidReason("Testing whether voided identifiers are ignored"); patient.addIdentifier(patientIdentifier); // If the identifier is ignored, it won't throw a // BlankIdentifierException as it should Context.getPatientService().checkPatientIdentifiers(patient); }
/** * @see PatientService#checkPatientIdentifiers(Patient) */ @Test(expected = DuplicateIdentifierException.class) public void checkPatientIdentifiers_shouldThrowErrorWhenPatientHasIdenticalIdentifiers() throws Exception { PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0); Patient patient = new Patient(); // Identifier #1 PatientIdentifier patientIdentifier1 = new PatientIdentifier(); patientIdentifier1.setIdentifier("123456789"); patientIdentifier1.setLocation( new Location(2) ); patientIdentifier1.setIdentifierType(patientIdentifierType); patient.addIdentifier(patientIdentifier1); // Identifier #2 PatientIdentifier patientIdentifier2 = new PatientIdentifier(); patientIdentifier2.setIdentifier("123456789"); patientIdentifier2.setIdentifierType(patientIdentifierType); patientIdentifier2.setLocation( new Location(2) ); patient.addIdentifier(patientIdentifier2); patientService.checkPatientIdentifiers(patient); }
@Override public long getAllCount() { return service.getAllPatientIdentifierTypes(false).size(); }
patient.setGender("male"); List<PatientIdentifierType> patientIdTypes = patientService.getAllPatientIdentifierTypes(); assertNotNull(patientIdTypes); PatientIdentifier patientIdentifier = new PatientIdentifier();
@Test public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() { PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0); Patient patient = new Patient(); PersonName pName = new PersonName();
@Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0); Patient patient = new Patient(); PersonName pName = new PersonName();
@Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0); Patient patient = new Patient(); PersonName pName = new PersonName();
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doGetAll(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected NeedsPaging<PatientIdentifierType> doGetAll(RequestContext context) throws ResponseException { return new NeedsPaging<PatientIdentifierType>(service().getAllPatientIdentifierTypes(context.getIncludeAll()), context); }