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.

import React, { useState, useEffect } from "react";
import { FhirMethod, withFhirDataMutate, FhirDataMutateConsumer } from "@commure/components-data";
import { Resource, Bundle } from "@commure/fhir-types/r4/types";
interface AnyResource extends Resource {
[key: string]: any;
}
const MyComponent = (props: FhirDataMutateConsumer) => {
const { mutate } = props;
const [outcome, setBundle] = useState<Bundle | undefined>(undefined);
useEffect(() => {
mutate({
query: "Patient",
body: {
resourceType: "Patient",
name: [{ given: ["joe"] }],
gender: "female"
} as AnyResource,
method: FhirMethod.POST
})
.then((response: Response) => response.clone().json())
.then(data => setBundle(data));
}, [mutate]);
return <div>Outcome: {JSON.stringify(outcome)}</div>;
};
export default withFhirDataMutate(MyComponent);

Troubleshooting

If you run into an error saying:

No 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