use of org.openmrs.EncounterRole in project openmrs-module-coreapps by openmrs.
the class ParseEncounterToJson method createEncounterJSON.
public SimpleObject createEncounterJSON(User authenticatedUser, Encounter encounter) {
boolean canDelete = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_DELETE_ENCOUNTER);
boolean canEdit = authenticatedUser.hasPrivilege(EmrApiConstants.PRIVILEGE_EDIT_ENCOUNTER);
SimpleObject simpleEncounter = SimpleObject.fromObject(new EncounterDomainWrapper(encounter), uiUtils, "encounterId", "location", "encounterDatetime", "encounterProviders.provider", "voided", "form");
// UUID is not provided by EncounterDomainWrapper, adding it here.
simpleEncounter.put("uuid", encounter.getUuid());
// manually set the date and time components so we can control how we format them
simpleEncounter.put("encounterDate", DateFormatUtils.format(encounter.getEncounterDatetime(), "dd MMM yyyy", Context.getLocale()));
simpleEncounter.put("encounterTime", DateFormatUtils.format(encounter.getEncounterDatetime(), "hh:mm a", Context.getLocale()));
// do the same for other date fields
simpleEncounter.put("dateCreated", DateFormatUtils.format(encounter.getDateCreated(), "dd MMM yyyy", Context.getLocale()));
simpleEncounter.put("creator", uiUtils.format(encounter.getCreator()));
if (encounter.getDateChanged() != null) {
simpleEncounter.put("dateChanged", DateFormatUtils.format(encounter.getDateChanged(), "dd MMM yyyy", Context.getLocale()));
}
if (encounter.getChangedBy() != null) {
simpleEncounter.put("changedBy", uiUtils.format(encounter.getChangedBy()));
}
EncounterType encounterType = encounter.getEncounterType();
simpleEncounter.put("encounterType", SimpleObject.create("uuid", encounterType.getUuid(), "name", uiUtils.format(encounterType)));
// determine the provider
Provider primaryProvider = null;
// if a primary encounter role has been specified, get the provider for that role
EncounterRole primaryEncounterRole = getPrimaryEncounterRoleForEncounter(encounter);
if (primaryEncounterRole != null) {
Set<Provider> providers = encounter.getProvidersByRole(primaryEncounterRole);
if (providers != null && !providers.isEmpty()) {
// for now, if there are multiple providers with this role, return an arbitrary one
primaryProvider = providers.iterator().next();
}
}
// otherwise, just pick an arbitrary (non-voided) provider
if (primaryProvider == null) {
primaryProvider = getFirstNonVoidedProvider(encounter);
}
simpleEncounter.put("primaryProvider", uiUtils.format(primaryProvider));
if (verifyIfUserHasPermissionToDeleteAnEncounter(encounter, authenticatedUser, canDelete)) {
simpleEncounter.put("canDelete", true);
}
if (verifyIfUserHasPermissionToEditAnEncounter(encounter, authenticatedUser, canEdit)) {
simpleEncounter.put("canEdit", true);
} else {
simpleEncounter.put("canEdit", false);
}
if (encounter.getVisit() != null) {
simpleEncounter.put("visitId", encounter.getVisit().getId());
}
return simpleEncounter;
}
use of org.openmrs.EncounterRole in project openmrs-core by openmrs.
the class EncounterServiceTest method retireEncounterRole_shouldRetireTypeAndSetAttributes.
/**
* @see EncounterService#retireEncounterRole(org.openmrs.EncounterRole, String)
*/
@Test
public void retireEncounterRole_shouldRetireTypeAndSetAttributes() {
EncounterService encounterService = Context.getEncounterService();
EncounterRole encounterRole = encounterService.getEncounterRole(1);
assertFalse(encounterRole.getRetired());
assertNull(encounterRole.getRetiredBy());
assertNull(encounterRole.getRetireReason());
assertNull(encounterRole.getDateRetired());
EncounterRole retiredEncounterRole = encounterService.retireEncounterRole(encounterRole, "Just Testing");
assertEquals(retiredEncounterRole, encounterRole);
assertTrue(retiredEncounterRole.getRetired());
assertNotNull(retiredEncounterRole.getDateRetired());
assertEquals(Context.getAuthenticatedUser(), retiredEncounterRole.getRetiredBy());
assertEquals("Just Testing", retiredEncounterRole.getRetireReason());
}
use of org.openmrs.EncounterRole in project openmrs-core by openmrs.
the class EncounterServiceTest method saveEncounterRole_shouldSaveEncounterRoleWithBasicDetails.
/**
* @see org.openmrs.api.EncounterService#saveEncounterRole(org.openmrs.EncounterRole)
*/
@Test
public void saveEncounterRole_shouldSaveEncounterRoleWithBasicDetails() {
EncounterRole encounterRole = new EncounterRole();
encounterRole.setName("Attending physician");
encounterRole.setDescription("The person in charge");
EncounterService encounterService = Context.getEncounterService();
encounterService.saveEncounterRole(encounterRole);
assertNotNull("The saved encounter role should have an encounter role id now", encounterRole.getEncounterRoleId());
EncounterRole newSavedEncounterRole = encounterService.getEncounterRole(encounterRole.getEncounterRoleId());
assertNotNull("We should get back an encounter role", newSavedEncounterRole);
assertEquals(encounterRole, newSavedEncounterRole);
assertTrue("The created encounter role needs to equal the pojo encounter role", encounterRole.equals(newSavedEncounterRole));
}
use of org.openmrs.EncounterRole in project openmrs-core by openmrs.
the class EncounterServiceTest method retireEncounterRole_shouldThrowErrorIfGivenNullReasonParameter.
/**
* @see EncounterService#retireEncounterRole(org.openmrs.EncounterRole, String)
*/
@Test(expected = IllegalArgumentException.class)
public void retireEncounterRole_shouldThrowErrorIfGivenNullReasonParameter() {
EncounterService encounterService = Context.getEncounterService();
EncounterRole encounterRole = encounterService.getEncounterRole(1);
encounterService.retireEncounterRole(encounterRole, null);
}
use of org.openmrs.EncounterRole in project openmrs-core by openmrs.
the class EncounterServiceTest method filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull.
/**
* @see EncounterService#filterEncountersByViewPermissions(List, User)
*/
@Test
public void filterEncountersByViewPermissions_shouldNotFilterAllEncountersWhenTheEncounterTypesViewPrivilegeColumnIsNull() {
EncounterService encounterService = Context.getEncounterService();
int beforeSize = 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);
// viewPrivilege on encounter type intentionally left null
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);
assertNotNull(patientEncounters);
assertEquals(beforeSize + 1, patientEncounters.size());
}
Aggregations