Skip to content

Instantly share code, notes, and snippets.

@mdlavin
Last active August 1, 2022 12:34
Show Gist options
  • Save mdlavin/40d464aeaecafb47720dd7610225cfb2 to your computer and use it in GitHub Desktop.
Save mdlavin/40d464aeaecafb47720dd7610225cfb2 to your computer and use it in GitHub Desktop.
Secure Health Data Storage Article - Create Observation Snippet
const createObservation = async (accountId: string, projectId: string, patientId: string) => {
const observation = await fetch(`https://fhir.us.lifeomic.com/${accountId}/dstu3/Observation`, {
method: 'POST',
headers: {
authorization: `Bearer ${process.env.PHC_API_KEY}`,
'content-type': 'application/json'
},
body: JSON.stringify({
resourceType: "Observation",
// Record the subject of the observation. In this case
// who is being weighed.
subject: {
reference: `Patient/${patientId}`
},
// Record the data from the observation. The weight
// and time of weighing
effectiveDateTime: "2022-07-28",
valueQuantity: {
value: 152,
unit: "lbs",
system: "http://unitsofmeasure.org",
code: "[lb_av]"
},
// Record what type of measurement this is. There are
// registiries of existing measurement types, LIONC and SNOMED,
// but you can make up your own too.
code: {
coding: [
{
system: "http://loinc.org",
code: "29463-7",
display: "Body Weight"
},
{
system: "http://loinc.org",
code: "3141-9",
display: "Body weight Measured"
},
{
system: "http://snomed.info/sct",
code: "27113001",
display: "Body weight"
}
]
},
// Same as for creating Patients, this resource must be owned by a PHC project
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": "Observation",
// ...rest
// }
return observation.json();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment