use of org.openmrs.Location in project openmrs-core by openmrs.
the class EncounterServiceTest method filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters.
/**
* @see EncounterService#filterEncountersByViewPermissions(List, User)
*/
@Test
public void filterEncountersByViewPermissions_shouldFilterEncountersIfUserIsNotAllowedToSeeSomeEncounters() {
EncounterService encounterService = Context.getEncounterService();
int expectedSize = encounterService.getEncountersByPatientId(3).size();
Encounter encounter = new Encounter();
encounter.setLocation(new Location(1));
encounter.setEncounterDatetime(new Date());
encounter.setPatient(Context.getPatientService().getPatient(3));
EncounterType encounterType = new EncounterType(1);
encounterType.setViewPrivilege(Context.getUserService().getPrivilege("Some Privilege For View Encounter Types"));
encounter.setEncounterType(encounterType);
EncounterRole role = new EncounterRole();
role.setName("role");
role = encounterService.saveEncounterRole(role);
Provider provider = new Provider();
provider.setIdentifier("id1");
provider.setPerson(newPerson("name"));
provider = Context.getProviderService().saveProvider(provider);
encounter.addProvider(role, provider);
encounterService.saveEncounter(encounter);
List<Encounter> patientEncounters = encounterService.getEncountersByPatientId(3);
assertEquals(expectedSize + 1, patientEncounters.size());
if (Context.isAuthenticated()) {
Context.logout();
}
Context.authenticate("test_user", "test");
Context.addProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
patientEncounters = encounterService.getEncountersByPatientId(3);
int actualSize = patientEncounters.size();
Context.removeProxyPrivilege(PrivilegeConstants.GET_ENCOUNTERS);
Context.logout();
assertEquals(actualSize, expectedSize);
assertTrue(!patientEncounters.contains(encounter));
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldSetAuditInfoIfAnyItemInTheLocationIsEdited.
/**
* should set audit info if any item in the location is edited
*
* @see LocationService#saveLocation(Location)
*/
@Test
public void saveLocation_shouldSetAuditInfoIfAnyItemInTheLocationIsEdited() {
LocationService ls = Context.getLocationService();
Location location = ls.getLocation(1);
Assert.assertNotNull(location);
Assert.assertNull(location.getDateChanged());
Assert.assertNull(location.getChangedBy());
location.setName("edited name");
ls.saveLocation(location);
Location editedLocation = Context.getLocationService().saveLocation(location);
Context.flushSession();
Assert.assertNotNull(editedLocation.getDateChanged());
Assert.assertNotNull(editedLocation.getChangedBy());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class ConceptServiceTest method purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs.
/**
* @see ConceptService#purgeConcept(Concept)
*/
@Test(expected = ConceptNameInUseException.class)
public void purgeConcept_shouldFailIfAnyOfTheConceptNamesOfTheConceptIsBeingUsedByAnObs() {
Obs o = new Obs();
o.setConcept(Context.getConceptService().getConcept(3));
o.setPerson(new Patient(2));
o.setEncounter(new Encounter(3));
o.setObsDatetime(new Date());
o.setLocation(new Location(1));
ConceptName conceptName = new ConceptName(1847);
o.setValueCodedName(conceptName);
Context.getObsService().saveObs(o, null);
// ensure that the association between the conceptName and the obs has been established
Assert.assertEquals(true, conceptService.hasAnyObservation(conceptName));
Concept concept = conceptService.getConceptByName("cd4 count");
// make sure the name concept name exists
Assert.assertNotNull(concept);
conceptService.purgeConcept(concept);
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class EncounterServiceTest method voidEncounter_shouldNotVoidProviders.
/**
* @see EncounterService#voidEncounter(Encounter, String)
*/
@Test
public void voidEncounter_shouldNotVoidProviders() {
EncounterService encounterService = Context.getEncounterService();
Encounter encounter = new Encounter();
encounter.setLocation(new Location(1));
encounter.setEncounterType(new EncounterType(1));
encounter.setEncounterDatetime(new Date());
encounter.setPatient(new Patient(3));
EncounterRole role = new EncounterRole();
role.setName("role");
role = encounterService.saveEncounterRole(role);
Provider provider = new Provider();
provider.setIdentifier("id1");
provider.setPerson(newPerson("name"));
provider = Context.getProviderService().saveProvider(provider);
encounter.addProvider(role, provider);
encounterService.saveEncounter(encounter);
assertEquals(1, encounter.getProvidersByRoles().size());
encounterService.voidEncounter(encounter, "reason");
encounter = encounterService.getEncounter(encounter.getEncounterId());
assertEquals(1, encounter.getProvidersByRoles().size());
}
use of org.openmrs.Location in project openmrs-core by openmrs.
the class EncounterServiceTest method buildObs.
private Obs buildObs() {
Obs newObs = new Obs();
newObs.setConcept(Context.getConceptService().getConcept(1));
newObs.setValueNumeric(50d);
newObs.setLocation(new Location(2));
return newObs;
}
Aggregations