Posting a Resource
An understanding of how to use the SMART Client is required before reading this section.
Example: Posting a DocumentReference to Epic
The following code snippet takes a Client
object and uses it to post a DocumentReference note to Epic:
const response = await myClient.create(myDocumentReference).catch((reason) => {
throw new Error(`Failed to create resource because: ${reason}`);
});
console.log(response);
The corresponding myDocumentReference
:
const noteText = "Some example Note text"
const myDocumentReference: DocumentReference = {
"resourceType": "DocumentReference",
"status": "current",
"docStatus": "final",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "11488-4",
"display": "Consultation Note"
}
],
"text": "Consultation Note"
},
"content": [
{
"attachment": {
"contentType": "text/plain",
"data": `${Buffer.from(noteText).toString('base64')}`
}
}
]
};
Note that we’re posting the Document as an HL7 FHIR Resource defined using HL7’s respective Typescript package
Additionally, our DocumentReference is missing Patient
and Encounter
information. That’s because our create
function for posting Resources automatically gets the Patient and Encounter context from our Client
object and inserts it into myDocumentReference
before posting it to the EMR. The respective response
object shows us the Resource that was fully fleshed out and created as a result of calling the function:
{
"resourceType": "DocumentReference",
"id": "eVehqmHLo5UycK879nxPi2g3",
"identifier": [
{
"system": "urn:oid:1.2.840.114350.1.13.0.1.7.2.727879",
"value": "196963"
},
{
"system": "urn:oid:1.2.840.114350.1.72.3.15",
"value": "1.2.840.114350.1.13.0.1.7.2.727879_196963"
}
],
"status": "current",
"docStatus": "final",
"type": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.0.1.7.4.737880.5010",
"code": "2",
"display": "Consults"
},
{
"system": "urn:oid:1.2.840.114350.1.72.727879.69848980",
"code": "2",
"display": "Consults"
},
{
"system": "http://loinc.org",
"code": "11488-4",
"display": "Consult note",
"userSelected": true
}
],
"text": "Consults"
},
"category": [
{
"coding": [
{
"system": "http://hl7.org/fhir/us/core/CodeSystem/us-core-documentreference-category",
"code": "clinical-note",
"display": "Clinical Note"
}
],
"text": "Clinical Note"
}
],
"subject": {
"reference": "Patient/eOPSKZbz6YIgoilQprzPy0Q3",
"display": "Cadence, Anna"
},
"date": "2023-06-22T19:41:32Z",
"author": [
{
"reference": "Practitioner/evNp-KhYwOOqAZn1pZ2enuA3",
"type": "Practitioner",
"display": "User Interconnect"
}
],
"authenticator": {
"extension": [
{
"valueDateTime": "2023-06-22T19:41:32Z",
"url": "http://open.epic.com/FHIR/StructureDefinition/extension/clinical-note-authentication-instant"
}
],
"reference": "Practitioner/evNp-KhYwOOqAZn1pZ2enuA3",
"type": "Practitioner",
"display": "User Interconnect"
},
"custodian": {
"identifier": { "system": "urn:ietf:rfc:3986", "value": "urn:oid:fhir" },
"display": "Epic USCDI on FHIR"
},
"securityLabel": [
{
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-ActCode",
"code": "NOPAT",
"display": "no disclosure to patient, family or caregivers without attending provider's authorization"
}
],
"text": "no disclosure to patient, family or caregivers without attending provider's authorization"
}
],
"content": [
{
"attachment": {
"contentType": "text/html",
"url": "Binary/eKsW51SKNSHP1EO4P4wYFpA3"
},
"format": {
"system": "http://ihe.net/fhir/ValueSet/IHE.FormatCode.codesystem",
"code": "urn:ihe:iti:xds:2017:mimeTypeSufficient",
"display": "mimeType Sufficient"
}
},
{
"attachment": {
"contentType": "text/rtf",
"url": "Binary/fXSaIwomPYHPUiA17s0dUWstMdTZcwU3xbmhNJrv7kck4"
},
"format": {
"system": "http://ihe.net/fhir/ValueSet/IHE.FormatCode.codesystem",
"code": "urn:ihe:iti:xds:2017:mimeTypeSufficient",
"display": "mimeType Sufficient"
}
}
],
"context": {
"extension": [
{
"valueCodeableConcept": {
"coding": [
{
"system": "urn:oid:1.2.840.114350.1.13.0.1.7.4.836982.1040",
"code": "3",
"display": "Registered Nurse"
}
],
"text": "Registered Nurse"
},
"url": "http://open.epic.com/FHIR/StructureDefinition/extension/clinical-note-author-provider-type"
}
],
"encounter": [
{
"reference": "Encounter/eVffiE7SavpOc0PtATuBQWg3",
"identifier": {
"use": "usual",
"system": "urn:oid:1.2.840.114350.1.13.0.1.7.3.698084.8",
"value": "27485"
},
"display": "Office Visit"
}
],
"period": { "start": "2019-04-18T13:30:00Z" }
}
}
Note that the content is stored in an attachment url. The following is an example of how to read back the DocumentReference Binary content from the EMR to confirm that the POST was successful:
const docReferenceBinaryIds = response.content.map(item => item.attachment.url)
const attachments = docReferenceBinaryIds.filter((id): id is string => !!id).map(async id => {
return await baseClient.requestResource(id)
})
attachments.forEach(async attachment => console.log(await attachment))