Search in sources :

Example 1 with EncounterDomainWrapper

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;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper)

Example 2 with EncounterDomainWrapper

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;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) SimpleObject(org.openmrs.ui.framework.SimpleObject) EncounterRole(org.openmrs.EncounterRole) EncounterType(org.openmrs.EncounterType) EncounterProvider(org.openmrs.EncounterProvider) Provider(org.openmrs.Provider)

Example 3 with EncounterDomainWrapper

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;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper)

Example 4 with EncounterDomainWrapper

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;
}
Also used : EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper)

Example 5 with EncounterDomainWrapper

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);
        }
    }
}
Also used : Obs(org.openmrs.Obs) EncounterDomainWrapper(org.openmrs.module.emrapi.encounter.EncounterDomainWrapper) Disposition(org.openmrs.module.emrapi.disposition.Disposition) Encounter(org.openmrs.Encounter) DispositionDescriptor(org.openmrs.module.emrapi.disposition.DispositionDescriptor) DispositionAction(org.openmrs.module.emrapi.disposition.actions.DispositionAction)

Aggregations

EncounterDomainWrapper (org.openmrs.module.emrapi.encounter.EncounterDomainWrapper)5 Encounter (org.openmrs.Encounter)1 EncounterProvider (org.openmrs.EncounterProvider)1 EncounterRole (org.openmrs.EncounterRole)1 EncounterType (org.openmrs.EncounterType)1 Obs (org.openmrs.Obs)1 Provider (org.openmrs.Provider)1 Disposition (org.openmrs.module.emrapi.disposition.Disposition)1 DispositionDescriptor (org.openmrs.module.emrapi.disposition.DispositionDescriptor)1 DispositionAction (org.openmrs.module.emrapi.disposition.actions.DispositionAction)1 SimpleObject (org.openmrs.ui.framework.SimpleObject)1