How to create a fragment which can support to edit from Patient Dashboard?

I have successfully added a new section called “Patient Location”(sectionId : accessLocationInfo, appDefinitionName : referenceapplication.registrationapp.myRegWithLoc ) to the Patient Registration Dashboard by creating a new app definition.

 {
   "id": "accessLocationInfo",
   "label": "Access Location",
   "questions": [
       {
         "legend": "Patient Location ",
         "id": "patientLocationLabel",
         "fields": [
           {
                "type": "personAttribute",
                "label": "Select Location",
                "formFieldName": "locationId",
                "uuid": "8b5c95ef-103c-41bc-9f24-368b8f77e070",
                "widget": {
                      "providerName": "locationbasedaccess",
                      "fragmentId": "field/locations"
                         }
          }
          ]
    }
    ]
}

Now I wanted to edit the patient location through the patient summary dashboard like editing the contact information. So I have created an extenstion.json as follows,

[
  {
    "id": "${project.parent.groupId}.${project.parent.artifactId}.editLocation",
    "extensionPointId": "patientDashboard.overallActions",
    "type": "link",
    "label": "Edit Location",
    "url": "registrationapp/editSection.page?patientId={{patient.uuid}}&sectionId=accessLocationInfo&appId=referenceapplication.registrationapp.myRegWithLoc",
    "icon": "icon-pencil",
    "order": 100,
    "requiredPrivilege": "Task: View Administration Functions"
  }
]

image

Then, I need to get the patient object from the PatientId in the URL

(i.e http://localhost:8080/openmrs/registrationapp/editSection.page?patientId=84&sectionId=accessLocationInfo&appId=referenceapplication.registrationapp.myRegWithLoc

to get the existing value to show in the form. So I have changed my controller as follows,

package org.openmrs.module.locationbasedaccess.fragment.controller.field;

import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.ui.framework.annotation.FragmentParam;
import org.openmrs.ui.framework.fragment.FragmentModel;
import org.openmrs.api.context.Context;
import javax.servlet.http.HttpSession;
import java.util.List;

public class LocationsFragmentController {

    public void controller(FragmentModel model,
                           HttpSession session,
                           @FragmentParam("patientId") Object patient) {
        List<Location> activeLocations = Context.getLocationService().getAllLocations();
        model.addAttribute("activeLocations", activeLocations);
        
        if (patient instanceof Patient) {
            model.addAttribute("patient", patient);
        } 

    }
}

But unfortunately, I’m getting this following error while goto that URL. Please see the error log here : UI Framework ErrorRoot Errororg.openmrs.ui.framework.UiFrameworkException: p - Pastebin.com

Please refer this PR for whole implementation,

Can someone please help me to resolve this issue :slight_smile: ?

CC : @dkayiwa

Are you sure that all your changes are in that pull request?

Oh, Sorry I just updated the PR. Please have a look again.

Your current pull request changes do not result into the error you have reported in your stack trace. Can you run your changes again?

@dkayiwa I think It might be “java.lang.NullPointerException” since the AppDefinition name was mentioned as “referenceapplication.registrationapp.myRegisterPat”

Now I have updated it to “referenceapplication.registrationapp.myRegWithLoc” as mentioned in the wiki page (Edited the main post also).

Can you share a new stack trace of the error that you are currently getting?

I’m getting the same error as I mentioned here : UI Framework ErrorRoot Errororg.openmrs.ui.framework.UiFrameworkException: p - Pastebin.com

Please use the updated PR with this changed line : https://github.com/openmrs/openmrs-module-locationbasedaccess/pull/8/commits/da8eca0ac97eff3b076e0349625e864c6b37b827#diff-dca4fc9b130a826416b545d3aa553e89R8

From the error message “patientId is required” did you supply this required parameter?

Yes @dkayiwa I passed the patientId through the URL. Even I have tried with Patient Uuid also. But got same error as mentioned above. I think, I am missing some configuration to communicate with UI framework :cry:

  1. http://localhost:8080/openmrs/registrationapp/editSection.page?patientId=84 … OR
  2. http://localhost:8080/openmrs/registrationapp/editSection.page?patientId=fa7a33bd-7860-42ff-b1e4-4dd26a8cc832

I have just done a fresh installation of the reference application, then installed your module changes, created a new patient and tried the edit location link. The error i get turns out to be different from yours. Can you try these steps?

@dkayiwa Just dont it and I’m getting the same error message as I mentioned above (https://pastebin.com/dTWFyPHB)

Even with my changes in the PR, I can’t create the Patient also. When I goto the Register Patient dashboard also, I’m getting the same error (to resolve this, I need to add the patient param with required=false)

You should keep the section and appId name as mentioned in this wiki - https://wiki.openmrs.org/display/docs/Location+Based+Access+Control+-+Deployment+Steps. Otherwise It should the Null Pointer Exception.

This is the branch of the whole content : https://github.com/suthagar23/openmrs-module-locationbasedaccess/tree/LBAC-5

Did you try my steps above with a fresh installation of the latest reference application?

Yes @dkayiwa I have tried as follows

  1. Installed fresh Ref App 2.7.0
  2. Created Person Attribute Type and Global properties
  3. Installed Appui module 1.9-SNAPSHOT (locally build)
  4. Installed Location based access control module
  5. Created the App Definition as mentioned here.

Then I went to Register Patient -> I got the same error as mentioned here(https://pastebin.com/dTWFyPHB) :cry: I can’t create the patient also - Same error

P.s - If you missed the step 3, you will get Controller missing - locationbasedaccess error

Let me repeat my steps. please do not do any more than what i say.

  1. Install the latest release of the reference application
  2. Install your module
  3. Create a new patient
  4. Go the patient dashboard and click the Edit Location link.

@dkayiwa

  1. I have done the step-1 (installed ref app 2.8.0) :white_check_mark:
  2. Then Installed my module. :x:

But failed to start the module since it’s required appui-1.9.0.

Error while trying to start module - Module Location Based Access Control cannot be started because it requires the following module(s): appui 1.9 Please install and start these modules first.


Then I thought you covered all the settings to run my module in step 2 :slight_smile:

  • So I installed the appui-1.9-SNAPSHOT

So now I can run my module successfully - Step 2 completed :white_check_mark:


  1. I created a patient. (Without selection location attribute - actually, I didn’t configure that yet)

  2. Then went to Patient Dashboard, and clicked the “Edit Location”.

As you mentioned, I got a different error :smile: - https://pastebin.com/iZupeDPW

But the reason for this error was,

  • I have attached an extension.json into my module to add a general action link.
  • When module loads, it will scan the resources/apps classpath, and generate the action link as usual.
  • In the action link, I have mentioned sectionId as “accesslocation-info”. It will be fetched from the App Definition link from the appId (mentioned as “referenceapplication.registrationapp.myRegWithLoc”)
  • Since I haven’t created any app definition with that appId and that section Id, System can’t fetch that required section to build the form.
  • It was the reason for this error. We can simply fix it by creating the App Definition as mentioned here.

After created the App definition, Click the “Edit location”, you will get the error as I mentioned before - https://pastebin.com/dTWFyPHB

P.S : I haven’t created the person attribute type and global property yet. It should be also created to continue the process after we fix this issue :slight_smile:

I have gone through the steps you have listed and now i get this error on clicking the Edit Location link: https://pastebin.com/5cQdw9j5

Possible two reasons for this issue,

  1. Please check your AppId in the App definition. It should be - referenceapplication.registrationapp.myRegWithLoc

  1. Please check your section id in the App definition. It should be - accesslocation-info

Because I’m using that in the extenstion,

[
  {
    "id": "${project.parent.groupId}.${project.parent.artifactId}.editLocation",
    "extensionPointId": "patientDashboard.overallActions",
    "type": "link",
    "label": "Edit Location",
    "url": "registrationapp/editSection.page?patientId={{patient.uuid}}&sectionId=accesslocation-info&appId=referenceapplication.registrationapp.myRegWithLoc",
    "icon": "icon-pencil",
    "order": 100,
    "requiredPrivilege": "Task: View Administration Functions"
  }
]

If those both are correct, probably it should move to another error (mentioned above).

I have just copied and pasted what you put here, without any modification: https://wiki.openmrs.org/display/docs/Location+Based+Access+Control+-+Deployment+Steps

Ohh, Let me try again :cry:

Could you please paste the actual URL when you click on the Edit Location? (Capital - small letters also made these type of problem)

Here it is: http://localhost:8080/openmrs/registrationapp/editSection.page?patientId=58016aa7-02e4-4993-96d1-83f391583bd1&sectionId=accessLocationInfo&appId=referenceapplication.registrationapp.myRegWithLoc&returnUrl=%2Fopenmrs%2Fcoreapps%2Fclinicianfacing%2Fpatient.page%3FpatientId%3D58016aa7-02e4-4993-96d1-83f391583bd1%26