Create native JSON composition format from OPT

Hi,
I am trying to test the EHRBase APIs and have been able to create EHR and sample templates(did not return success though the template was created) . The next is to create compositions.

Here I am stuck as the API expects the native JSON format for the composition. How can I create the JSON composition format from OPT? Is there any tool that I can use? In Ethercis, I used the template example format API to get a sample that I can use for compositions, but could not find something similar in EHRBase.

Also is the git repository the preferred location to log bugs ?

regards

1 Like

My suggestion (for now) is to create the template composition example in Ethercis, save that composition, Get the composition in RAW JSON format and bingo, you have a JSON RAW format composition.

Might be quite easy to string together with a wee bit of code.

I would be pretty sure that Github is the preferred option for reporting bugs

Ian

EHRbase does also accept XML. The only part that is restricted to JSON is AQL.

Also EHRbase has a client library with recently made some progress: https://github.com/ehrbase/ehrbase_client_library

I started off with generating XML instances here: https://server001.cloudehrserver.com/cot/opt/xml_instance_generator
Right now it looks like the certificate is expired, but it still works.
Just make sure to select “Composition” in the Options.

Then upload the composition to the EHRbase Server with the following headers to get it back in JSON format:
Prefer: return=representation
Accept: application/json

Just make sure that your build of the EHRbase server is at least commit 638a0fb if your template contains clusters.

Best regards
Niklas

1 Like

Hi Niklas,

I’m working to make the CaboLabs openEHR Toolkit to generate canonical JSON instances directly, since the current JSON instances we generate are just a transformation from the canonical XML to JSON

It seems I need to update the certs :slight_smile: good catch!

Do I understand correctly that CaboLabs openEHR Toolkit to generate canonical JSON examples directly from an OPT-file?

EDIT: might have found it at https://server001.cloudehrserver.com/cot/opt/json_instance_generator will test…

1 Like

Is there anything out there like https://github.com/ehrbase/ehrbase_client_library but for Javascript/Typescript instead? Something that exposes the RM or generate template-specific classes to client javacript code?

Not yet but I want it!!

@erik.sundvall it’s not as convenient, but it should be possible to convert the JPA like classes to a simplified JSON format, allowing to build form specific REST interfaces. I know that this is not the same as directly setting values in the class but could be a nice method while we are waiting for such a tool to occur :wink:

Ok, I agree with @ian.mcnicoll, so let’s figure out a simple way to get started, and then a way to do it properly. I mixed two tings in one post, i’ll try to split and name the two…

Project RM2TS: from RM BMM-files, JSON-schema etc via some tooling/code to Typescript classes with generic RM names

Project OPT2TS: from operational templates (OPT) via some tooling/code to template-specific Typescript classes with use-case-meaningful names

For RM2TS or RM2xyz, be aware that BMM has been upgraded significantly to cover pretty much all semantics of normal specification languages, i.e. the same semantics of most programming languages at interface level, and expressions. The only thing missing (I don’t think it’s needed right now) is procedural control structure statements like if/then/else etc.

Some of the most recent changes:

  • support for agents (aka lambdas), as calls, delayed calls, and ‘signature’ types
  • fully described routine definitions, including pre- and post-conditions
  • class invariants
  • better meta-data and documentation structures

Of course, these still need to be transferred into projects like Archie (@pieterbos - be afraid, be very afraid :wink: but the general direction is that the primary definition of all openEHR information models (RM, BASE, TP etc) will be in BMM in sufficient precision to enable generation of any code interfaces in any reasonable OO+FP language.

1 Like

If there is a tool that can be used to generate JSON data from a JSON schema, I added JSON schema generation to LinkEHR some time ago, maybe it’s enough for your use case.

I think we are a little behind BMM latest changes though… :sweat_smile: :sweat_smile:

1 Like

Interesting. Thanks!

There are things like https://github.com/bcherny/json-schema-to-typescript#readme (demo at https://bcherny.github.io/json-schema-to-typescript-browser/ ) and https://quicktype.io/typescript/ and several others.

A drawback is likely that the route via json schema likely removes some detail from the BMM that typescript (or extension classes/libraries) could handle better than JSON can. I am guessing a bit, so I could be wrong, https://spin.atomicobject.com/2018/03/26/typescript-data-validation/ that describes
this approach says “JSON schema actually provides a superset of the basic features of the TypeScript type system for runtime validation”.

Modifying the pipeline in your tool to outputting typescript directly (instead of just json schema) from BMM might be even more interesting. Is that part open sourced? @yampeku could you post a link to the part/classes/code that does the conversion?

Those are generated using of min PHP code from the UML .xmi files we have.
However, those schemas still needs some work to make them more accurate, to remove annotations, and potentially to be generated from BMM instead of UML.

1 Like

It’s not from BMM directly, but from any given archetype (which can be derived from RM archetypes based on BMM). This functionality is fully available on LinkEHR, if it’s from an end user perspective maybe easiest thing would be to download an use it from there. Code is not currently open, but I can liberate this part without problems. Has dependencies to the old java libs (not archie) and code is quite “handcrafted”, but does the job. If you are interested I could clean it a little and publish it in a git repo or something.

@yampeku don’t put too much time into publishing that for our sake yet, let’s explore some other options first. Or are your “RM archetypes” already auto generated from BMMs in some other pipeline? I’d like to find a (semi)automated way from BMM to Typescript/Javascript-library or some already actively maintained library.

@bna I believe you mentioned the other day that DIPS already has some TypeScript library for openEHR that makes Intellisense etc in IDEs work. When looking at https://github.com/DIPSAS/ehrcraft-pre-procurement-demo/tree/master/typescript, the files in the “/src”-directory seem to import openEHR types such as DvQuantity, DvBoolean, DvCodedText.

  • Where are those classes imported from?
  • Are they available as open source (or could be made available)?
  • How did you create them - handcrafted, BMM-conversion or something else?

You are right @erik.sundvall. There is a Typescript library for the Form script types. It’s not a real implementation just the API definitions to make dev of Form scripts faster. The package is published to NPM and should be available for anyone.

1 Like

Great! Thanks @bna! How did you create them - handcrafted, BMM-conversion or something else?

Handcrafted. It was a need using the platform to get intellisense building Form scripts. It was also a minor RD project to test if it was possible to do it like this.

The hardest part was actually compiling TS into supported JS syntax without upgrading the Form Designer. This is done by some tricks in the Gulp script also added to the Github project.

Yep, that’s what linkehr uses for rm representation. RM is defined as archetypes with special atcodes. These are bundled with every linkehr, available in the data/rm folder. There you will find rm archetypes for openEHR, CDA, ISO13606 and even some FHIR STU3 Resources

1 Like

Hi all,
Reconnecting to the first question of the post, do you have a couple template-composition that works in Ehrbase? (I’m on the latest, ehrbase-0.10.0)
And can you explicit the header and parameter settings needed?
I tried many couple, in xml, (that works with ThinkEHR and/or Ethercis) with no success.

Then I tried the procedure proposed by @ian.mcnicoll , that is get in JSON a composition saved in Ethercis in XML, but the only format Ethercis can export to seems to be XML and ECISFLAT. I tried to insert the ECISFLAT in Ehrbase but I failed.

I also created a composition from the cloudehrserver tool mentioned by @backbord. I tried both the xml and the json composition but it didn’t work.

Any help is appreciated :slight_smile:
Thanks
Giovanni