Is anyone aware of some good resources discussing ...
# general
c
Is anyone aware of some good resources discussing moving data from another FHIR API into Medplum? I think my needs are fairly simple - essentially performing a read to another FHIR API (e.g. the
Patient/$everything
operation), then pushing the resulting bundle/resources into Medplum (ideally in an upsert fashion). I'm using the TS SDK and playing around with
validateResource
and
createResource
, but I have to imagine this is a fairly common use case with common patterns to follow (and pitfalls to avoid!) I'm also pretty new to FHIR generally, so I feel like I might be missing some important context. Some things I'm thinking about: - Whether any transformation is required to go from a resource that was read, to one which is suitable for writing (e.g. stripping out certain fields). - How to handle poor adherence to FHIR on the source API - e.g. missing or additional properties. (Maybe this is not such an issue with FHIR? I am already seeing some fields prepended with underscores unexpectedly, though). - How to handle deduplication generically (e.g. with the provided source identifier(s) - I know these can be passed as an extra query arg to
createResourceIfNoneExist
), and perform a create or update accordingly.
Here's an example of an error I'm seeing from `validateResource`:
Copy code
{
    "severity": "error",
    "code": "structure",
    "details": {
      "text": "Missing required property"
    },
    "expression": [
      "ExplanationOfBenefit.supportingInfo.sequence"
    ]
  },
  {
    "severity": "error",
    "code": "structure",
    "details": {
      "text": "Invalid additional property \"ExplanationOfBenefit.supportingInfo._sequence\""
    },
    "expression": [
      "ExplanationOfBenefit.supportingInfo._sequence"
    ]
  },
My understanding is that the underscore is indicative of an extension, where the actual "value" is further down in the structure; but I'm not sure why this is not recognized by Medplum, or why the source API thinks it should be an extension.
Ahh, this is the data:
Copy code
_sequence: {
              extension: [
                {
                  url: "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
                  valueCode: "unknown",
                },
              ],
            },
r
Hi @codingtom , I'm happy to assist. Out of curiosity, which FHIR server are you pulling data from?
> Whether any transformation is required to go from a resource that was read, to one which is suitable for writing (e.g. stripping out certain fields). In general this should not be necessary for a given resource. The only caveat would be for
Bundle
resources, which have an input and output flavor. However, if you're using the
Patient/$everything
operation, you shouldn't have to deal with bundles
> How to handle poor adherence to FHIR on the source API - e.g. missing or additional properties. (Maybe this is not such an issue with FHIR? I am already seeing some fields prepended with underscores unexpectedly, though). As you noted, the underscores indicate that an extension is present on a primitive field. After doing some research, I found that there is a special case for missing data, which your source server conforms to https://www.hl7.org/fhir/extensibility.html#Special-Case
We'll open a ticket to make sure we handle that properly in our validation rules
In the meantime, you can disable "strict mode" on your project, to reduce some of the validation checks on the server side
You can do that by 1. Navigating to https://app.medplum.com/Project, 2. Clicking on your project 3. Clicking on the Edit tab 4. Unchecking the "stict mode" checkbox
c
Thanks for taking a look, Rahul!
> Out of curiosity, which FHIR server are you pulling data from? These are payer FHIR APIs, queried via Flexpa
The above example comes from Cigna, specifically
> In general this should not be necessary for a given resource. The only caveat would be for Bundle resources, which have an input and output flavor. > > However, if you're using the Patient/$everything operation, you shouldn't have to deal with bundles Interesting, I'll look into this.
Patient/$everything
does actually return a Bundle, but it's easy enough to just iterate through the resources and create one by one too. Do you have any recommendations for dealing with references? It seems like Medplum forces creation of new IDs for resources that are inserted. Do I need to then keep track of a mapping of original->inserted IDs, and deeply modify each resource to update its references? This introduces complexity for making sure all of a resource's dependent resources are inserted first, but still doable I suppose. This is another example of what feels like a common pitfall, though. Maybe this is handled automatically if I am performing a bulk action?
> In the meantime, you can disable "strict mode" on your project, to reduce some of the validation checks on the server side Thanks for the suggestion! Unfortunately, it does not resolve the extension case mentioned above, but will keep it in mind if other discrepancies pop up 🙂
r
Regarding references, unfortunately there is not a FHIR-standard way to convert an output bundle into an input bundle with all the references rewritten properly. You can read more about "FHIR Transactions" here, to see how you could create a bundle that can be input. https://hl7.org/fhir/R4/bundle.html#references We do also have a helper function to try to automate this process, but I have to caution that it is very experiment so may not work 100% perfectly. There are a lot of edge cases to these kinds of conversions (cycles, non-conformance, etc.) https://www.medplum.com/docs/sdk/modules#converttotransactionbundle
Our Batch upload tool (https://www.medplum.com/docs/tutorials/importing-sample-data#batch-upload-tool) also uses this conversion in the UI
c
Ahh sweet, thankyou! Will look into the helper function. Appreciate the pointers 🙂
r
Hi @codingtom - i just wanted to let you know that we've fixed the issue that was causing validation errors for your flexpa data
If you could try again, I'm hoping you will be able to upload
c
I did see that, thankyou! Will have to try my code again
r
Thank you for bringing it to our attention 🙂
150 Views