Stream: shorthand
Topic: Reverse Engineer Structure Definitions to FSH
ben (Jul 09 2020 at 01:07):
Hi, I am working on changing from using XML/JSON based structure definitions to use the FSH ones, however we have quite a base and I looking for a better way to reverse engineer the files, can you recommend any tool/ example to do this?
ben (Jul 09 2020 at 01:52):
@Chris Moesel can you point me somewhere?
Chris Moesel (Jul 09 2020 at 02:59):
Hey @ben -- this is a fairly common request. Up until now, we've been focusing on SUSHI, a tool for translating FSH --> SD JSON. But we've just started working on GoFSH, a tool for translating SD JSON --> FSH. It's still very early on, so we haven't yet pushed anything up to GitHub. If we pushed it up soon, is this something you might be interested in contributing to?
Chris Moesel (Jul 09 2020 at 03:01):
There is also an early prototype from Lantana called FSH Food, but it's fairly out of date now. The GoFSH implementation is based on TypeScript, while FSH Food was prototyped using XSLT.
Halina Labikova (Jul 13 2020 at 19:08):
On a similar note - any plans for developing a tool for reverse engineering of valueset files? I find that dynamic valuesets are much easier to maintain in fsh than manipulating the xml/jsons inside the vocab folder.
Chris Moesel (Jul 13 2020 at 23:25):
Yes, @Halina Labikova. Translating value sets to FSH is part of the plan as well -- although StructureDefinitions are the first priority. We're also going to have to figure out what to do for Value Sets that use features that don't have a FSH syntax (yet). We may have to translate them as straight-up Instances (of ValueSet) -- which won't be quite as nice...
Richard Kavanagh (Jul 14 2020 at 08:11):
I have C# code to generate FSH from STU3 ValueSet/CodeSystems - I need to get that on GitHub somewhere.
Gino Canessa (Jul 14 2020 at 14:42):
I have a project on GitHub (fhir-codegen) that loads, parses, and filters FHIR (DSTU2 through R5 beta). It supports most all FHIR features (StructureDefs, Codes, CodeSystems, ValueSets / Expansions, Operations, SearchParameters...), though Interactions need work (noted below). Export "Languages" are defined via an interface, which lets you traverse the loaded structures and output whatever you want.
I've already done exports of
- Plain Text: language definition, R4 output
- TypeScript language definition, R4 output
- Simple C# (for prototyping/simple projects) language definition, R4 output
- Still testing: Firely-style C# (replacing the
generated
content from the T4 templates) language definition
I'm working on OpenAPI next (as noted above, I need to flesh out support for Interactions, so it will take a little longer than just a language export), but I can add FSH to my list if you let me know what you want them to look like. Or, anyone else could take a stab at defining the export file and I'm happy to review/merge.
Edit: docs here
John Moehrke (Jul 14 2020 at 16:10):
@Gino Canessa do you have a cloud hosted service? I have some StructureDef that I would really like converted to FSH, and I am not looking forward to doing it by hand.
Gino Canessa (Jul 14 2020 at 16:11):
I plan to, but building the UI is behind some of the languages on the list down a bit on the list.
Chris Moesel (Jul 14 2020 at 17:22):
@Gino Canessa -- the "Usage" and "Extending" links in that doc are 404
.
Gino Canessa (Jul 14 2020 at 18:07):
Thanks @Chris Moesel . GH Pages isn't serving the updated content for some reason - until it updates you can access them via the Articles
tab.
Edit: done, though you may need to force-refresh the page. Thanks again!
Jens Villadsen (Nov 17 2020 at 18:00):
@Gino Canessa how do you handle invariants in your code generation ?
Jens Villadsen (Nov 17 2020 at 18:01):
as in invariants in the profiles
Gino Canessa (Nov 18 2020 at 12:07):
Hi Jens, I was just looking and it doesn't seem that's come up yet. I've added it to my list for parsing, but it would be up to each exported 'language' to decide what to do with them.
Jens Villadsen (Nov 19 2020 at 19:41):
right ... makes sense. Any class annotation / class documentation would however be helpful
Jens Villadsen (Nov 19 2020 at 19:43):
@Gino Canessa an annotation of mine (just as an example, to make your head spin):
Category message invariant:
category.coding.code = 'message' implies (recipient.reference.contains('Patient/') and ( sender.reference.contains('Device/') or contained.ofType(Device).where('#' + id = %resource.sender.reference).empty().not() or extension.where(url = 'http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-communication-senderCareTeam').valueReference.exists())) or (( extension.where(url = 'http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-communication-recipientCareTeam').valueReference.exists()) and (sender.reference.contains('Patient/') or sender.reference.contains('Device/'))) or (extension.where(url = 'http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-communication-recipientCareTeam').valueReference.exists() and extension.where(url = 'http://ehealth.sundhed.dk/fhir/StructureDefinition/ehealth-communication-senderCareTeam').valueReference.exists() )
Gino Canessa (Nov 19 2020 at 19:48):
Yep. I can see the value, just hadn't been added yet since none of the languages were using them. The first step will be getting the invariants parsed (across all FHIR versions) and into a common set of models.
From there, it is straightforward to add something to export in various languages (e.g., annotations, FHIRpath strings, etc.). But there is a long tail around functionality that would be possible (e.g., converting FHIRpath into language-appropriate validation checks using the exported model hierarchy).
Jens Villadsen (Nov 19 2020 at 19:54):
I agree - first step is simply to just generate helper functions (at least in Java) in order to support extensions and associated mechanisms for codeableconcepts and such stuff I guess. I've previously given it a shot where the generation was based on top of HAPI FHIR classes as most Java FHIR devs will probably be using HAPI, and by using extended HAPI classes, everything just works out of the box.
Jens Villadsen (Nov 19 2020 at 19:55):
I actually came pretty far but realised that the need wasn't proportional with the effort of maintaining it
Jens Villadsen (Nov 19 2020 at 19:55):
and I eventually did abandon it
Gino Canessa (Nov 19 2020 at 20:19):
That's one of the primary drivers for the project - by separating out the parsing and normalizing everything (which still has to be done, but that's generally me), the language exports are a lot less work to maintain. Hopefully as it matures, we can build more extended / fun things (e.g., I was playing with an export for cytoscape to use as visualization for the spec).
I'll ping you when I have the invariants added to the core, but it may be a little bit until I get there.
Janaka Peiris (Apr 06 2021 at 12:26):
I see a tool called "Hatchery", at https://github.com/HL7/fhir-shorthand/wiki/4.1-Hatchery. @Chris Moesel is this the same tool you were talking about ? But could not see any code checked in to download. Can you help ?
Jean Duteau (Apr 06 2021 at 13:07):
if you are looking for a tool to go from FHIR structuredefinitions to FSH then it is GoFSH: https://github.com/FHIR/GoFSH. (documentation is here: https://fshschool.org/docs/gofsh/)
Chris Moesel (Apr 06 2021 at 18:54):
@Jean Duteau is exactly right. Hatchery was the early concept name for it, but we eventually ended up calling it GoFSH. That Wiki is fairly outdated at this point. We need to update it or retire it. Thanks for the reminder!
Last updated: Apr 12 2022 at 19:14 UTC