The GSoC project, Interactive Builder for Forms Translations, introduces the ability to add form translations directly from the form builder instead of via the distro. However, the o3forms module currently lacks an endpoint to post form resources like translations. Would it be possible to provide an endpoint for this? CC @dkayiwa @ibacher , @samuel34 , @dennis
Why would we need an endpoint for this? We also don’t have a specific endpoint for posting forms.
@ibacher my suggestion is inspired by the desire to persist the translations generated from the form-builder to the back-end.
We can already do that with the existing endpoints.
What a surprise, which ones in particular if you don’t mind!
I don’t remember off-hand, but you should be able to find it in the form builder source code.
You can POST a form via: openmrs/ws/rest/v1/form
.
A form resource is a sub-resource of a form, which you can POST via: openmrs/ws/rest/v1/form/{{formUuid}}/resource
A form resource value eg, a Translation file, can be POSTed via: openmrs/ws/rest/v1/form/{{formUuid}}/resource/{{resourceUuid}}/value
This feels incomplete. There’s a form reference, but the actual schema is stored in the clob table and should be true for translations as well.
So the resource endpoint gives you the value reference: openmrs/ws/rest/v1/form/{{formUuid}}/resource/{{resourceUuid}}
returns something like:
{
"uuid": "23a48ca0-e198-475b-99ee-56b71e6ea616",
"name": "Adult HIV Return Visit Form_translations_fr",
"valueReference": "49d887b8-3345-4c1f-8926-6f13920413a6",
"display": "Adult HIV Return Visit Form_translations_fr",
"links": [
{
"rel": "value",
"uri": "https://dev3.openmrs.org/openmrs/ws/rest/v1/form/107c32e8-a318-30bf-acfc-a0244f3a795a/resource/23a48ca0-e198-475b-99ee-56b71e6ea616/value",
"resourceAlias": "resource"
},
{
"rel": "self",
"uri": "https://dev3.openmrs.org/openmrs/ws/rest/v1/form/107c32e8-a318-30bf-acfc-a0244f3a795a/resource/23a48ca0-e198-475b-99ee-56b71e6ea616",
"resourceAlias": "resource"
},
{
"rel": "full",
"uri": "https://dev3.openmrs.org/openmrs/ws/rest/v1/form/107c32e8-a318-30bf-acfc-a0244f3a795a/resource/23a48ca0-e198-475b-99ee-56b71e6ea616?v=full",
"resourceAlias": "resource"
}
],
"resourceVersion": "1.9"
}
You then use the valueReference
to retrieve the actual value from the clob data storage:
openmrs/ws/rest/v1/clobdata/{{valueReference}}
Exactly. It’s just that I think when creating things, the API is asymmetrical, so you need to create the CLOB, then create the resource with the reference.
Downloading is definitely more important than being able to save it in the backend, but the question in this thread was specifically about adding a backend endpoint.
Hey @ibacher @samuel34 When creating a form translation resource via POST /openmrs/ws/rest/v1/form/{formUuid}/resource
, what should be the expected payload?
and is this payload is correct?
{
{
form: "107c32e8-a318-30bf-acfc-a0244f3a795a",
name: "Adult HIV Return Visit Form_translations_en",
dataType: 'FormTranslation',
handler: "",
handlerConfig: "",
value: "",
valueReference: "492515ae-728e-4d96-a8c4-647494bdd0d6"
}
}
Hey @dkayiwa can i know what is the valid dataType for the payload while posting the translation file as a sub-resource.Is it the json
itself
You can take a look at existing data in the form_resource
table.
Where exactly I can get that existing data?
You can set up a local instance of O3 and then look at its database tables.
Ok @dkayiwa..! Thanks