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