@Override protected EncounterType getExistingObject() { return encounterService.getEncounterType(EXISTING_ID); } }
@Override protected EncounterType getObjectById(Integer id) { return Context.getEncounterService().getEncounterType(id); }
/** * @see EncounterService#getEncounterType(Integer) */ @Test(expected = IllegalArgumentException.class) public void getEncounterType_shouldThrowErrorIfGivenNullParameter() { Context.getEncounterService().getEncounterType((Integer) null); }
/** * @see EncounterService#purgeEncounterType(EncounterType) */ @Test public void purgeEncounterType_shouldPurgeType() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterTypeToPurge = encounterService.getEncounterType(4); assertNotNull(encounterTypeToPurge); // check deletion encounterService.purgeEncounterType(encounterTypeToPurge); assertNull(encounterService.getEncounterType(4)); }
/** * Make sure that we are matching on exact name and not partial name in * * @see EncounterService#getEncounterType(String) */ @Test public void getEncounterType_shouldNotGetByInexactName() { EncounterService encounterService = Context.getEncounterService(); // we should not get two types here, the second one is retired EncounterType type = encounterService.getEncounterType("Test Enc Type A"); assertEquals(2, type.getEncounterTypeId().intValue()); // we should not get any encounters here even though "Test Enc" is // similar // to a name that is in the db EncounterType typeByInExactName = encounterService.getEncounterType("Test Enc"); assertNull(typeByInExactName); }
/** * @see EncounterService#retireEncounterType(EncounterType,String) */ @Test(expected = IllegalArgumentException.class) public void retireEncounterType_shouldThrowErrorIfGivenNullReasonParameter() { EncounterService encounterService = Context.getEncounterService(); EncounterType type = encounterService.getEncounterType(1); encounterService.retireEncounterType(type, null); }
/** * Make sure that the "Some Retired Type" type is not returned because it is retired in * {@link EncounterService#getEncounterType(String)} * * @see EncounterService#getEncounterType(String) */ @Test public void getEncounterType_shouldReturnNullIfOnlyRetiredTypeFound() { EncounterService encounterService = Context.getEncounterService(); // sanity check to make sure 'some retired type' is in the dataset assertTrue(encounterService.getEncounterType(4).getRetired()); assertEquals("Some Retired Type", encounterService.getEncounterType(4).getName()); // we should get a null here because this named type is retired EncounterType type = encounterService.getEncounterType("Some Retired Type"); assertNull(type); }
/** * Make sure that we are not throwing an error with a null parameter to * * @see EncounterService#getEncounterType(String) */ @Test public void getEncounterType_shouldReturnNullWithNullNameParameter() { EncounterService encounterService = Context.getEncounterService(); // we should not get an error here...but silently return nothing EncounterType type = encounterService.getEncounterType((String) null); assertNull(type); }
/** * @see EncounterService#saveEncounterType(EncounterType) */ @Test public void saveEncounterType_shouldUpdateAnExistingEncounterTypeName() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterTypeToChange = encounterService.getEncounterType(1); // change the name of the type encounterTypeToChange.setName("another test"); // save the type to the database encounterService.saveEncounterType(encounterTypeToChange); // make sure the encounter type id didn't change assertEquals(1, encounterTypeToChange.getEncounterTypeId().intValue()); // refetch the encounter type from the database EncounterType fetchedEncounterType = encounterService.getEncounterType(1); assertTrue(fetchedEncounterType.getName().equals("another test")); }
/** * @see EncounterService#getEncounterType(String) */ @Test public void getEncounterType_shouldNotGetRetiredTypes() { EncounterService encounterService = Context.getEncounterService(); // loop over all types to make sure // that the retired "Test Enc Type C" exists boolean foundRetired = false; for (EncounterType encType : encounterService.getAllEncounterTypes(true)) { if (encType.getName().equals("Test Enc Type C") && encType.getRetired()) { foundRetired = true; } } assertTrue(foundRetired); assertNull(encounterService.getEncounterType("Test Enc Type C")); }
/** * @see EncounterTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationWhenEditingAnExistingEncounterType() { EncounterType type = Context.getEncounterService().getEncounterType("Scheduled"); Assert.assertNotNull(type); Errors errors = new BindException(type, "encounterType"); new EncounterTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see EncounterService#unretireEncounterType(EncounterType) */ @Test(expected = EncounterTypeLockedException.class) public void unretireEncounterType_shouldThrowErrorWhenTryingToUnretireEncounterTypeWhenEncounterTypesAreLocked() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(2); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); encounterService.unretireEncounterType(encounterType); }
/** * @see EncounterService#saveEncounterType(EncounterType) */ @Test public void saveEncounterType_shouldSaveEncounterType() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = new EncounterType("testing", "desc"); encounterService.saveEncounterType(encounterType); // make sure an encounter type id was created assertNotNull(encounterType.getEncounterTypeId()); // make sure we can fetch this new encounter type // from the database EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId()); assertNotNull(newEncounterType); }
/** * @see EncounterTypeValidator#validate(Object, Errors) */ @Test public void validate_shouldFailIfEncounterTypeNameIsDuplicate() { Assert.assertNotNull(Context.getEncounterService().getEncounterType("Scheduled")); EncounterType newEncounterType = new EncounterType(); newEncounterType.setName("Scheduled"); Errors errors = new BindException(newEncounterType, "encounterType"); new EncounterTypeValidator().validate(newEncounterType, errors); Assert.assertTrue(errors.hasFieldErrors("name")); }
/** * @see EncounterService#retireEncounterType(EncounterType, String) */ @Test(expected = EncounterTypeLockedException.class) public void retireEncounterType_shouldThrowErrorWhenTryingToRetireEncounterTypeWhenEncounterTypesAreLocked() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); encounterService.retireEncounterType(encounterType, "reason"); }
/** * @see EncounterService#purgeEncounterType(EncounterType) */ @Test(expected = EncounterTypeLockedException.class) public void purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); encounterService.purgeEncounterType(encounterType); }
private Encounter buildEncounter() { // First, create a new Encounter Encounter enc = new Encounter(); enc.setLocation(Context.getLocationService().getLocation(1)); enc.setEncounterType(Context.getEncounterService().getEncounterType(1)); enc.setEncounterDatetime(new Date()); enc.setPatient(Context.getPatientService().getPatient(3)); enc.addProvider(Context.getEncounterService().getEncounterRole(1), Context.getProviderService().getProvider(1)); return enc; }
/** * @see EncounterService#saveEncounterType(EncounterType) * @see EncounterService#checkIfEncounterTypesAreLocked() */ @Test(expected = EncounterTypeLockedException.class) public void saveEncounterType_shouldThrowErrorWhenTryingToSaveEncounterTypeWhenEncounterTypesAreLocked() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); encounterService.saveEncounterType(encounterType); }
/** * @see VisitService#saveVisit(Visit) */ @Test(expected = TransientObjectException.class) public void saveVisit_shouldNotPersistNewEncounter() { Visit visit = visitService.getVisit(1); Encounter encounter = new Encounter(); encounter.setEncounterDatetime(new Date()); encounter.setEncounterType(Context.getEncounterService().getEncounterType(1)); encounter.setPatient(visit.getPatient()); encounter.setLocation(visit.getLocation()); visit.addEncounter(encounter); visitService.saveVisit(visit); Context.flushSession(); }
/** * @see EncounterService#retireEncounterType(EncounterType,String) */ @Test public void retireEncounterType_shouldRetireTypeAndSetAttributes() { EncounterService encounterService = Context.getEncounterService(); EncounterType type = encounterService.getEncounterType(1); assertFalse(type.getRetired()); assertNull(type.getRetiredBy()); assertNull(type.getRetireReason()); assertNull(type.getDateRetired()); EncounterType retiredEncType = encounterService.retireEncounterType(type, "Just Testing"); // make sure its still the same object assertEquals(retiredEncType, type); // make sure that all the values were filled in assertTrue(retiredEncType.getRetired()); assertNotNull(retiredEncType.getDateRetired()); assertEquals(Context.getAuthenticatedUser(), retiredEncType.getRetiredBy()); assertEquals("Just Testing", retiredEncType.getRetireReason()); }