Require Attribute for Apps and Extensions using Context Models

Continuing the discussion from Patient Summary Widgets Sprint:

@darius I am breaking this out into a new topic for your advice

@ssmusoke can you please summarize what you’re intending to do?

I think you’re saying that you want a widget to be displayed on the patient dashboard only if a certain condition is true, e.g. patient is female.

I don’t know if the code has changed since I last looked at it, but I recall that we have two extension points on the patient dashboard, for left column widgets and right column widgets. So, “what widgets to show in the dashboard?” means “which extensions are active for the (left/right) column extension point?”

In other words, the widget is an extension, so you should be able to just add a require field at the line Rafal referred to. Can you try something as simple as "require":"false" and check if this hides things?

Exactly that is what I am trying to do, which I thought would use the context models just like the forms.

This does not seem to work for the dashboard widgets see https://qa-refapp.openmrs.org/openmrs/coreapps/clinicianfacing/patient.page?patientId=fedaa0cb-974c-4258-ba6c-379653c66ab5 for the Recent Visits - Hidden widget

The app definition is below:

{ "id": "coreapps.visitByEncounterType.hidden", "instanceOf": "coreapps.template.dashboardWidget", "description": "coreapps.visitByEncounterType.app.description", "order": 50, "config": { "widget": "visitbyencountertype", "icon": "icon-group", "label": "RECENT VISITS - HIDDEN", "maxRecords": "8", "maxAge": "60m", "combineEncounterTypes": "true" }, "extensions": [ { "id": "org.openmrs.module.coreapps.mostRecentVitals.clinicianDashboardSecondColumn", "appId": "coreapps.visitByEncounterType.hidden", "extensionPointId": "patientDashboard.secondColumnFragments", "require":"false", "extensionParams": { "provider": "coreapps", "fragment": "dashboardwidgets/dashboardWidget" } } ] }

I see this error in the logs on that server, although I don’t know if it’s relevant:

ERROR - AppFrameworkActivator.registerAppsAndExtensions(101) |2017-06-01 06:07:56,298| Error loading app framework. Some apps might not work.org.openmrs.module.appframework.factory.UserAppFactory@3ad6e318 java.lang.IllegalStateException: App ‘coreapps.visitByEncounterType.hidden’ says its an instanceOf ‘coreapps.template.dashboardWidget’ but there is no AppTemplate with that id

I haven’t looked into at the way you all have set up things, such that each widget is an app. (This seems wrong to me; I would expect that if you have 5 widgets, those are 5 extensions in a single app.)

I think someone will need to debug this code and see why the require expression isn’t being evaluated (or why it’s evaluating wrong). Because in theory just adding the require on the extension should work, we shouldn’t need an equivalent function on apps.

@darius Do you have time for a call today to help me better understand how apps, extensions are expected to work as per the design? I am available up to 5:00pm UTC

@ssmusoke apps can declare app templates, from the error messages it shows that you’re referencing a none existent app template, did you include that by mistake? If not, you might want to confirm it’s the correct app template and that the module and app that provide it are started.

@darius @wyclif

Actually that template exists, looks like I will need to dive into the app framework to understand what is not working https://github.com/openmrs/openmrs-module-coreapps/blob/f19d878415846d663787e84fd0c5039ab8177c15/omod/src/main/resources/apps/coreappsAppTemplates.json#L98-L110

This seems consistent for some of the test apps I have created through the UI