Skip to the content.

Fhir.js methods and their client-js equivalents

read

client.request("ResourceType/resourceId")

// client-js also has 3 methods for reading the current user, patient and encounter
client.user.read()
client.patient.read()
client.encounter.read()

vread

client.request("ResourceType/resourceId/_history/versionId")

conformance

client.request("metadata")
client.request("ResourceType?query")

create

client.request({
    url: "ResourceType",
    method: "POST"
    body: data
})

or

client.create(data)

update

client.request({
    url: "ResourceType/resourceId",
    method: "PUT"
    body: data
})

or

client.update(data)

delete

client.request({
    url: "ResourceType/resourceId",
    method: "DELETE"
})

or

client.delete("ResourceType/resourceId")

patch

client.patch("ResourceType/resourceId", [
    { op: "replace", path: "/something", value: "something else" }
])

transaction

client.request({
    url: "/",
    method: "POST"
    body: data
})

validate

client.request({
    url: "ResourceType/resourceId/_validate",
    method: "POST"
    body: data
})

fetchAll

client.request("ResourceType?optional-query", {
    pageLimit: 0
})

fetchAllWithReferences

client.request("ResourceType?optional-query", {
    pageLimit: 0,
    resolveReferences: [ "someReference" ],
    graph: false // Set to true or omit to have the references mounted into the resource tree
})

Building query strings

Without fhir.js the mongo-like syntax is not available. However, the request function also accepts URL instances as it’s first argument (or as value of the url property of the first argument if that is an object). This means that your browser will be polyfill-ed if needed and URL and URLSearchParams will always be available in the global scope (even in Node). Here are some examples of building search queries:

// First 10 patients sorted by name
const query = new URLSearchParams();
query.set("_sort", "name");
query.set("_count", 10);
client.request(`Patient?${query}`);


// Real-life example borrowed from the Growth Chart App
function fetchVitals(client) {
    var query = new URLSearchParams();
    query.set("patient", client.patient.id);
    query.set("_count", 100); // Try this to fetch fewer pages
    query.set("code", [
        'http://loinc.org|29463-7', // weight
        'http://loinc.org|3141-9' , // weight
        'http://loinc.org|8302-2' , // Body height
        'http://loinc.org|8306-3' , // Body height --lying
        'http://loinc.org|8287-5' , // headC
        'http://loinc.org|39156-5', // BMI 39156-5
        'http://loinc.org|18185-9', // gestAge
        'http://loinc.org|37362-1', // bone age
        'http://loinc.org|11884-4'  // gestAge
    ].join(","));
    return client.request("Observation?" + query, {
        pageLimit: 0,   // get all pages
        flat     : true // return flat array of Observation resources
    });
}