Application Name: Reference Application Version 2.5
Is it possible to display a custom fragment conditionally based on the patient’s age? We have a mostRecentEncounter fragment that displays the power of attorney information, but it’s only applicable to children under the age of ‘n’ as is defined in a global property. If it’s not possible to do it through the appFramework, should I create a fragment in my module and pass a variable through the controller?
I have not seen this implemented. So you will need to pass a variable through your controller.
The “correct” answer is that you should make a change in the coreapps module so that the extension points on the patient dashboard respect the “require” property on your extension, and then to set
"require":"patient.age < 5" in your extension config json.
I think this is as easy as adding
contextModel as a second parameter to both of the
getExtensionsForCurrentUser calls in: https://github.com/openmrs/openmrs-module-coreapps/blob/1.13.0/omod/src/main/java/org/openmrs/module/coreapps/page/controller/clinicianfacing/PatientPageController.java#L106-L112
I notice that you say that the age cutoff needs to be controlled by a global property. If that’s a requirement, I don’t think what I’ve said here will solve your situation, and you’ll need to do the controller path that you say.
For anyone who happens upon this thread it has not yet been done as of today. However, I was able to test Darius’ approach in the registration summary page with success using “require”:“patient.person.age < 18” to display the fragment only if the patient is younger than 18 years old. Here’s a sample of the fragment:
"require":"patient.person.age < 18"
Notice that the require field is part of the Extension, not the extensionParams.
@craigappl Happy Dance as this has been a pain in my side for a looonng time! Thanks
@craigappl Looks like I danced too early, I have been unable to get the require to work, at least for dashboard widgets. I am using appframework 3.10.0
The registration Summary page in the registration app has the proper configuration and the extension example I gave, provides a the display only on the registration summary page. To do it, you would have to add the appContextModel to the clinician facing patient page controller as Darius mentions. You can see an example in the registrationSummary fragment. After that, you’ll be able to use the require property on the extension json.
I’ve merged this in, thanks @ssmusoke @craigappl @darius