use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-mirebalais by PIH.
the class RequireUtilTest method shouldReturnFalseIfVisitNotActive.
@Test
public void shouldReturnFalseIfVisitNotActive() {
VisitDomainWrapper visit = mock(VisitDomainWrapper.class);
when(visit.isActive()).thenReturn(false);
AppContextModel appContextModel = uiSessionContext.generateAppContextModel();
appContextModel.put("visit", visit);
assertThat(appFrameworkService.checkRequireExpression(extensionRequiring(patientHasActiveVisit()), appContextModel), is(false));
}
use of org.openmrs.module.appframework.context.AppContextModel 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.module.appframework.context.AppContextModel 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.module.appframework.context.AppContextModel in project openmrs-module-coreapps by openmrs.
the class MergePatientsPageController method post.
public String post(UiUtils ui, HttpServletRequest request, PageModel pageModel, @RequestParam("patient1") Patient patient1, @RequestParam("patient2") Patient patient2, @RequestParam("preferred") Patient preferred, @RequestParam(value = "isUnknownPatient", defaultValue = "false") boolean isUnknownPatient, @InjectBeans PatientDomainWrapper preferredWrapper, @InjectBeans PatientDomainWrapper notPreferredWrapper, @RequestParam("app") AppDescriptor app, @SpringBean("appframeworkTemplateFactory") TemplateFactory templateFactory, UiSessionContext sessionContext, @SpringBean("adtService") AdtService adtService) {
Patient notPreferred = patient1.equals(preferred) ? patient2 : patient1;
preferredWrapper.setPatient(preferred);
notPreferredWrapper.setPatient(notPreferred);
if (preferredWrapper.isUnknownPatient() && !notPreferredWrapper.isUnknownPatient()) {
request.getSession().setAttribute("emr.errorMessage", ui.message("coreapps.mergePatients.unknownPatient.error"));
preferredWrapper.setPatient(patient1);
notPreferredWrapper.setPatient(patient2);
Map<String, Object> params = new HashMap<String, Object>();
params.put("app", "coreapps.mergePatients");
params.put("patient1", preferred);
params.put("patient2", notPreferred);
params.put("isUnknownPatient", isUnknownPatient);
return "redirect:" + ui.pageLink("coreapps", "datamanagement/mergePatients", params);
}
adtService.mergePatients(preferred, notPreferred);
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_INFO_MESSAGE, "coreapps.mergePatients.success");
request.getSession().setAttribute(AppUiConstants.SESSION_ATTRIBUTE_TOAST_MESSAGE, "true");
String provider = "coreapps";
String fragment = "patientdashboard/patientDashboard";
String returnUrl = null;
if (app.getConfig() != null && app.getConfig().get("dashboardUrl") != null) {
returnUrl = app.getConfig().get("dashboardUrl").getTextValue();
}
if (StringUtils.isNotBlank(returnUrl)) {
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patientId", preferred.getId());
returnUrl = templateFactory.handlebars(returnUrl, contextModel);
} else {
returnUrl = ui.pageLink(provider, fragment, SimpleObject.create("patientId", preferred.getId()));
}
return "redirect:" + returnUrl;
}
use of org.openmrs.module.appframework.context.AppContextModel in project openmrs-module-coreapps by openmrs.
the class PatientHeaderFragmentController method controller.
public void controller(FragmentConfiguration config, @SpringBean("emrApiProperties") EmrApiProperties emrApiProperties, @SpringBean("coreAppsProperties") CoreAppsProperties coreAppsProperties, @SpringBean("baseIdentifierSourceService") IdentifierSourceService identifierSourceService, @FragmentParam(required = false, value = "appContextModel") AppContextModel appContextModel, @SpringBean("appFrameworkService") AppFrameworkService appFrameworkService, @FragmentParam("patient") Object patient, @InjectBeans PatientDomainWrapper wrapper, @SpringBean("adtService") AdtService adtService, UiSessionContext sessionContext, UiUtils uiUtils, FragmentModel model) {
if (patient instanceof Patient) {
wrapper.setPatient((Patient) patient);
} else {
wrapper = (PatientDomainWrapper) patient;
}
config.addAttribute("patient", wrapper);
config.addAttribute("patientNames", getNames(wrapper.getPersonName()));
if (appContextModel == null) {
AppContextModel contextModel = sessionContext.generateAppContextModel();
contextModel.put("patient", new PatientContextModel(wrapper.getPatient()));
model.addAttribute("appContextModel", contextModel);
}
List<Extension> firstLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.firstLineFragments");
Collections.sort(firstLineFragments);
model.addAttribute("firstLineFragments", firstLineFragments);
List<Extension> secondLineFragments = appFrameworkService.getExtensionsForCurrentUser("patientHeader.secondLineFragments");
Collections.sort(secondLineFragments);
model.addAttribute("secondLineFragments", secondLineFragments);
List<ExtraPatientIdentifierType> extraPatientIdentifierTypes = new ArrayList<ExtraPatientIdentifierType>();
for (PatientIdentifierType type : emrApiProperties.getExtraPatientIdentifierTypes()) {
List<AutoGenerationOption> options = identifierSourceService.getAutoGenerationOptions(type);
// TODO note that this may allow use to edit a identifier that should not be editable, or vice versa, in the rare case where there are multiple autogeneration
// TODO options for a single identifier type (which is possible if you have multiple locations) and the manual entry boolean is different between those two generators
extraPatientIdentifierTypes.add(new ExtraPatientIdentifierType(type, options.size() > 0 ? options.get(0).isManualEntryEnabled() : true));
}
config.addAttribute("extraPatientIdentifierTypes", extraPatientIdentifierTypes);
config.addAttribute("extraPatientIdentifiersMappedByType", wrapper.getExtraIdentifiersMappedByType(sessionContext.getSessionLocation()));
config.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
}
Aggregations