Tuesday, 1 February 2022

How to update a value in a complex fhirBundle JSON?

Given a bewildering fhir document like https://raw.githubusercontent.com/Notarise-gov-sg/api-notarise-healthcerts/master/test/fixtures/v2/pdt_art_with_nric_unwrapped.json

I need to update the part the JSON from { "id": "NRIC-FIN", "value": "S9098989Z" } to { "id": "NRIC-FIN", "value": "foobar" } and then emit the whole JSON again with that change.

I just about know how to access the value.

const fs = require("fs");
let rawdata = fs.readFileSync("pdt_art_with_nric_unwrapped.json");
let art = JSON.parse(rawdata);

let nric = art.fhirBundle.entry
  .flatMap((entry) => entry.resource)
  .find((entry) => entry.resourceType === "Patient")
  .identifier.find((entry) => entry.id === "NRIC-FIN").value;

console.log(nric);

Though I am puzzled how to update this value since it's so difficult to access. Am I missing a trick? I don't want to use regex btw!



from How to update a value in a complex fhirBundle JSON?

No comments:

Post a Comment