Search in sources :

Example 21 with Location

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));
}
Also used : Encounter(org.openmrs.Encounter) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 22 with Location

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());
}
Also used : Location(org.openmrs.Location) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with Location

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);
}
Also used : OpenmrsMatchers.hasConcept(org.openmrs.test.OpenmrsMatchers.hasConcept) Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) ConceptName(org.openmrs.ConceptName) Date(java.util.Date) Location(org.openmrs.Location) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 24 with Location

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());
}
Also used : Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) Provider(org.openmrs.Provider) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 25 with Location

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;
}
Also used : Obs(org.openmrs.Obs) Location(org.openmrs.Location)

Aggregations

Location (org.openmrs.Location)235 Test (org.junit.Test)161 Date (java.util.Date)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)66 Encounter (org.openmrs.Encounter)38 SimpleObject (org.openmrs.ui.framework.SimpleObject)32 PatientIdentifierType (org.openmrs.PatientIdentifierType)31 VisitDomainWrapper (org.openmrs.module.emrapi.visit.VisitDomainWrapper)31 Visit (org.openmrs.Visit)28 AppContextModel (org.openmrs.module.appframework.context.AppContextModel)28 Obs (org.openmrs.Obs)27 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 PatientIdentifier (org.openmrs.PatientIdentifier)26 Concept (org.openmrs.Concept)19 EncounterType (org.openmrs.EncounterType)18 DateTime (org.joda.time.DateTime)17 ArrayList (java.util.ArrayList)15 VisitContextModel (org.openmrs.module.coreapps.contextmodel.VisitContextModel)15 BindException (org.springframework.validation.BindException)15