use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method shouldReturnFalseIfLocationDOesNotHaveTagAndVisitNotActive.
@Test
public void shouldReturnFalseIfLocationDOesNotHaveTagAndVisitNotActive() {
Location sessionLocation = new Location();
SimpleObject sessionLocationRestRep = new SimpleObject();
sessionLocationRestRep.put("uuid", "123abc");
SimpleObject admitTag = new SimpleObject();
admitTag.put("display", LocationTags.CHECKIN_LOCATION.name());
sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
PowerMockito.mockStatic(ConversionUtil.class);
when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
when(visit.isActive()).thenReturn(false);
uiSessionContext.setSessionLocation(sessionLocation);
AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
appContextModel.put("visit", visit);
assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION), patientHasActiveVisit())), appContextModel), is(false));
}
use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilege.
@Test
public void shouldReturnTrueIfProperLocationTagAndUserHasRetroPrivilege() {
user.addRole(admin);
Location sessionLocation = new Location();
SimpleObject sessionLocationRestRep = new SimpleObject();
sessionLocationRestRep.put("uuid", "123abc");
SimpleObject admitTag = new SimpleObject();
admitTag.put("display", LocationTags.CONSULT_NOTE_LOCATION.name());
sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
PowerMockito.mockStatic(ConversionUtil.class);
when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
VisitContextModel visit = mock(VisitContextModel.class);
when(visit.getStopDatetimeInMilliseconds()).thenReturn(new DateTime(2014, 1, 1, 1, 1).getMillis());
uiSessionContext.setSessionLocation(sessionLocation);
AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
appContextModel.put("visit", visit);
Config config = mock(Config.class);
when(config.isComponentEnabled("visitNote")).thenReturn(false);
assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.CONSULT_NOTE_LOCATION), or(and(userHasPrivilege(Privileges.TASK_EMR_ENTER_CONSULT_NOTE), patientHasActiveVisit()), userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE), and(userHasPrivilege(Privileges.TASK_EMR_RETRO_CLINICAL_NOTE_THIS_PROVIDER_ONLY), patientVisitWithinPastThirtyDays(config))))), appContextModel), is(true));
}
use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method shouldReturnTrueIfLocationHasTagAndVisitActive.
@Test
public void shouldReturnTrueIfLocationHasTagAndVisitActive() {
Location sessionLocation = new Location();
SimpleObject sessionLocationRestRep = new SimpleObject();
sessionLocationRestRep.put("uuid", "123abc");
SimpleObject admitTag = new SimpleObject();
admitTag.put("display", LocationTags.ADMISSION_LOCATION.name());
sessionLocationRestRep.put("tags", Arrays.asList(admitTag));
PowerMockito.mockStatic(ConversionUtil.class);
when(ConversionUtil.convertToRepresentation(sessionLocation, Representation.DEFAULT)).thenReturn(sessionLocationRestRep);
VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
when(visit.isActive()).thenReturn(true);
uiSessionContext.setSessionLocation(sessionLocation);
AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
appContextModel.put("visit", visit);
assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(and(sessionLocationHasTag(LocationTags.ADMISSION_LOCATION), patientHasActiveVisit())), appContextModel), is(true));
}
use of org.openmrs.ui.framework.SimpleObject in project openmrs-module-mirebalais by PIH.
the class PatientPageController method controller.
public void controller(@RequestParam("patientId") Patient patient, UiUtils ui, EmrContext emrContext, PageModel model, @SpringBean("formService") FormService formService, @InjectBeans PatientDomainWrapper patientDomainWrapper) {
patientDomainWrapper.setPatient(patient);
SimpleObject appHomepageBreadcrumb = SimpleObject.create("label", ui.message("mirebalais.outpatientVitals.title"), "link", ui.pageLink("coreapps", "findpatient/findPatient", Collections.singletonMap("app", (Object) "mirebalais.outpatientVitals")));
SimpleObject patientPageBreadcrumb = SimpleObject.create("label", patient.getFamilyName() + ", " + patient.getGivenName(), "link", ui.thisUrlWithContextPath());
Form outpatientVitalsForm = formService.getFormByUuid("68728aa6-4985-11e2-8815-657001b58a90");
List<Encounter> existingEncounters = new ArrayList<Encounter>();
if (emrContext.getActiveVisit() != null) {
for (Encounter encounter : emrContext.getActiveVisit().getVisit().getEncounters()) {
if (!encounter.isVoided() && outpatientVitalsForm.equals(encounter.getForm())) {
existingEncounters.add(encounter);
}
}
}
model.addAttribute("visit", emrContext.getActiveVisit() != null ? emrContext.getActiveVisit().getVisit() : null);
model.addAttribute("existingEncounters", existingEncounters);
model.addAttribute("patient", patientDomainWrapper);
model.addAttribute("breadcrumbOverride", ui.toJson(Arrays.asList(appHomepageBreadcrumb, patientPageBreadcrumb)));
model.addAttribute("appName", CustomAppLoaderConstants.Apps.UHM_VITALS);
}
use of org.openmrs.ui.framework.SimpleObject 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;
}
Aggregations