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));
}
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());
}
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());
}
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;
}
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());
}
Aggregations