use of org.openmrs.module.emrapi.encounter.EncounterDomainWrapper in project openmrs-module-coreapps by openmrs.
the class VisitDetailsFragmentController method verifyIfUserHasPermissionToDeleteAnEncounter.
private boolean verifyIfUserHasPermissionToDeleteAnEncounter(Encounter encounter, User authenticatedUser, boolean canDelete) {
EncounterDomainWrapper encounterDomainWrapper = new EncounterDomainWrapper(encounter);
boolean userParticipatedInEncounter = encounterDomainWrapper.participatedInEncounter(authenticatedUser);
return canDelete || userParticipatedInEncounter;
}
use of org.openmrs.module.emrapi.encounter.EncounterDomainWrapper 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.module.emrapi.encounter.EncounterDomainWrapper in project openmrs-module-coreapps by openmrs.
the class ParseEncounterToJson method verifyIfUserHasPermissionToDeleteAnEncounter.
private boolean verifyIfUserHasPermissionToDeleteAnEncounter(Encounter encounter, User authenticatedUser, boolean canDelete) {
EncounterDomainWrapper encounterDomainWrapper = new EncounterDomainWrapper(encounter);
boolean userParticipatedInEncounter = encounterDomainWrapper.participatedInEncounter(authenticatedUser);
return canDelete || userParticipatedInEncounter;
}
use of org.openmrs.module.emrapi.encounter.EncounterDomainWrapper in project openmrs-module-coreapps by openmrs.
the class ParseEncounterToJson method verifyIfUserHasPermissionToEditAnEncounter.
private boolean verifyIfUserHasPermissionToEditAnEncounter(Encounter encounter, User authenticatedUser, boolean canEdit) {
EncounterDomainWrapper encounterDomainWrapper = new EncounterDomainWrapper(encounter);
boolean userParticipatedInEncounter = encounterDomainWrapper.participatedInEncounter(authenticatedUser);
boolean userIsAdmin = authenticatedUser.isSuperUser();
return (canEdit || userParticipatedInEncounter) || userIsAdmin;
}
use of org.openmrs.module.emrapi.encounter.EncounterDomainWrapper in project openmrs-module-pihcore by PIH.
the class ApplyDispositionAction method applyDispositionActions.
void applyDispositionActions(FormEntrySession session, DispositionService dispositionService) {
DispositionDescriptor dispositionDescriptor = dispositionService.getDispositionDescriptor();
Encounter encounter = session.getEncounter();
Disposition disposition = null;
Obs dispositionObsGroup = null;
for (Obs candidate : encounter.getObsAtTopLevel(false)) {
if (dispositionDescriptor.isDisposition(candidate)) {
dispositionObsGroup = candidate;
disposition = dispositionService.getDispositionFromObsGroup(dispositionObsGroup);
}
}
if (disposition != null && disposition.getActions() != null) {
for (String actionBeanName : disposition.getActions()) {
DispositionAction action = getBean(actionBeanName, DispositionAction.class);
action.action(new EncounterDomainWrapper(encounter), dispositionObsGroup, null);
}
}
}
Aggregations