Search in sources :

Example 76 with Encounter

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

the class EncounterServiceTest method saveEncounter_shouldCascadeDeleteEncounterProviders.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadeDeleteEncounterProviders() {
    // given
    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 = Context.getEncounterService().saveEncounterRole(role);
    Provider provider = new Provider();
    provider.setIdentifier("id1");
    provider.setPerson(newPerson("name"));
    provider = Context.getProviderService().saveProvider(provider);
    Provider provider2 = new Provider();
    provider2.setIdentifier("id2");
    provider2.setPerson(newPerson("name2"));
    provider2 = Context.getProviderService().saveProvider(provider2);
    encounter.addProvider(role, provider);
    encounter.addProvider(role, provider2);
    EncounterService es = Context.getEncounterService();
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // when
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    encounter.setProvider(role, provider);
    es.saveEncounter(encounter);
    Context.flushSession();
    Context.clearSession();
    // then
    encounter = Context.getEncounterService().getEncounter(encounter.getEncounterId());
    Assert.assertEquals(1, encounter.getProvidersByRole(role).size());
    Assert.assertTrue("Role", encounter.getProvidersByRole(role).contains(provider));
}
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 77 with Encounter

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

the class EncounterServiceTest method transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient.

/**
 * @see EncounterService#transferEncounter(Encounter,Patient)
 */
@Test
public void transferEncounter_shouldTransferAnEncounterWithObservationsButNotOrdersToGivenPatient() {
    executeDataSet(TRANSFER_ENC_DATA_XML);
    Patient targetPatient = Context.getPatientService().getPatient(201);
    // encounter has 2 obs which are connected with the same order
    Encounter sourceEncounter = Context.getEncounterService().getEncounter(201);
    Assert.assertEquals(2, sourceEncounter.getOrders().size());
    Assert.assertEquals(2, sourceEncounter.getObs().size());
    // transfer
    Encounter transferredEncounter = Context.getEncounterService().transferEncounter(sourceEncounter, targetPatient);
    List<Order> transferredOrders = new ArrayList<>(transferredEncounter.getOrders());
    List<Obs> transferredObservations = new ArrayList<>(transferredEncounter.getObs());
    // check if transferredEncounter is newly created encounter
    Assert.assertNotEquals(sourceEncounter.getId(), transferredEncounter.getId());
    Assert.assertEquals(targetPatient, transferredEncounter.getPatient());
    // check order
    Assert.assertEquals(0, transferredOrders.size());
    // check obs
    Assert.assertEquals(2, transferredObservations.size());
    Assert.assertEquals(targetPatient, transferredObservations.get(0).getPerson());
    Assert.assertEquals(targetPatient, transferredObservations.get(1).getPerson());
    Assert.assertNull(transferredObservations.get(0).getOrder());
    Assert.assertNull(transferredObservations.get(1).getOrder());
    // check if form is transferred
    Assert.assertNotNull(transferredEncounter.getForm());
}
Also used : TestOrder(org.openmrs.TestOrder) Order(org.openmrs.Order) Obs(org.openmrs.Obs) ArrayList(java.util.ArrayList) Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 78 with Encounter

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

the class EncounterServiceTest method transferEncounter_shouldVoidGivenEncounter.

/**
 * @see EncounterService#transferEncounter(Encounter,Patient)
 */
@Test
public void transferEncounter_shouldVoidGivenEncounter() {
    executeDataSet(TRANSFER_ENC_DATA_XML);
    Patient anyPatient = new Patient(2);
    Encounter sourceEncounter = Context.getEncounterService().getEncounter(200);
    Context.getEncounterService().transferEncounter(sourceEncounter, anyPatient);
    // get fresh encounter from db
    Encounter sourceEncounterAfterTransfer = Context.getEncounterService().getEncounter(sourceEncounter.getId());
    Assert.assertTrue(sourceEncounterAfterTransfer.getVoided());
}
Also used : Patient(org.openmrs.Patient) Encounter(org.openmrs.Encounter) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) Test(org.junit.Test)

Example 79 with Encounter

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

the class EncounterServiceTest method getEncounterWithEditPrivilege.

/**
 * Gets encounter and adds edit privilege to it
 *
 * @return encounter with type having non null edit privilege
 */
private Encounter getEncounterWithEditPrivilege() {
    // create service to be used for encounter manipulations
    EncounterService encounterService = Context.getEncounterService();
    Encounter encounter = encounterService.getEncounter(1);
    EncounterType encounterType = encounter.getEncounterType();
    // make sure that encounter type is not null
    assertNotNull(encounterType);
    // set view privilege on this encounter type
    Privilege editPrivilege = Context.getUserService().getPrivilege("Some Privilege For Edit Encounter Types");
    encounterType.setEditPrivilege(editPrivilege);
    encounter.setEncounterType(encounterType);
    // update encounter
    encounter = encounterService.saveEncounter(encounter);
    // make sure that encounter type updated successfully
    assertNotNull(encounter);
    return encounter;
}
Also used : Encounter(org.openmrs.Encounter) EncounterType(org.openmrs.EncounterType) Privilege(org.openmrs.Privilege)

Example 80 with Encounter

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

the class EncounterServiceTest method saveEncounter_shouldCascadePatientToOrdersInTheEncounter.

/**
 * @see EncounterService#saveEncounter(Encounter)
 */
@Test
public void saveEncounter_shouldCascadePatientToOrdersInTheEncounter() {
    Encounter enc = Context.getEncounterService().getEncounter(15);
    Order existing = enc.getOrders().iterator().next();
    // for some reason the xml for the existing encounter has already given
    // this order a different patient than the encounter that it's contained
    // in, but let's verify that:
    Assert.assertNotSame(enc.getPatient().getId(), existing.getPatient().getId());
    Context.getEncounterService().saveEncounter(enc);
    Assert.assertEquals(enc.getPatient().getId(), existing.getPatient().getId());
}
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