Search in sources :

Example 96 with Encounter

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

the class EncounterServiceTest method getEncounters_shouldGetEncountersOnOrUpToADate.

/**
 * @throws ParseException
 * @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
 *      java.util.Collection, java.util.Collection, boolean)
 */
@Test
public void getEncounters_shouldGetEncountersOnOrUpToADate() throws ParseException {
    Date toDate = new SimpleDateFormat("yyyy-dd-MM").parse("2006-01-01");
    EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setToDate(toDate).setIncludeVoided(true).createEncounterSearchCriteria();
    List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
    assertEquals(2, encounters.size());
    assertEquals(15, encounters.get(0).getEncounterId().intValue());
    assertEquals(1, encounters.get(1).getEncounterId().intValue());
}
Also used : EncounterSearchCriteria(org.openmrs.parameter.EncounterSearchCriteria) EncounterSearchCriteriaBuilder(org.openmrs.parameter.EncounterSearchCriteriaBuilder) Encounter(org.openmrs.Encounter) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 97 with Encounter

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

the class EncounterServiceTest method purgeEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter.

/**
 * @see EncounterService#purgeEncounter(Encounter)
 */
@Test(expected = APIException.class)
public void purgeEncounter_shouldFailfIfUserIsNotSupposedToEditEncountersOfTypeOfGivenEncounter() {
    // get encounter that has type with edit privilege set
    Encounter encounter = getEncounterWithEditPrivilege();
    User user = Context.getUserService().getUserByUsername("test_user");
    assertNotNull(user);
    // left this user as is - i.e. without required privilege
    // and authenticate under it's account
    Context.becomeUser(user.getSystemId());
    // have to add privilege in order to be able to call purgeEncounter(Encounter) method
    Context.addProxyPrivilege(PrivilegeConstants.PURGE_ENCOUNTERS);
    Context.getEncounterService().purgeEncounter(encounter);
}
Also used : User(org.openmrs.User) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 98 with Encounter

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

the class EncounterServiceTest method saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldSetDateStoppedOnTheOriginalAfterAddingReviseOrder() {
    EncounterService es = Context.getEncounterService();
    TestOrder order = (TestOrder) Context.getOrderService().getOrder(7);
    Assert.assertNull(order.getDateStopped());
    Encounter encounter = es.getEncounter(6);
    TestOrder reviseOrder = order.cloneForRevision();
    reviseOrder.setOrderer(Context.getProviderService().getProvider(1));
    encounter.addOrder(reviseOrder);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    Date dateStopped = Context.getOrderService().getOrder(7).getDateStopped();
    Assert.assertNotNull(dateStopped);
}
Also used : TestOrder(org.openmrs.TestOrder) Encounter(org.openmrs.Encounter) Date(java.util.Date) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 99 with Encounter

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

the class EncounterServiceTest method unvoidEncounter_shouldCascadeUnvoidToObs.

/**
 * @see EncounterService#unvoidEncounter(Encounter)
 */
@Test
public void unvoidEncounter_shouldCascadeUnvoidToObs() {
    EncounterService encounterService = Context.getEncounterService();
    // get a voided encounter that has some voided obs
    Encounter encounter = encounterService.getEncounter(2);
    encounterService.unvoidEncounter(encounter);
    Obs obs = Context.getObsService().getObs(4);
    assertFalse(obs.getVoided());
    assertNull(obs.getVoidReason());
}
Also used : Obs(org.openmrs.Obs) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 100 with Encounter

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

the class EncounterServiceTest method voidEncounter_shouldCascadeToOrders.

/**
 * @see EncounterService#voidEncounter(Encounter,String)
 */
@Test
public void voidEncounter_shouldCascadeToOrders() {
    EncounterService encounterService = Context.getEncounterService();
    // get a nonvoided encounter that has some obs
    Encounter encounter = encounterService.getEncounter(1);
    encounterService.voidEncounter(encounter, "Just Testing");
    Order order = Context.getOrderService().getOrder(1);
    assertTrue(order.getVoided());
    assertEquals("Just Testing", order.getVoidReason());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) 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