I was able to achieve this. I was able to POST data to an html form via an open web app. The reason I needed to be able to POST html forms via REST was because my open web app is behind a service worker which makes it available while offline. While handling offline registration patients was straightforward, form entry was not. But I was able to make it work. So now I can do form entry even while client is offline and it will sync with server when it’s back online and it will seem like it was saved from the html form entry module.
To achieve this,
- I created the forms with the html form entry module and took note of the ID of the concepts used in the obs fields
- Create Java and REST api for form entries in a custom module. E.g CultureResult.java and CultureResultResource
and when saving my resouce, I create an encounter which is attached to my previously created html form. An obs that is linked the encounter. Save both encounter and obs. And on visiting the patient dashboard from legacyui, I could see my submitted data as though It was done using the html form created with the form entry module.
Below is the form replica in my webapp
Entering the form makes a POST to /cultureresult with this json data
"result": "text entered in field"
And on the backend, I created an encounter and obs linked to my html form using
final Encounter encounter = new Encounter();
Encounter saved = Context.getEncounterService().saveEncounter(encounter);
final Concept conceptForResult = Context.getConceptService().getConcept(3);
final Obs obs = new Obs();
Visiting the patient dashboard I could see an entry for an encounter created
Viewing the entry works too