FHIR Chat · Reverse FHIR Version Mapping · implementers

Stream: implementers

Topic: Reverse FHIR Version Mapping


view this post on Zulip Luke Swindale (Apr 01 2020 at 03:37):

Howdy @Grahame Grieve . I've tested using org.hl7.fhir.convertors.VersionConvertor_30_40 (https://github.com/hapifhir/org.hl7.fhir.core) to convert some STU3 resources to R4 and from what I've seen so far this seems to match my own original implementation. However, we also have the need to convert back from R4 to STU3 for a number of resources. I can't find anything in the org.hl7.fhir.convertors project that does that. I've also noticed that there are StructureMaps on the HL7 site for this purpose so I'm hoping there may already be an implementation. Is there any intention to incorporate the back conversion into the convertors project? I think I've got something that covers our discrete requirements but would prefer to use an existing library if there's something available.

view this post on Zulip Grahame Grieve (Apr 01 2020 at 03:43):

VersionConvertor_30_40 mostly has bidirectional converters. what resource types are you interested in?

view this post on Zulip Luke Swindale (Apr 01 2020 at 04:37):

oh right. I mustn't didn't have had a good enough look. At the moment, just CodeSystem, ValueSet and ConceptMap. At the moment I've got the following. Obviously, VersionConverter_40_30 doesn't exist, so that'll be the bit I need to work out. Cheers.

           IBaseResource sourceResource = this.sourceJsonParser.parseResource(reader);
            IBaseResource targetResource = null;

            if (sourceResource.getStructureFhirVersionEnum().isEquivalentTo(FhirVersionEnum.DSTU3) &&
                    targetResource.getStructureFhirVersionEnum().isEquivalentTo(FhirVersionEnum.R4)) {
                targetResource = VersionConvertor_30_40.convertResource((Resource) sourceResource, true);
            } else if (sourceResource.getStructureFhirVersionEnum().isEquivalentTo(FhirVersionEnum.R4) &&
                    targetResource.getStructureFhirVersionEnum().isEquivalentTo(FhirVersionEnum.DSTU3)) {
                targetResource = VersionConvertor_40_30.convertResource((Resource) sourceResource, true);
            } else {
                targetResource = VersionConvertor_30_40.convertResource((Resource) sourceResource, true);
            }

            this.targetJsonParser.encodeResourceToWriter(targetResource, writer);

view this post on Zulip Grahame Grieve (Apr 01 2020 at 04:42):

no the 30_40 has methods for both ways for those classes.

view this post on Zulip Grahame Grieve (Apr 01 2020 at 04:43):

e.g. org.hl7.fhir.convertors.conv30_40.CodeSystem30_40 has both

  public static org.hl7.fhir.r4.model.CodeSystem convertCodeSystem(org.hl7.fhir.dstu3.model.CodeSystem src);

and

  public static org.hl7.fhir.dstu3.model.CodeSystem convertCodeSystem(org.hl7.fhir.r4.model.CodeSystem src) {

view this post on Zulip Luke Swindale (Apr 01 2020 at 04:44):

wow.... I really should have looked harder. Thanks @Grahame Grieve ! Thats a big help

view this post on Zulip Grahame Grieve (Apr 01 2020 at 04:44):

and VersionConvertor_30_40 has

public static org.hl7.fhir.r4.model.Resource convertResource(org.hl7.fhir.dstu3.model.Resource src, boolean nullOk);

and

public static org.hl7.fhir.r4.model.Resource convertResource(org.hl7.fhir.dstu3.model.Resource src, boolean nullOk);

Last updated: Apr 12 2022 at 19:14 UTC