Search in sources :

Example 86 with Encounter

use of org.openmrs.Encounter in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldCascadeSaveToContainedObsWhenEncounterAlreadyExists.

/**
 * You should be able to add an obs to an encounter, save the encounter, and have the obs
 * automatically persisted.
 *
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeSaveToContainedObsWhenEncounterAlreadyExists() {
    EncounterService es = Context.getEncounterService();
    // get an encounter from the database
    Encounter encounter = es.getEncounter(1);
    assertNotNull(encounter.getEncounterDatetime());
    // Now add an obs to it
    Obs obs = new Obs();
    obs.setConcept(Context.getConceptService().getConcept(1));
    obs.setValueNumeric(50d);
    obs.setObsDatetime(new Date());
    encounter.addObs(obs);
    // there should not be an obs id before saving the encounter
    assertNull(obs.getObsId());
    es.saveEncounter(encounter);
    // the obs id should have been populated during the save
    assertNotNull(obs.getObsId());
}
Also used : Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 87 with Encounter

use of org.openmrs.Encounter in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingOrNewHandlerIsRegistered() {
    Encounter encounter = new Encounter();
    encounter.setLocation(new Location(2));
    encounter.setEncounterType(new EncounterType(1));
    encounter.setEncounterDatetime(new Date());
    encounter.setPatient(new Patient(2));
    encounter.setCreator(new User(4));
    // We should have no visit
    assertNull(encounter.getVisit());
    GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER);
    gp.setPropertyValue("org.openmrs.api.handler.ExistingOrNewVisitAssignmentHandler");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(encounter.getEncounterDatetime());
    calendar.set(Calendar.YEAR, 1900);
    encounter.setEncounterDatetime(calendar.getTime());
    Context.getEncounterService().saveEncounter(encounter);
    // We should have a visit.
    assertNotNull(encounter.getVisit());
    // The visit should be persisted.
    assertNotNull(encounter.getVisit().getVisitId());
}
Also used : User(org.openmrs.User) Calendar(java.util.Calendar) Encounter(org.openmrs.Encounter) Patient(org.openmrs.Patient) EncounterType(org.openmrs.EncounterType) Date(java.util.Date) Location(org.openmrs.Location) GlobalProperty(org.openmrs.GlobalProperty) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 88 with Encounter

use of org.openmrs.Encounter 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 89 with Encounter

use of org.openmrs.Encounter in project openmrs-core by openmrs.

the class EncounterServiceTest method saveEncounter_shouldNotCascadeToExistingOrder.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldNotCascadeToExistingOrder() {
    EncounterService es = Context.getEncounterService();
    TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
    order.setVoided(true);
    Encounter encounter = es.getEncounter(6);
    es.saveEncounter(encounter);
    String sql = "SELECT voided FROM orders WHERE order_id=7";
    Boolean voided = (Boolean) Context.getAdministrationService().executeSQL(sql, true).get(0).get(0);
    Assert.assertFalse(voided);
}
Also used : TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 90 with Encounter

use of org.openmrs.Encounter in project openmrs-core by openmrs.

the class EncounterServiceTest method getEncounters_shouldGetEncountersByVisitType.

/**
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection,
 *      boolean)
 */
@Test
public void getEncounters_shouldGetEncountersByVisitType() {
    List<VisitType> visitTypes = new ArrayList<>();
    visitTypes.add(new VisitType(2));
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setVisitTypes(visitTypes).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(2, encounters.size());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) ArrayList(java.util.ArrayList) VisitType(org.openmrs.VisitType) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Aggregations

Encounter (org.openmrs.Encounter)261 Test (org.junit.Test)204 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)153 Patient (org.openmrs.Patient)91 Date (java.util.Date)87 Order (org.openmrs.Order)46 Obs (org.openmrs.Obs)41 Visit (org.openmrs.Visit)40 Location (org.openmrs.Location)38 OrderUtilTest (org.openmrs.order.OrderUtilTest)38 DrugOrder (org.openmrs.DrugOrder)37 TestOrder (org.openmrs.TestOrder)34 EncounterType (org.openmrs.EncounterType)27 ArrayList (java.util.ArrayList)25 Concept (org.openmrs.Concept)25 BindException (org.springframework.validation.BindException)25 Calendar (java.util.Calendar)21 Errors (org.springframework.validation.Errors)21 User (org.openmrs.User)20 PihCoreContextSensitiveTest (org.openmrs.module.pihcore.PihCoreContextSensitiveTest)19