# Generation of Example Instances of a Template **Category:** [CKM](https://discourse.openehr.org/c/ckm/89) **Created:** 2024-08-15 02:13 UTC **Views:** 221 **Replies:** 23 **URL:** https://discourse.openehr.org/t/generation-of-example-instances-of-a-template/5568 --- ## Post #1 by @linforest A disirable feature would be generation of example Instances of a Template for demo. Currently, when open a specified Template, the right panel will render it as a form that could be used for entering some example data. So, sometime, displaying and export/save the example Instance data would be a nice feature. ![image|565x500](upload://3Ehe7FV0FAQeujvoXvy2tYk0bEl.png) For example, the Web Template JSON to be displayed and exported/saved: ``` { "vital_signs/body_temperature/any_event/temperature|magnitude": 38, "vital_signs/body_temperature/any_event/temperature|unit": "°C" ... } ``` **Reference**: [* 2.5. Step 4: Load Data — EHRbase documentation](https://ehrbase.readthedocs.io/en/latest/02_getting_started/05_load_data/index.html) For now, using the EHRbase Swagger UI, the operation GET {BASE-URL}/rest/openehr/v1/definition/template/{template_id}/example can be used to generate an example composition (populated with fake data; format = application/xml) for the specified template. --- ## Post #2 by @borut.jures Generating example instances from a template is "easy" and can be fully automated (I know that @pablo, Archie and @borut.jures have done it – probably others too – please reply to add your solution). Next level is generating fully randomized example instances where optional data is sometimes added and sometimes omitted and variable number of items is added for lists. The interesting part is generating instances with **clinically relevant data**. I'm using YAML based formulas which clinicians can prepare: ``` formulas: # LOINC based formulas loinc: # Heart rate 8867-4: set: - attribute: value element: value_range: low: 40 high: 130 # Body temperature 8310-5: set: - attribute: value element: value_ranges: deg_C_snomed: low: 35.0 high: 38.9 deg_F_snomed: low: 90.0 high: 102.0 interpretation_ranges: deg_C_snomed: low: 36.1 high: 38.0 deg_F_snomed: low: 96.98 high: 100.4 ``` Notice that there are no references to archetype names or paths (even if they are supported for more complex cases). This means that clinically relevant data will be added to **ANY** template based on LOINC codes alone. Manually creating example instances is time consuming and in the long run hard to maintain. Writing formulas (as shown above) would be time better spent. It would be great if example instances with clinically relevant data were available for download in the CKM (try googling "fhir blood pressure example" and "openehr blood pressure example" – Google will autocomplete it for FHIR, but not for openEHR). From my experience developers can better understand JSON example than reading archetype description in CKM (even if CKM is more detailed). Maybe this is one of the reasons why FHIR is picked up so quickly by the developers. --- ## Post #3 by @ian.mcnicoll Archetype Designer actually has this feature (I only recently discovered). Via the Form tab, then enter some dummy data (or generate) then Export->JSON ![image|580x500](upload://io0PrVYwiKDTDg0yaZJoKAP0vGy.png) --- ## Post #4 by @linforest **[Synthea](https://github.com/synthetichealth/synthea)** works for FHIR > Blockquote **Synthea** is a Synthetic Patient Population Simulator that is used to generate the synthetic patients within SyntheticMass. **Synthea** outputs synthetic, realistic but not real patient data and associated health … Such a "Synthea" for openEHR would be nice! --- ## Post #5 by @borut.jures [quote="ian.mcnicoll, post:3, topic:5568"] Export->JSON [/quote] I was so hopeful, but it doesn't export as canonical RM composition :cry: It is probably web template as JSON. --- ## Post #6 by @linforest Wow, It's worth trying... --- ## Post #7 by @linforest [quote="borut.jures, post:2, topic:5568"] From my experience developers can better understand JSON example than reading archetype description in CKM (even if CKM is more detailed). Maybe this is one of the reasons why FHIR is picked up so quickly by the developers. [/quote] Agree :heart: --- ## Post #8 by @borut.jures [quote="linforest, post:4, topic:5568"] Such a “Synthea” for openEHR would be nice! [/quote] I'll use Synthea FHIR data to map it to openEHR (Synthea doesn't support openEHR format). This is where posted formulas originate from – my MapEHR project for migrating legacy EHR data to openEHR :wink: They were just re-purposed for my client's example instance synthesizer. --- ## Post #9 by @ian.mcnicoll It is a STRUCTURED JSON Compositon instance not a web template. If I need a canonical json or xml, I just post the composition into a Better or EhrBase CDR and read it back again as Canonical . --- ## Post #10 by @ian.mcnicoll Synthea openEHR data would be very interesting - I know @bna was working in this area a few years ago. --- ## Post #11 by @borut.jures [quote="ian.mcnicoll, post:9, topic:5568"] If I need a canonical json or xml, I just post the composition into a Better or EhrBase CDR and read it back again as Canonical . [/quote] That is because you are not “lazy” like me :blush: And it helps that you have a lot of experience with the tools. Consider a new developer trying to figure out “STRUCTURED JSON”, “Composition instance”, “web template”, “canonical json or xml”, “post to CDR”. They will be overwhelmed. It would be great if Archetype Designer would export directly to canonical composition :crossed_fingers: --- ## Post #12 by @ian.mcnicoll Completely agree!! I think we could easily hide some of this in a wee developer playpark environment --- ## Post #13 by @linforest Is [FHIR-Bridge[(https://github.com/NUM-Forschungsdatenplattform/num-fhir-bridge) relavant for this topic? Imagined pipline: Synthea --> FHIR-Bridge --> [EHRBase, EHRServer...] --- ## Post #14 by @ian.mcnicoll @borut.fabjan - we love the new Export Example JSON in AD via Form but can we expand that to support other formats like FLAT JSON, Canonical JSON? --- ## Post #15 by @borut.jures [quote="linforest, post:13, topic:5568"] Is [FHIR-Bridge relavant for this topic? [/quote] It is, but it uses Java classes for mapping FHIR to openEHR. I tried a similar "code-based" approach but it was quickly rejected as "unfriendly" to clinicians – they prefer YAML over programming languages. Similar to two-level approach of openEHR archetypes, mapping should also separate formal definitions of mapping clinical content from the technical implementation. The idea is to have a generic tool to convert EHR data to openEHR where **mapping rules are defined outside the tool** (e.g. YAML/JSON). Ideally the mapping rules would be reusable by different tools/vendors. --- ## Post #16 by @linforest [quote="borut.jures, post:15, topic:5568"] reusable by different tools/vendors. [/quote] **+1** I.e., technology and vendor neutral --- ## Post #17 by @sebastian.garde This hasn't been used much in CKM so far, but if you have a nice realistic example for a template (or archetype) in JSON, you can add these in CKM. ![image|562x500](upload://gXvmcYbvgsEo3NISZHO9RwNNs3U.png) Agree it would be useful especially for developers to see this, ideally with realistic clinical data as @borut.jures says. --- ## Post #18 by @ian.mcnicoll Yup @SevKohler is leading this work for HighMed to bring together the FHIR Bridge work and FHIR-Connect, so that it is based on sharable YAML-based artefacts. --- ## Post #19 by @linforest [quote="sebastian.garde, post:17, topic:5568"] you can add these in CKM [/quote] What role(s) is this CKM feature available for? --- ## Post #20 by @sebastian.garde [quote="linforest, post:19, topic:5568"] What role(s) is this CKM feature available for? [/quote] Anybody can view this. Upload is for editors, CKAs. --- ## Post #21 by @linforest Thanks, [Sebastian](https://discourse.openehr.org/u/sebastian.garde)! Looks like I only have access to view. --- ## Post #22 by @pablo [quote="borut.jures, post:2, topic:5568"] The interesting part is generating instances with **clinically relevant data**. I’m using YAML based formulas which clinicians can prepare [/quote] That's an interesting approach. We are actually testing some AI to generate human like text for the text fields in the openEHR Toolkit (https://toolkit.cabolabs.com/) for which we are generating just random text now. I like the script thing, though some of the constraints could be directly set in the OPT itself, like the ranges for some vitals, but I get that the script constraints could be narrower for testing purposes, which is something we currently do when we test Atomik/EHRServer from Insomnia REST Client (it's like Postman but friendlier) which allows to set small data generators in JSON payloads. So we first generate the canonical JSON using the openEHR Toolkit, then on Insomnia we adjust the data generators for some nodes. --- ## Post #23 by @birger.haarbrandt You could also use the openEHR SDK. Maybe something that we provide in a more convenient way, though. --- ## Post #24 by @linforest Does the Composition generated by [openEHR-tool](https://github.com/crs4/openEHR-tool) needs to fully support UTF-8 encoding? Currently, Chinese characters (zh--CN, therefore other language characters) in the catenated path key are Unicode-encoded , such as \u4e00, which are not human-readable. ![image|690x335](upload://eBHgJW2Fkv193zn86mIZOVvvGGL.png) Does this encoding issue of Composition generatation originate from [openEHR-tool](https://github.com/crs4/openEHR-tool) or [openEHR_SDK](https://github.com/ehrbase/openEHR_SDK/tree/develop/web-template)? Both github project repo directories have been searched, and Only [one file](https://github.com/crs4/openEHR-tool/blob/31317daebbbec723d4413ae4ba4a8512205ff2d7/ehrbase_routines.py#L827) contains 'Unicode' in the openEHR-tool project but it looks like directly related to XML: ![image|690x150](upload://AbTfbfGJwghg5Yca6J6XS2Yq79W.png) In addition, both XML and JSON formats are OK with the encoding; both Structured and FLAT formats are not. When POST a Composition in the formats above, only the XML format works but the other three formats all get a **Composition insertion failure** (status code = 400): ![image|690x389](upload://2pjcrl1wo6wkM9Qiv7BMkM1Lvr8.png) --- **Canonical:** https://discourse.openehr.org/t/generation-of-example-instances-of-a-template/5568 **Original content:** https://discourse.openehr.org/t/generation-of-example-instances-of-a-template/5568