Skip to content

Instantly share code, notes, and snippets.

@mdlavin
Last active August 1, 2022 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdlavin/32eae32122b7e8a0113b1db44ba6a465 to your computer and use it in GitHub Desktop.
Save mdlavin/32eae32122b7e8a0113b1db44ba6a465 to your computer and use it in GitHub Desktop.
Secure Health Data Storage Article - Create Patient Snippet
const createPatient = async (accountId: string, projectId: string) => {
const patient = await fetch(`https://fhir.us.lifeomic.com/${accountId}/dstu3/Patient`, {
method: 'POST',
headers: {
authorization: `Bearer ${process.env.PHC_API_KEY}`,
'content-type': 'application/json'
},
body: JSON.stringify({
resourceType: "Patient",
// Fill in the details of your patient
name: [
{
use: "official",
family: "Lavin",
given: ["Matt"]
}
],
gender: "male",
// Add a `meta` tag to the resource so that the PHC knows what project to put the patient in.
meta: {
tag: [
{
system: 'http://lifeomic.com/fhir/dataset',
code: projectId
}
]
}
})
})
// The result from the POST is a copy of the body from above
// and also includes a new `id` attribute.
// {
// "id": <newid>
// "resourceType": "Patient",
// ...rest
// }
return patient.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment