Write Data

Introduction

Component for mutating FHIR data using the Commure FHIR API. This is a Higher-Order Component that passes a mutate function as a prop to the component you supply it.

Usage

Make sure to wrap your app in <CommureSmartApp /> to get access to the data.

withFhirDataMutate

Use this when you want to POST, PUT, or PATCH a resource.

1import React, { useState, useEffect } from "react";
2import { FhirMethod, withFhirDataMutate, FhirDataMutateConsumer } from "@commure/components-data";
3import { Resource, Bundle } from "@commure/fhir-types/r4/types";
4
5interface AnyResource extends Resource {
6 [key: string]: any;
7}
8
9const MyComponent = (props: FhirDataMutateConsumer) => {
10 const { mutate } = props;
11 const [outcome, setBundle] = useState<Bundle | undefined>(undefined);
12 useEffect(() => {
13 mutate({
14 query: "Patient",
15 body: {
16 resourceType: "Patient",
17 name: [{ given: ["joe"] }],
18 gender: "female"
19 } as AnyResource,
20 method: FhirMethod.POST
21 })
22 .then((response: Response) => response.clone().json())
23 .then(data => setBundle(data));
24 }, [mutate]);
25
26 return <div>Outcome: {JSON.stringify(outcome)}</div>;
27};
28
29export default withFhirDataMutate(MyComponent);

Troubleshooting

If you run into an error saying:

1No FhirClientProvider found in component tree

make sure that you have wrapped this component (or your app) in a <CommureSmartApp />.

Note that we only support JSON patches right now, though the FHIR Spec supports XML and FHIRPath patches.

Related Reading

Commure FHIR API
SMART
Read data