/** * @see org.openmrs.api.EncounterService#unretireEncounterType(org.openmrs.EncounterType) */ @Override public EncounterType unretireEncounterType(EncounterType encounterType) throws APIException { Context.getEncounterService().checkIfEncounterTypesAreLocked(); encounterType.setRetired(false); return Context.getEncounterService().saveEncounterType(encounterType); }
/** * @see org.openmrs.api.EncounterService#retireEncounterType(EncounterType, String) */ @Override public EncounterType retireEncounterType(EncounterType encounterType, String reason) throws APIException { if (reason == null) { throw new IllegalArgumentException("The 'reason' for retiring is required"); } //make sure the user has not turned off encounter types editing Context.getEncounterService().checkIfEncounterTypesAreLocked(); encounterType.setRetired(true); encounterType.setRetireReason(reason); return Context.getEncounterService().saveEncounterType(encounterType); }
/** * @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#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 DelegatingCrudResource#save(java.lang.Object) */ @Override public EncounterType save(EncounterType encounterType) { return Context.getEncounterService().saveEncounterType(encounterType); }
/** * @see EncounterService#canViewAllEncounterTypes(User) */ @Test public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesViewPrivilegeColumnIsNull() { EncounterService encounterService = Context.getEncounterService(); // set viewPrivilege on each encounter type to null for (EncounterType encounterType : encounterService.getAllEncounterTypes()) { encounterType.setViewPrivilege(null); encounterService.saveEncounterType(encounterType); } User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); assertTrue(encounterService.canViewAllEncounterTypes(user)); }
/** * @see EncounterService#canEditAllEncounterTypes(User) */ @Test public void canViewAllEncounterTypes_shouldReturnTrueWhenTheEncounterTypesEditPrivilegeColumnIsNull() { EncounterService encounterService = Context.getEncounterService(); // set editPrivilege on each encounter type to null for (EncounterType encounterType : encounterService.getAllEncounterTypes()) { encounterType.setEditPrivilege(null); encounterService.saveEncounterType(encounterType); } User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); assertTrue(encounterService.canEditAllEncounterTypes(user)); }
/** * @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 EncounterService#saveEncounterType(EncounterType) */ @Test public void saveEncounterType_shouldNotOverwriteDateCreated() { EncounterService encounterService = Context.getEncounterService(); // the encounter to save without a dateCreated EncounterType encounterType = new EncounterType(); encounterType.setName("testing"); encounterType.setDescription("desc"); Date date = new Date(System.currentTimeMillis() - 5000); // make sure we // have a // date that // isn't // "right now" encounterType.setDateCreated(date); encounterService.saveEncounterType(encounterType); // make sure the encounter type date created wasn't overwritten assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated()); // make sure we can fetch this new encounter type // from the database and its values are the same as the passed in ones EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId()); assertNotNull(newEncounterType); assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated()); }
/** * @see EncounterService#saveEncounterType(EncounterType) */ @Test public void saveEncounterType_shouldSetAuditInfoIfAnyItemInEncounterTypeIsEdited() { EncounterService es = Context.getEncounterService(); // Create encounter type, ensure creator/dateCreated are set, and changedBy and dateChanged are not setDateCreated. EncounterType encounterType = es.saveEncounterType(new EncounterType("testing", "desc")); User creator = encounterType.getCreator(); Date dateCreated = encounterType.getDateCreated(); assertNotNull("creator should be set after saving", creator); assertNotNull("date creates should be set after saving", dateCreated); assertNull("changed by should not be set after creation", encounterType.getChangedBy()); assertNull("date changed should not be set after creation", encounterType.getDateChanged()); // Edit encounter type. encounterType.setDescription("This has been a test!"); EncounterType editedEt = es.saveEncounterType(encounterType); Context.flushSession(); // Ensure creator/dateCreated remain unchanged, and changedBy and dateChanged are set. assertTrue("creator should not change during edit", creator.equals(editedEt.getCreator())); assertTrue("date created should not changed during edit", dateCreated.equals(editedEt.getDateCreated())); assertNotNull("changed by should be set after edit", editedEt.getChangedBy()); assertNotNull("date changed should be set after edit", editedEt.getDateChanged()); }
/** * @see EncounterService#saveEncounterType(EncounterType) */ @Test public void saveEncounterType_shouldNotOverwriteCreator() { EncounterService encounterService = Context.getEncounterService(); // the encounter to save without a dateCreated EncounterType encounterType = new EncounterType("testing", "desc"); encounterType.setCreator(new User(4)); // make sure the logged in user isn't the user we're testing with assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser()); encounterService.saveEncounterType(encounterType); // make sure the encounter type creator is user 4 not user 1 assertEquals(4, encounterType.getCreator().getId().intValue()); assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser()); // make sure we can fetch this new encounter type // from the database and its values are the same as the passed in ones EncounterType newEncounterType = encounterService.getEncounterType(encounterType.getEncounterTypeId()); assertNotNull(newEncounterType); assertEquals(4, encounterType.getCreator().getId().intValue()); assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser()); }
encounterService.saveEncounterType(encounterType);
/** * @see EncounterService#canEditAllEncounterTypes(User) */ @Test public void canEditAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToEditEncounters() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = new EncounterType("testing", "desc"); Privilege editPrivilege = Context.getUserService().getPrivilege("Some Privilege For Edit Encounter Types"); encounterType.setEditPrivilege(editPrivilege); encounterService.saveEncounterType(encounterType); User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); assertFalse(encounterService.canEditAllEncounterTypes(user)); Role role = Context.getUserService().getRole("Provider"); role.addPrivilege(editPrivilege); user.addRole(role); assertTrue(encounterService.canEditAllEncounterTypes(user)); }
/** * @see EncounterService#canViewAllEncounterTypes(User) */ @Test public void canViewAllEncounterTypes_shouldReturnTrueIfUserIsGrantedToViewEncounters() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = new EncounterType("testing", "desc"); Privilege viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"); encounterType.setViewPrivilege(viewPrivilege); encounterService.saveEncounterType(encounterType); User user = Context.getUserService().getUserByUsername("test_user"); assertNotNull(user); assertFalse(encounterService.canViewAllEncounterTypes(user)); Role role = Context.getUserService().getRole("Provider"); role.addPrivilege(viewPrivilege); user.addRole(role); assertTrue(encounterService.canViewAllEncounterTypes(user)); }