private void evictObsAndChildren(Obs obs) { Context.evictFromSession(obs); if(obs.hasGroupMembers()) { for(Obs member : obs.getGroupMembers()) { evictObsAndChildren(member); } } }
Context.evictFromSession(existingProgram);
@Test public void savePatient_shouldUpdateTheDateChangedAndChangedByOnUpdateOfThePersonAddress() throws Exception { Patient patient = patientService.getPatient(2); PersonAddress address = patient.getAddresses().iterator().next(); address.setAddress1("Modified Address"); patientService.savePatient(patient); Context.evictFromSession(patient); patient = patientService.getPatient(2); PersonAddress personAddress = patient.getAddresses().iterator().next(); assertNotNull(personAddress.getDateChanged()); assertNotNull(personAddress.getChangedBy()); }
/** * @see ProgramWorkflowService#saveProgram(Program) */ @Test public void saveProgram_shouldUpdateDetachedProgram() { Program program = Context.getProgramWorkflowService().getProgramByUuid("eae98b4c-e195-403b-b34a-82d94103b2c0"); program.setDescription("new description"); Context.evictFromSession(program); program = Context.getProgramWorkflowService().saveProgram(program); Assert.assertEquals("new description", program.getDescription()); }
@Test public void saveUser_shouldGrantNewRolesInRolesListToUser() { // add in some basic properties executeDataSet(XML_FILENAME); User u = userService.getUserByUsername(ADMIN_USERNAME); Role role1 = new Role(); role1.setDescription("testing1"); role1.setRole("test1"); Privilege p1 = userService.getAllPrivileges().get(0); Set<Privilege> privileges1 = new HashSet<>(); privileges1.add(p1); role1.setPrivileges(privileges1); Role role2 = new Role(); role2.setDescription("testing2"); role2.setRole("test2"); Privilege p2 = userService.getAllPrivileges().get(0); Set<Privilege> privileges2 = new HashSet<>(); privileges2.add(p2); role2.setPrivileges(privileges2); userService.saveUser(u.addRole(role1)); userService.saveUser(u.addRole(role2)); // so the contents are fetched from the db Context.evictFromSession(u); userService.getUser(u.getUserId()).hasRole("test1"); userService.getUser(u.getUserId()).hasRole("test2"); }
Context.evictFromSession(editedAllergy);
/** * @see Context#refreshAuthenticatedUser() */ @Test public void refreshAuthenticatedUser_shouldGetFreshValuesFromTheDatabase() { User evictedUser = Context.getAuthenticatedUser(); Context.evictFromSession(evictedUser); User fetchedUser = Context.getUserService().getUser(evictedUser.getUserId()); fetchedUser.getPersonName().setGivenName("new username"); Context.getUserService().saveUser(fetchedUser); // sanity check to make sure the cached object wasn't updated already Assert.assertNotSame(Context.getAuthenticatedUser().getGivenName(), fetchedUser.getGivenName()); Context.refreshAuthenticatedUser(); Assert.assertEquals("new username", Context.getAuthenticatedUser().getGivenName()); }
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(editedAllergy);
Context.evictFromSession(encounter); encounter = encounterService.getEncounter(encounterId);
public Patient getPatient(SimpleObject propertiesToCreate) { Object personProperty = propertiesToCreate.get("person"); Person person = null; if (personProperty == null) { throw new ConversionException("The person property is missing"); } else if (personProperty instanceof String) { person = Context.getPersonService().getPersonByUuid((String) personProperty); Context.evictFromSession(person); } else if (personProperty instanceof Map) { person = (Person) ConversionUtil.convert(personProperty, Person.class); propertiesToCreate.put("person", ""); } Patient delegate = new Patient(person); setConvertedProperties(delegate, propertiesToCreate, getCreatableProperties(), true); return delegate; }