@Test public void saveUser_shouldCreateNewUser() { dao.saveUser(userJoe, "Openmr5xy"); User u2 = dao.getUser(userJoe.getId()); assertNotNull("User should have been returned", u2); }
/** * @see PersonVoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldSetPersonVoidedBy() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); handler.handle(person, new User(2), null, " "); assertEquals(2, person.getPersonVoidedBy().getId().intValue()); }
/** * @see BaseVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldSetVoidedBy() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); handler.handle(voidable, new User(2), null, " "); Assert.assertEquals(2, voidable.getVoidedBy().getId().intValue()); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldSetRetiredBy() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(2, retireable.getRetiredBy().getId().intValue()); }
/** * @see PersonVoidHandler#handle(Person,User,Date,String) */ @Test public void handle_shouldNotSetPersonVoidedByIfNonNull() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonVoidedBy(new User(3)); handler.handle(person, new User(2), null, " "); assertEquals(3, person.getPersonVoidedBy().getId().intValue()); }
/** * @see BaseRetireHandler#handle(Retireable,User,Date,String) */ @Test public void handle_shouldNotSetRetiredByIfNonNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetiredBy(new User(3)); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(3, retireable.getRetiredBy().getId().intValue()); }
/** * @see BaseVoidHandler#handle(Voidable,User,Date,String) */ @Test public void handle_shouldNotSetVoidedByIfNonNull() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setVoidedBy(new User(3)); handler.handle(voidable, new User(2), null, " "); Assert.assertEquals(3, voidable.getVoidedBy().getId().intValue()); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateChangedAndChangedByOnUpdate() throws Exception { PersonService service = Context.getPersonService(); // get the type and change something about it PersonAttributeType pat = service.getPersonAttributeType(2); pat.setName("attr type name"); // save the type again service.savePersonAttributeType(pat); assertEquals(1, pat.getChangedBy().getId().intValue()); assertNotNull(pat.getDateChanged()); }
/** * @see PersonService#savePersonAttributeType(PersonAttributeType) */ @Test public void savePersonAttributeType_shouldSetTheDateCreatedAndCreatorOnNew() throws Exception { PersonService service = Context.getPersonService(); PersonAttributeType pat = new PersonAttributeType(); pat.setName("attr type name"); pat.setDescription("attr type desc"); pat.setFormat("java.lang.String"); service.savePersonAttributeType(pat); assertEquals(1, pat.getCreator().getId().intValue()); assertNotNull(pat.getDateCreated()); }
assertNotSame(encounterType.getCreator().getId(), Context.getAuthenticatedUser().getId()); assertEquals(4, encounterType.getCreator().getId().intValue()); assertNotSame(encounterType.getCreator(), Context.getAuthenticatedUser()); assertEquals(DateUtil.truncateToSeconds(date), encounterType.getDateCreated());
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldNotOverwriteCreatorIfNonNull() { EncounterService encounterService = Context.getEncounterService(); // the encounter to save with a non null creator Encounter encounter = buildEncounter(); encounter.setCreator(new User(4)); // make sure the logged in user isn't the user we're testing with assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser()); encounterService.saveEncounter(encounter); // make sure the encounter creator is user 4 not user 1 assertEquals(4, encounter.getCreator().getId().intValue()); // make sure we can fetch this new encounter // from the database and its values are the same as the passed in ones Encounter newEncounter = encounterService.getEncounter(encounter.getEncounterId()); assertNotNull(newEncounter); assertEquals(4, encounter.getCreator().getId().intValue()); assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser()); }
/** * @return id */ @Override public Integer getId() { return getUser().getId(); }
/** * @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()); }
@Test public void shouldGetCondition() { int id = 1; ConditionClinicalStatus expectedClinicalStatus = ConditionClinicalStatus.INACTIVE; ConditionVerificationStatus expectedVerificationStatus = ConditionVerificationStatus.PROVISIONAL; Condition condition = dao.getCondition(id); assertEquals(expectedClinicalStatus, condition.getClinicalStatus()); assertEquals(expectedVerificationStatus, condition.getVerificationStatus()); assertEquals(1, (int) condition.getId()); assertEquals(null, condition.getEndDate()); assertEquals(1, (int) condition.getCreator().getId()); }
@Test public void shouldGetConditionByUuid() { String uuid = "2cc6880e-2c46-15e4-9038-a6c5e4d22fb7"; ConditionClinicalStatus expectedClinicalStatus = ConditionClinicalStatus.INACTIVE; ConditionVerificationStatus expectedVerificationStatus = ConditionVerificationStatus.PROVISIONAL; Condition condition = dao.getConditionByUuid(uuid); assertEquals(condition.getClinicalStatus(), expectedClinicalStatus); assertEquals(condition.getVerificationStatus(), expectedVerificationStatus); assertEquals(1, (int) condition.getId()); assertEquals(null, condition.getEndDate()); assertEquals(1, (int) condition.getCreator().getId()); }
assertEquals(4, encounter.getCreator().getId().intValue()); assertNotSame(encounter.getCreator(), Context.getAuthenticatedUser());
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#save(java.lang.Object) */ @Override public UserAndPassword1_8 save(UserAndPassword1_8 user) { User openmrsUser = new User(); String password = user.getPassword(); openmrsUser = Context.getUserService().saveUser(user.getUser(), password); Context.refreshAuthenticatedUser(); if (openmrsUser.getId() != null && StringUtils.isNotBlank(password)) { Context.getUserService().changePassword(openmrsUser, password); } return new UserAndPassword1_8(openmrsUser); }
/** * Finds user by UserName * * @param userId User's unique Identifier ( email or MOTECH id ) * @return The User object, if found, else null. */ @Override public MRSUser getUserByUserName(String userId) { org.openmrs.User openMrsUser = getOpenMrsUserByUserName(userId); if (openMrsUser == null) { return null; } return (!isSystemAdmin(openMrsUser.getSystemId())) ? openMrsToMrsUser(openMrsUser) : new OpenMRSUser().systemId(openMrsUser.getSystemId()).id(Integer.toString(openMrsUser.getId())) .person(new OpenMRSPerson().id(Integer.toString(openMrsUser.getPerson().getId()))); }
MRSUser openMrsToMrsUser(org.openmrs.User openMRSUser) { OpenMRSUser mrsUser = new OpenMRSUser(); OpenMRSPerson mrsPerson = PersonHelper.openMRSToMRSPerson(openMRSUser.getPerson()); mrsUser.setUserId(Integer.toString(openMRSUser.getId())); mrsUser.setSystemId(openMRSUser.getSystemId()); mrsUser.setUserName(openMRSUser.getUsername()); mrsUser.setPerson(mrsPerson); mrsUser.setSecurityRole(getRoleFromOpenMRSUser(openMRSUser.getRoles())); return mrsUser; }
MRSEncounter openmrsToMrsEncounter(Encounter openMrsEncounter) { String id = Integer.toString(openMrsEncounter.getEncounterId()); String encounterType = openMrsEncounter.getEncounterType().getName(); Date date = openMrsEncounter.getEncounterDatetime(); MRSFacility facility = openMRSFacilityAdapter.convertLocationToFacility(openMrsEncounter.getLocation()); MRSPatient patient = openMRSPatientAdapter.getMrsPatient(openMrsEncounter.getPatient()); Set<? extends MRSObservation> observations = openMRSObservationAdapter.convertOpenMRSToMRSObservations(openMrsEncounter.getObs()); MRSUser creator = new OpenMRSUser().systemId(openMrsEncounter.getCreator().getSystemId()).id(openMrsEncounter.getCreator().getId().toString()); MRSPerson person = new OpenMRSPerson().id(String.valueOf(openMrsEncounter.getProvider().getId())); MRSProvider provider = new OpenMRSProvider(person); provider.setProviderId(String.valueOf(openMrsEncounter.getProvider().getId())); return new OpenMRSEncounter.MRSEncounterBuilder().withId(id).withProvider(provider).withCreator(creator).withFacility(facility) .withDate(date).withPatient(patient).withObservations(observations).withEncounterType(encounterType).build(); }