use of org.openmrs.EncounterType 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.EncounterType 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.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounters_shouldGetEncountersByType.
/**
* @see EncounterService#getEncounters(Patient, Location, Date, Date, java.util.Collection,
* java.util.Collection, java.util.Collection, boolean)
*/
@Test
public void getEncounters_shouldGetEncountersByType() {
List<EncounterType> types = new ArrayList<>();
types.add(new EncounterType(1));
EncounterSearchCriteria encounterSearchCriteria = new EncounterSearchCriteriaBuilder().setEncounterTypes(types).setIncludeVoided(true).createEncounterSearchCriteria();
List<Encounter> encounters = Context.getEncounterService().getEncounters(encounterSearchCriteria);
assertEquals(7, encounters.size());
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method unretireEncounterType_shouldThrowErrorWhenTryingToUnretireEncounterTypeWhenEncounterTypesAreLocked.
/**
* @see EncounterService#unretireEncounterType(EncounterType)
*/
@Test(expected = EncounterTypeLockedException.class)
public void unretireEncounterType_shouldThrowErrorWhenTryingToUnretireEncounterTypeWhenEncounterTypesAreLocked() {
EncounterService encounterService = Context.getEncounterService();
EncounterType encounterType = Context.getEncounterService().getEncounterType(2);
GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED);
gp.setPropertyValue("true");
Context.getAdministrationService().saveGlobalProperty(gp);
encounterService.unretireEncounterType(encounterType);
}
use of org.openmrs.EncounterType in project openmrs-core by openmrs.
the class EncounterServiceTest method getEncounterWithViewPrivilege.
/**
* Gets encounter and adds view privilege to it
*
* @return encounter with type having non null view privilege
*/
private Encounter getEncounterWithViewPrivilege() {
// 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 viewPrivilege = Context.getUserService().getPrivilege("Some Privilege For View Encounter Types");
encounterType.setViewPrivilege(viewPrivilege);
encounter.setEncounterType(encounterType);
// update encounter
encounter = encounterService.saveEncounter(encounter);
// make sure that encounter was updated successfully
assertNotNull(encounter);
return encounter;
}
Aggregations