FHIR Chat · Object models in JS · javascript

Stream: javascript

Topic: Object models in JS


view this post on Zulip Chris Moesel (Nov 06 2018 at 21:58):

Are there any existing projects that have object models in JS allowing for simpler creation and manipulation of models? I realize it is not rocket science to use JSON directly, but I'm wondering if there are any models with helper functions for accessing extensions more easily or finding elements by slice name, etc.

view this post on Zulip Marco Descher (Jan 25 2019 at 08:16):

I have the same question - it is really tedious to do binding to the json parsed object - e.g. if you have to bind to a specific telecom property ...

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 08:23):

We used something like this https://github.com/niquola/2way

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 08:23):

See samples in https://github.com/niquola/2way/blob/master/test/index.spec.js

view this post on Zulip Marco Descher (Jan 25 2019 at 08:31):

Thats nice, but is it capable of handling newly added values? E.g. if I add a mobile number in form which then has to be added to the telcom array?

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 08:32):

you always can extend it - in real projects this lib was inlinded and extended for specific needs

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 08:34):

here is our more advanced lib - but it's in clojure - https://github.com/abcdw/ironhide

view this post on Zulip Morten Ernebjerg (Jan 25 2019 at 08:41):

The Clinical Meteor project also has explicit JS models for Resources: https://github.com/clinical-meteor/ . Never worked with them, though, so I'm not sure how "thick" they are.

view this post on Zulip Marco Descher (Jan 25 2019 at 09:00):

Thanks for the links ... I'm pretty new to javascript (seasoned java developer) and really missing the formal classes at the moment. Trying to bind in vue.js! It seems like there are some projects, but more the less everybody has it's own implementation despite the standardization.

view this post on Zulip Morten Ernebjerg (Jan 25 2019 at 09:14):

We've found that working with TypeScript rather than JS directly helps a lot since it gives you the types while still being interoperable with JS. There are pre-defined (STU3) types on NPM: https://www.npmjs.com/package/@types/fhir .

view this post on Zulip Marco Descher (Jan 25 2019 at 09:17):

Do you know how I can create such a Typescript Patient object given the JSON representation delivered by a FHIR server?

view this post on Zulip Morten Ernebjerg (Jan 25 2019 at 09:32):

I suppose one way would be to start from the official JSON Schemata for the various resources (see also this thread) and then generate the types from there (random Google-hit for the latter: https://www.npmjs.com/package/json-schema-to-typescript). As for the case of an arbitrary StructureDefinition (e.g. a Profile on a base resource), there may be tools to automatically generate JSON schema from them, I know there's been some discussion on this - @nicola (RIO/SS) do you know what the current state on that is?

view this post on Zulip Morten Ernebjerg (Jan 25 2019 at 09:38):

JSON schemata for base resources are available on the download page, e.g. for R4 http://build.fhir.org/downloads Oops, now it's of course http://hl7.org/fhir/downloads.html

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 09:57):

Guys do not complicate things :) Use plain js objects :)

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 09:58):

It's much more fun

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 09:59):

Types will not help you to flatten FHIR resources for UI manipulation

view this post on Zulip nicola (RIO/SS) (Jan 25 2019 at 10:00):

even make it worse

view this post on Zulip Morten Ernebjerg (Jan 25 2019 at 10:08):

I get nervous twitches every time I manipulate complicated JS objects - maybe I'm getting old ;) Anyway, I live mainly in the backend.

view this post on Zulip Grahame Grieve (Jan 25 2019 at 19:03):

if you want to generate code, the best place to start from is the formal StructureDefinitions - these contain the most knowledge about what is really going on in the objects

view this post on Zulip Grahame Grieve (Jan 25 2019 at 19:03):

Generating code from the JSON schema would be really hard - it is not geared for code generation at all

view this post on Zulip Robert Winterbottom (Jan 25 2019 at 19:21):

We found that out the hard way, originally generating classes based on JSON schema but quickly switched to structure definitions. We just updated our generator and have R4 models working with basic getters and setters so once we work out any kinks, they will be up on our github. Not exactly sure what you all are looking for but I can link them here once they are live.

view this post on Zulip Morten Ernebjerg (Jan 27 2019 at 20:00):

Right, I should clarify that I was only talking about generating TypeScript types, which only give the shape of the objects and contain only basis info from the StructureDefinition (not even the full cardinality info).


Last updated: Apr 12 2022 at 19:14 UTC