# Problems creating an EHR with Swagger EHRbase API **Category:** [Resources](https://discourse.openehr.org/c/resources/71) **Created:** 2024-06-12 10:57 UTC **Views:** 412 **Replies:** 10 **URL:** https://discourse.openehr.org/t/problems-creating-an-ehr-with-swagger-ehrbase-api/5354 --- ## Post #1 by @sofialfaro Hi, my name is Sofia. I am introducing with EHRbase API and I have problems creating an EHR using PUT. I am trying to use this code: ``` { "archetype_node_id": "openEHR-EHR-EHR_STATUS.generic.v1", "name": { "value": "EHR status"}, "uid": { "_type": "OBJECT_VERSION_ID", "value": "8849182c-82ad-4088-a07f-48ead4180515::openEHRSys.example.com::1"}, "subject": { "_type": "PARTY_SELF"}, "is_queryable": true, "is_modifiable": true } ``` but gives me this error: ``` { "error": "Bad Request", "message": "Could not resolve subtype of [simple type, class com.nedap.archie.rm.RMObject]: missing type id property '_type'\n at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 271]" } ``` What can I do to solve this problem? --- ## Post #2 by @birger.haarbrandt Hi Sofia, not sure about the error message in particular, but your payload might not be correct (you are missing the _type information of the EHR_STATUS object). See here for a working example: ``` { "_type": "EHR_STATUS", "archetype_node_id": "openEHR-EHR-EHR_STATUS.generic.v1", "name": { "value": "EHR Status" }, "subject": { "external_ref": { "id": { "_type": "GENERIC_ID", "value": "ins01", "scheme": "id_scheme" }, "namespace": "examples", "type": "PERSON" } }, "is_modifiable": true, "is_queryable": true } ``` When using put, you should also provide the EHR ID as part of the URL like ``` {{ehrbase-url}}/ehrbase/rest/openehr/v1/ehr/:ehr_id ``` If you want EHRbase to create an UUID, use POST instead. Hope this helps --- ## Post #3 by @sofialfaro Thanks! Now it works! --- ## Post #4 by @sofialfaro My next doubt comes when using POST to create a composition If I use the code from de OpenEHR Manual: ``` { "archetype_node_id": "openEHR-EHR-COMPOSITION.encounter.v1", "name": { "value": "Vital Signs" }, "uid": { "_type": "OBJECT_VERSION_ID", "value": "8849182c-82ad-4088-a07f-48ead4180515::openEHRSys.example.com::1" }, "archetype_details": { "archetype_id": { "value": "openEHR-EHR-COMPOSITION.encounter.v1" }, "template_id": { "value": "Example.v1::c7ec861c-c413-39ff-9965-a198ebf44747" }, "rm_version": "1.0.2" }, "language": { "terminology_id": { "value": "ISO_639-1" }, "code_string": "en" }, "territory": { "terminology_id": { "value": "ISO_3166-1" }, "code_string": "NL" }, "category": { "value": "event", "defining_code": { "terminology_id": { "value": "openehr" }, "code_string": "433" } }, "composer": { "_type": "PARTY_IDENTIFIED", "external_ref": { "id": { "_type": "GENERIC_ID", "value": "16b74749-e6aa-4945-b760-b42bdc07098a", "scheme": "pid" }, "namespace": "openEHRSys.example.com", "type": "PERSON" }, "name": "A name" }, "context": { "start_time": { "value": "2014-11-18T09:50:35.000+01:00" }, "setting": { "value": "other care", "defining_code": { "terminology_id": { "value": "openehr" }, "code_string": "238" } } }, "content": [] } ``` It gives me another error: ``` { "error": "Internal Server Error", "message": "An internal error has occurred. Please contact your administrator." } ``` I don't know how to solve it. How can I solve it? Another question, once I have created an EHR with the code you gave me, where can I see that info, if I make a GET I see it but if I enter in OpenEMR can I also see it there? I want to create an EHR with many encounters but I don't really understand how this works. Do you know other manuals or tutorials that explain how to understand this step by step? --- ## Post #5 by @birger.haarbrandt I think the best source is @Sidharth_Ramesh 's YouTube channel with different tutorials: https://www.youtube.com/@medblocks/videos We also have a small tutorial in the EHRbase documentation, but I admit that this requires an overhaul: https://docs.ehrbase.org/docs/EHRbase/openEHR-Introduction/Introduction --- ## Post #6 by @sebastian.iancu The json payload above, representing a composition to be created, is not ready to be used on real systems. It represents roughly a composition, but is invalid as is missing content; and perhaps you also need to create / publish the template that is used. So don’t use example as-is, rather focus on complete flow from to generate real valid content. In any case Birger’s recommendation are going to help you further. --- ## Post #7 by @birger.haarbrandt For your concrete problem, I would recommend the following approach. After uploading the Template, you can let EHRbase create an example for you `GET localhost:8080/ehrbase/rest/openehr/v1/definition/template/adl1.4/Körpergewicht/example?format=FLAT` Replace "Körpergewicht" with your template id. This will give you an example composition like this for the FLAT representation: ``` { "körpergewicht/category|value": "event", "körpergewicht/category|code": "433", "körpergewicht/category|terminology": "openehr", "körpergewicht/context/status|code": "at0010", "körpergewicht/context/status|value": "registriert", "körpergewicht/context/status|terminology": "local", "körpergewicht/context/kategorie:0": "Lorem ipsum", "körpergewicht/context/start_time": "2022-02-03T04:05:06", "körpergewicht/context/setting|value": "home", "körpergewicht/context/setting|terminology": "openehr", "körpergewicht/context/setting|code": "225", "körpergewicht/context/_end_time": "2022-02-03T04:05:06", "körpergewicht/context/_health_care_facility|name": "DOE, John", "körpergewicht/körpergewicht/gewicht|magnitude": 500.0, "körpergewicht/körpergewicht/gewicht|unit": "kg", "körpergewicht/körpergewicht/time": "2022-02-03T04:05:06", "körpergewicht/körpergewicht/width": "PT42H", "körpergewicht/körpergewicht/math_function|terminology": "openehr", "körpergewicht/körpergewicht/math_function|code": "145", "körpergewicht/körpergewicht/math_function|value": "minimum", "körpergewicht/körpergewicht/language|terminology": "ISO_639-1", "körpergewicht/körpergewicht/language|code": "de", "körpergewicht/körpergewicht/encoding|code": "UTF-8", "körpergewicht/körpergewicht/encoding|terminology": "IANA_character-sets", "körpergewicht/körpergewicht/_work_flow_id|id": "121d020d-0639-3fc3-a3ed-21f2d72eee1f", "körpergewicht/körpergewicht/_work_flow_id|id_scheme": "scheme", "körpergewicht/körpergewicht/_work_flow_id|namespace": "unknown", "körpergewicht/körpergewicht/_work_flow_id|type": "ANY", "körpergewicht/körpergewicht/_guideline_id|id": "97063a6d-140c-3bbf-a25b-35ee3c0adeda", "körpergewicht/körpergewicht/_guideline_id|id_scheme": "scheme", "körpergewicht/körpergewicht/_guideline_id|namespace": "unknown", "körpergewicht/körpergewicht/_guideline_id|type": "ANY", "körpergewicht/language|code": "de", "körpergewicht/language|terminology": "ISO_639-1", "körpergewicht/territory|terminology": "ISO_3166-1", "körpergewicht/territory|code": "DE", "körpergewicht/composer|name": "Max Mustermann" } ``` Then you can use the result to create the composition with POST localhost:8080/ehrbase/rest/openehr/v1/composition?templateId=Körpergewicht&format=FLAT --- ## Post #8 by @sofialfaro Hi, I'm trying to upload a template using POST adl template 1.4 but I don't know which templates are valid to upload. I want a template to introduce de personal data of a patient such as name, surname, phone address ... Where can I find them and how should I upload them??? Thanks! --- ## Post #9 by @linforest [quote="birger.haarbrandt, post:2, topic:5354"] `{{ehrbase-url}}` [/quote] EHRBase and its DB are started up with the latest official Docker images, including keycloak. Then what is the default ehrbase-url? Thanks. --- ## Post #10 by @birger.haarbrandt you should be able to access via localhost:8080. In doubt, you can always check using docker ps oder docker inspect. --- ## Post #11 by @linforest Thanks, Birger. My local EHRBase server instance (based on its offical Docker images) can be accessed now. --- **Canonical:** https://discourse.openehr.org/t/problems-creating-an-ehr-with-swagger-ehrbase-api/5354 **Original content:** https://discourse.openehr.org/t/problems-creating-an-ehr-with-swagger-ehrbase-api/5354