FHIR Chat · custom resource and example · shorthand

Stream: shorthand

Topic: custom resource and example


view this post on Zulip Carl Leitner (Apr 01 2021 at 12:45):

I am struggling a bit in trying to get sushi to process a custom resource and an example. I run into two issues:
1) the custom resource has to be hardcoded into the IG.xml file
2) when trying to create an example of the custom resource, sushi doesn't seem to know about the custom resource

view this post on Zulip Carl Leitner (Apr 01 2021 at 12:46):

Issue w/ 2 may very well be my issue, but not sure what it should be. Does anyone have a complete example of a similar scenario?

view this post on Zulip Carl Leitner (Apr 01 2021 at 12:55):

FYI here is what I am looking at:

Sushi error is: error InstanceOf SVC-QR-UVCI not found for svc-qr-uvci-example

view this post on Zulip Carl Leitner (Apr 01 2021 at 12:55):

any help would be appreciated!

view this post on Zulip Martin Höcker (Apr 01 2021 at 13:51):

I'm no sushi expert, but I ran into similar problems. As far as I understand, the problem is that StructureDefinitions created with Instance: are not put into the appropriate internal data-structures that hold all the other StructureDefinitions.

One thing you can do (it's undocumented!), is to run sushi once, then take the generated StructureDefinition-SVC-QR-UVCI-json and place it into the folderinput/resources. Then, on the next run, it will be available, because sushi scans this folder and parses all contents into the appropriate data-structures. This is the method that I am currently using.

Another method could be to place the generated StructureDefinition into your local FHIR-cache (look for a folder called .fhir in your user-directory/home-directory). You could either place it into the 4.0.1 package (super-hacky!), or you create a new, local package and metion this local package as a dependency in the sushi-config.yaml.

view this post on Zulip Chris Moesel (Apr 01 2021 at 14:52):

@Martin Höcker got it pretty well right. Not bad for someone who claims to not be a SUSHI expert! ;-)

Ideally, SUSHI should support creating an instance of a StructureDefinition that is defined using Instance. The fact that we don't is at-best a limitation (and at-worst a bug). BUT... even if SUSHI could find it, SUSHI would still not be able to use it because it does not have a snapshot. SUSHI requires a snapshot in order to properly process an SD as the basis for an instance (or as a parent of a profile). So if we made it so SUSHI could find that SD instance, you would still need to update the instance to also include the snapshot elements (which is tedious, I know).

Martin's idea to write the FSH and then generate the SD and copy the SD into input/resources is probably your best bet for now. But there are a few things to note: (a) Since SUSHI needs the snapshot, you'd actually want to use the SD that is produced by the IG Publisher (since it will generate the snapshot for you). (b) You'll want to comment out the FSH that originally produced the instance so that we don't have duplicate definitions to contend with.

The good news is that support for logical models and custom resources is in the works (thanks to @Joe Paquette at athenaHealth). We hope to have native support for building custom resources soon! Once we have that, you won't need to use Instance and all this stuff should work much better.

view this post on Zulip Carl Leitner (Apr 01 2021 at 15:07):

thanks @Chris Moesel and @Martin Höcker for the suggestions. the pre-pre-processing with SUSHI was what I was expecting (assuming there was no magic bullet/errors on my side). I guess for b) I could also have a second non-normative directory like inputs/pre-fsh or so.

view this post on Zulip Martin Höcker (Apr 01 2021 at 15:17):

Ahh, yes, I forgot about the snapshot! I don't yet have IG in my toolchain, so I use sushi -s to generate the snapshot.

view this post on Zulip Chris Moesel (Apr 01 2021 at 15:29):

The -s flag does a decent job of producing the snapshot for profiles/extensions created using the Profile:/Extension: syntax, but it will not produce a valid snapshot for StructureDefinitions created using the Instance: syntax.

view this post on Zulip Martin Höcker (Apr 01 2021 at 15:48):

:open_mouth: That's good to know! And also good proof that I'm not a sushi expert! :smile:

Come to think of it, generating the custom resources happened a long time ago and some massaging was necessary afterwards (for other reasons). It could be that we generated the snapshot in another way.

Looking forward to the full support of custom resources!

view this post on Zulip Carl Leitner (Apr 01 2021 at 17:02):

@Chris Moesel should I take your last comment to mean that for the time being it's probably better just to not use fsh for the customer resource and really just do it by hand? Or are you saying that we should be using a something different than the instance syntax? ( Flagging for @Luke Duncan )

view this post on Zulip Chris Moesel (Apr 01 2021 at 17:12):

@Carl Leitner - My last comment (re: the -s flag) means you should not rely on SUSHI to create a snapshot. This is why I recommended in my earlier comment that if you put the built SD into input/resources, use the SD created by the IG Publisher (not directly from SUSHI). In other words, this should work fine for creating and using custom resources:

  1. Use FSH Instance syntax to create an instance of StructureDefinition with differential elements specified.
  2. Build w/ SUSHI to produce formal SD in fsh-generated, but it will still have no snapshot elements.
  3. Use IG Publisher to build the IG, which will create a new SD in output w/ the snapshot elements.
  4. Copy the SD from output to input/resources so that SUSHI will pick it up as a FHIR definition next time.
  5. Comment out the original FSH definition (from step 1) so SUSHI doesn't generate it again.
  6. Now you can use that custom resource as an InstanceOf or Parent in other FSH definitions.

Of course you can use another tool (like Forge) to create the custom resource, but if you prefer to use FSH and don't mind the sequence up above, it should work. Of course, you'll need to redo that every time you need to make edits to the custom resource.

view this post on Zulip Carl Leitner (Apr 01 2021 at 17:14):

Thanks @Chris Moesel for clearly articulating the process!

view this post on Zulip Carl Leitner (Apr 05 2021 at 14:33):

Hi @Chris Moesel I did try the suggestions you provided (see lines 42-52 here FWIW https://github.com/who-int/svc/blob/rc2/pre-process-fishy-examples.sh) but it didn't seem to process the example.

Note, I really am trying to get the $transform of the examples. It seems that I should be adding exValue and index extensions along the lines of https://hl7.org/fhir/2017Jan/extension-structuredefinition-example.json.html as the IG Publisher seems to process those:
https://github.com/hapifhir/org.hl7.fhir.core/blob/master/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/conformance/ProfileUtilities.java#L4176

Do you know if sushi or the IG publisher was injecting these extensions from the examples into the SD snapshot?

view this post on Zulip Carl Leitner (Apr 05 2021 at 14:34):

flagging for @Luke Duncan

view this post on Zulip Chris Moesel (Apr 06 2021 at 21:12):

Hi @Carl Leitner. I checked this out locally to try to get a better understanding of it. I ran the commands in your script one at a time to see what happened. Here's what I found...

First I did:

rm -f input/resources/StructureDefinition-svc-qr-uvci.xml
rm -f input/resources/StructureDefinition-svc-qr-uvcei.xml
rm -f input/fsh/svc-qr-uvci-example.fsh
rm -f input/fsh/svc-qr-uvcei-example.fsh
rm -f input/examples/svc-qr-uvci-example.json
rm -f input/examples/svc-qr-uvcei-example.json
cp input/pre-generated/svc-qr-uvci.fsh input/fsh/svc-qr-uvci.fsh
cp input/pre-generated/svc-qr-uvcei.fsh input/fsh/svc-qr-uvcei.fsh
sushi

SUSHI ran just fine.

Then I did:

./_genonce.sh

I noticed two thrown exceptions from the IG Publisher. I'm not sure if we care of if this is expected?

  • Exception generating resource /Users/cmoesel/dev/fsh/svc/fsh-generated/resources/StructureDefinition-svc-qr-uvcei::StructureDefinition/svc-qr-uvcei: not the right kind of structure to generate schematrons for (00:47.0621)
  • Exception generating resource /Users/cmoesel/dev/fsh/svc/fsh-generated/resources/StructureDefinition-svc-qr-uvci::StructureDefinition/svc-qr-uvci: not the right kind of structure to generate schematrons for (00:49.0336)

Then I did:

cp output/StructureDefinition-svc-qr-uvci.xml input/resources/
cp output/StructureDefinition-svc-qr-uvcei.xml input/resources/
cp input/pre-generated/svc-qr-uvci-example.fsh input/fsh
cp input/pre-generated/svc-qr-uvcei-example.fsh input/fsh
rm -f input/fsh/svc-qr-uvci.fsh
rm -f input/fsh/svc-qr-uvcei.fsh

I got one error, which was a valid error because it does seem that file is not checked in.

  • cp: input/pre-generated/svc-qr-uvcei-example.fsh: No such file or directory

I continued and ran this again:

./_genonce.sh

SUSHI ran cleanly again (no errors) and the IG Publisher reported the same two exceptions as before.

Then I ran these commands, although, honestly, I'm not sure I understand the point of them:

rm -f input/fsh/svc-qr-uvci-example.fsh
rm -f input/fsh/svc-qr-uvcei-example.fsh
mkdir -p input/examples
cp fsh-generated/resources/svc-qr-uvci-example.json input/examples
cp fsh-generated/resources/svc-qr-uvcei-example.json input/examples

I again received an error regarding the missing uvcei example, but that's expected since the fsh file wasn't checked in (so SUSHI didn't generate it).

And finally ran SUSHI one more time:

sushi .

and did not receive any errors. Does this line up w/ what you've experienced? The problem I was trying to solve above was getting past the SUSHI error, and it seems that this process has gotten around that.

BUT... I did notice that the IG Publisher does not seem to render the example of your custom resource. So we've got past the FSH issue but now are into a potential issue w/ the IG Publisher. I'm not sure what is going on there. It may be worth asking in #IG creation if there are any additional steps needed to cause the IG Publisher to correctly process examples of custom resources.

view this post on Zulip Chris Moesel (Apr 06 2021 at 21:26):

Actually, I just noticed an error I missed before. The second time running genonce.sh, the IG Publisher emits this error:

This does not appear to be a FHIR resource (unknown name 'svc-qr-uvci') at line -1 col -1 loading /Users/cmoesel/dev/fsh/svc/fsh-generated/resources/svc-qr-uvci-example.js

This looks like it's definitely the reason we don't get the example in the IG. The publisher, for whatever reason, does not recognize the custom resource.

view this post on Zulip Chris Moesel (Apr 06 2021 at 21:37):

BTW -- I wondered if the problem might be that your resource name did not follow the recommended format, so I changed svc-qr-uvci to SvcQrUvci -- but that did not change anything. It still had all the same errors and did not produce an example in the IG.

view this post on Zulip Carl Leitner (Apr 07 2021 at 14:17):

thanks for looking @Chris Moesel - yes, I had tried other versions of the ID format as well to no success. Looks like I need to go through the IG Publisher code more carefully. BTW... I don't think the schematron warning is related (at least directly) to the example issue - it's in a different part of the IG publisher

view this post on Zulip Carl Leitner (Apr 07 2021 at 14:17):

(and yes, you previous comment does line up w/ my experience)


Last updated: Apr 12 2022 at 19:14 UTC