How can custom forms be added to the Android Client from an OpenMRS Backend

How can one add custom forms to the Android client from an OpenMRS custom module

@f4ww4z did you see this? :slight_smile:

If you’re still wondering, I am pretty sure that after adding a form to the custom module with the name: “json” and valuereference: the form’s json data, the form should appear in the android client when the formlistactivity begins.

If not, and this is a problem I had, in you can try to modify the function showFormList. For me, when I called setAdapter, upon creating a new adapter I changed the input parameter from getContext() to this.getActivity(). Beware that I really don’t know why it worked because this is first time I’ve ever worked on an Android application. I simply read these guidelines:

1 Like

@f4ww4z I am still confused about adding the JSON for a custom form. I see the vitals forms in the Reference Application, and also in the Android app code. How are they interlinked or tied together

Thanks in advance

The formlist activity is what displays available forms on the Android application. The JSON form resources stored in the Android app’s code can be accessed by this activity through a method in the activity’s fragment called formCreate(). This function is only ever called by the loadFormResourceList() function in the activity’s presenter. In that function, form resources which have been synced from the RefApp through REST are first obtained using FormService.getFormResourceList(), and then loadFormResourceList() will add those resources whose name is “json” to the list of forms to be displayed. If a form resource doesn’t have a name which is “json”, the Android code will call formCreate() in the fragment and you can see from that function that it looks for specific names and will load from the JSON files stored in the Android app’s code if and only if the name provided by the JSON resource contains the words “vitals” or “admission”. Then, and only then, are the JSON forms which are stored in the Android app’s code accessed. I am not sure if this formCreate() function even works to access these local resources; I always just name my custom JSON form resources “json” in the RefApp so that the Android app automatically adds the form’s resources to the list of forms to display, rather than needing to go through formCreate() to load the custom JSON form from a local source.

Sorry if this did not answer your question, I just wanted to make the mechanics of the functions which display forms on the Android Client clear. If you are wondering why the content of the vitals form on the RefApp is similar to the content of the vitals form in the Android app code (such as the uuids of the forms being the same), I am not sure why that is the case. I would assume it is so that the RefApp correctly interprets the Android’s local JSON form as vitals data if the local form were ever submitted to the RefApp through REST.

For me, I got rid of all the forms in the Android app code because I realized we weren’t using them, didn’t need them, and they were confusing my teammates in much the same way they are confusing you.

  1. Where do you place your custom .json forms - what is the folder where you place them
  2. How do you ensure they get loaded into the form_resource table so that the Android application can load them?

Do you have a repository link that one can look at

  1. We actually don’t place the .json file directly in the RefApp, rather we copy/paste the entire contents of the file into the RefApp. To do this go to System administration -> Advanced administration -> Manage Forms. Then if the form you want to add your resources to is already in the list click on its name; otherwise click “Add Form,” name your form and give it a description a version and an encounter type, click save, then finally click on the name of your new form in the list of forms. After this, click “Manage Resources”. This is where you “Add Resource”, choose “Free Text”, “Default” UI Handler, and finally in the name field put “json” and in the value reference copy over your entire .json file contents. In the Android Client you may get a “There is no encounter type called” + custom_formname. That’s alright, all you need to do is add a new encounter type with the same name as your custom_formname to the Android Client. To do this add it in along with the other Strings (admission, visit note). Also, because replaces those Strings with synced EncounterTypes, you should also add a new Encounter Type in Manage Encounter Types from the advanced administration page on the RefApp with the same name as your custom form, and then don’t forget to change your form’s encounter type to this newly created one in the Manage Forms page.

  2. This is a good question that I am not 100% certain on. I think that what happens is something like on startup of the Client calls REST API’s @GET on all the form resources that the RefApp has, which will now include your custom form resource.

Our team is currently working on a writing assignment due this week, and we are in the middle of the process of figuring out how to push our modifications to our forked GitHub repo. I will let you know as soon as we figure out how to push to our repository, which will be after we have completed the assignment.

So the automatic approach is to load the JSON forms into the database from a directory on startup just like the HTML Forms, maybe better to be called androidforms vs htmlforms for the HTML Form Entry module

I can work with this - and it seems to make sense