{"_id":"@bluehalo/fhir-response-util","_rev":"8-67c5ddc19fe8b1cea006be4db0b2357d","name":"@bluehalo/fhir-response-util","dist-tags":{"latest":"1.3.0"},"versions":{"1.2.4":{"name":"@bluehalo/fhir-response-util","version":"1.2.4","author":{"name":"Robert-W","email":"rwinterbottom@asymmetrik.com"},"license":"MIT","_id":"@bluehalo/fhir-response-util@1.2.4","maintainers":[{"name":"ashin-bluehalo","email":"andrew.shin@bluehalo.com"},{"name":"ekoon121","email":"ekoon@asymmetrik.com"},{"name":"reblace","email":"reblace@gmail.com"}],"homepage":"https://github.com/BlueHalo/node-fhir-server-core","dist":{"shasum":"5bba9f631d3ca17559ff2efcfc59e9367d04939e","tarball":"https://registry.npmjs.org/@bluehalo/fhir-response-util/-/fhir-response-util-1.2.4.tgz","fileCount":17,"integrity":"sha512-VcStCsLT/rx9c7ReIt+6Bty3Myt1tyShyg1J5yn2CiG11M5qlOJfSWl7YT1bDzVLjzxhl96vTBqG0JWATzv/7g==","signatures":[{"sig":"MEYCIQDEjkFHNUGu7Jvr1Oa56GZEJVkpHskI+Wo6ow3iWnv33wIhAPO3t9G7fkol3pGvjYK4Rz0nKB4VAguLuR5v90d1hhoT","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":93585},"main":"index.js","gitHead":"717c4ad053a5034563d778318b9ccb673d025930","scripts":{"test":"jest"},"_npmUser":{"name":"ashin-bluehalo","email":"andrew.shin@bluehalo.com"},"repository":{"type":"git","directory":"packages/fhir-response-util"},"_npmVersion":"8.5.0","description":"Utility for handling the headers, content, and status types for a response.","directories":{},"_nodeVersion":"16.14.2","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/fhir-response-util_1.2.4_1708113951235_0.3823576188169322","host":"s3://npm-registry-packages"}},"1.3.0":{"name":"@bluehalo/fhir-response-util","version":"1.3.0","author":{"name":"Robert-W","email":"rwinterbottom@asymmetrik.com"},"license":"MIT","_id":"@bluehalo/fhir-response-util@1.3.0","maintainers":[{"name":"ekdeveloper","email":"eugene.koon@bluehalo.com"},{"name":"shane-bh","email":"shane.oneill@bluehalo.com"},{"name":"ashin-bluehalo","email":"andrew.shin@bluehalo.com"},{"name":"reblace","email":"reblace@gmail.com"}],"homepage":"https://github.com/Bluehalo/node-fhir-server-core","dist":{"shasum":"94fccd367f0ba64c506bedb8e809871d4b37b771","tarball":"https://registry.npmjs.org/@bluehalo/fhir-response-util/-/fhir-response-util-1.3.0.tgz","fileCount":6,"integrity":"sha512-ogvdqzH10m9/7viKJRCZg50RFvZLOLuANqCniRETbkknIc//G+gUf8Oa8jZzbHYNJzbahM0QfDYpwpenK8lYWQ==","signatures":[{"sig":"MEQCIHt2vjVLCxJh5gNFaRt788EZ/0V5FASWKqn8IK/tdsUhAiAQUhvOL5QL/s4D66oT86jZwQ7xduM10G9QRachz+ZFCQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23538},"main":"index.js","gitHead":"717c4ad053a5034563d778318b9ccb673d025930","scripts":{"test":"jest"},"_npmUser":{"name":"ekdeveloper","email":"eugene.koon@bluehalo.com"},"repository":{"type":"git","directory":"packages/fhir-response-util"},"description":"Utility for handling the headers, content, and status types for a response.","directories":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0"},"_npmOperationalInternal":{"tmp":"tmp/fhir-response-util_1.3.0_1726061238796_0.22135522791876383","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-02-16T20:05:51.127Z","modified":"2026-03-25T20:10:57.959Z","1.2.4":"2024-02-16T20:05:51.413Z","1.3.0":"2024-09-11T13:27:18.942Z"},"author":{"name":"Robert-W","email":"rwinterbottom@asymmetrik.com"},"license":"MIT","homepage":"https://github.com/Bluehalo/node-fhir-server-core","repository":{"type":"git","directory":"packages/fhir-response-util"},"description":"Utility for handling the headers, content, and status types for a response.","maintainers":[{"email":"reblace@gmail.com","name":"reblace"},{"email":"eugene.koon@bluehalo.com","name":"ekdeveloper"},{"email":"andrew.shin@bluehalo.com","name":"ashin-bluehalo"},{"email":"shane.oneill@bluehalo.com","name":"shane-bh"},{"email":"rnmercado@gmail.com","name":"rodmercad"}],"readme":"# FHIR Response Utility\n\n> Utility for handling the headers, content, and status types for a response\n\n## Install\n\n```shell\nyarn add @bluehalo/fhir-response-util\n```\n\n## Usage\n\nThe response utility exposes the following methods which can be used to for different scenarios and different types of responses. They all make certain assumptions about the arguments they receive which are documented below in the [arguments](#arguments) section.\n\nThis is designed to be used in [node-fhir-server-core](https://github.com/BlueHalo/node-fhir-server-core) and similar FHIR servers. There is some pseudocode with each method's description to give an idea of how this might work. If you read the source code for resource controllers in node-fhir-server-core, you can see how we are using this internally.\n\n### read\n\n> Used when you are returning a Bundle of resources\n\nThis will set the correct Content-Type and status code while sending the json back to the client.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction getPatientsController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .getPatients(req)\n    .then((bundle) => {\n      // Assuming bundle contains a bunch of patients\n      handler.read(req, res, bundle);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n### readOne\n\n> Used when you are returning a single resource of any type.\n\nThis will set the correct Content-Type and status code while sending the json back to the client.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction getPatientController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .getPatient(req)\n    .then((patient) => {\n      handler.readOne(req, res, patient);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n### create\n\n> Used when you are creating a single resource of any type.\n\nThis will set the correct Content-Location, Location, and ETag headers. As well as set the correct status code.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction createPatientController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .create(req)\n    .then((patient) => {\n      let json = { id: patient.id, resource_version: patient.meta.versionId };\n      let options = { type: 'Patient' };\n\n      handler.create(req, res, json, options);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n### update\n\n> Used when you are updating a single resource of any type\n\nThis will set the correct Content-Location, Last-Modified, Location, and ETag headers. As well as set the correct Content-Type and status code.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction updatePatientController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .update(req)\n    .then((patient) => {\n      let json = { id: patient.id, resource_version: patient.meta.versionId, created: false };\n      let options = { type: 'Patient' };\n\n      handler.update(req, res, json, options);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n### remove\n\n> Used when you are deleting a single resource of any type\n\nThis will set the correct ETag header and status code.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction removePatientController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .remove(req)\n    .then((id) => {\n      let json = { deleted: id };\n\n      handler.remove(req, res, json);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n### history\n\n> Used when you are querying the history of a resource of any type\n\nThis will set the correct Content-Type and status code while sending the json back to the client.\n\n```javascript\nconst handler = require('@bluehalo/fhir-response-util');\n\n// Some controller\nfunction getPatientHistoryController(req, res, next) {\n  // The user may have some service to fetch results\n  service\n    .history(req)\n    .then((bundle) => {\n      handler.history(req, res, bundle);\n    })\n    .catch((err) => {\n      next(err);\n    });\n}\n```\n\n## Arguments\n\n[`req`](https://expressjs.com/en/api.html#req) and [`res`](https://expressjs.com/en/api.html#res) that you see in each method are from express. `res` is just a normal response, but request must have a base_version parameter(`req.params.base_version`). Specifically, it should be one of the valid versions we support in our server, which are '1_0_2', '3_0_1', and '4_0_0'. If you would like us to add more versions for this, just let us know, we use this to determine the correct content-type as well as the url of the resource for the response type and response headers.\n\n### read\n\n> handler.read(req, res, json);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nBundle FHIR resource.\n\nType: `Object`  \nRequired: `true`\n\n### readOne\n\n> handler.readOne(req, res, json);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nIndividual FHIR resource.\n\nType: `Object`  \nRequired: `true`\n\n### create\n\n> handler.create(req, res, json, options);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nProperties from the results. Must have an `id`\n\nType: `Object`  \nRequired: `true`\n\n#### `json.id`\n\nID of the FHIR resource that was created.\n\nType: `String`  \nRequired: `true`\n\n#### `json.resource_version`\n\nIf we are using history, which version of the resource did we create.\n\nType: `String`  \nRequired: `false`\n\n#### `options`\n\nAdditional options needed to set the correct headers in the response.\n\nType: `Object`  \nRequired: `true`\n\n#### `options.type`\n\nThis helps us set the content-location and location headers. For example, `handler.create(req, res, json, { type: 'Patient' })` would allow us to set a header like this, `res.set('Location', '4_0_0/Patient/patient-identifier')`.\n\nType: 'String'  \nRequired: 'true'\n\n### update\n\n> handler.update(req, res, json, options);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nProperties from the results. Must have an `id`\n\nType: `Object`  \nRequired: `true`\n\n#### `json.id`\n\nID of the FHIR resource that was created.\n\nType: `String`  \nRequired: `true`\n\n#### `json.resource_version`\n\nIf we are using history, which version of the resource did we create.\n\nType: `String`  \nRequired: `false`\n\n#### `json.created`\n\nDid we create a resource or not. If we created a resource, we need to know so that we can set a `res.status` of 201, otherwise, we will default to a status of 200.\n\nType: `Boolean`  \nRequired: `false`\n\n#### `options`\n\nAdditional options needed to set the correct headers in the response.\n\nType: `Object`  \nRequired: `true`\n\n#### `options.type`\n\nThis helps us set the content-location and location headers. For example, `handler.create(req, res, json, { type: 'Patient' })` would allow us to set a header like this, `res.set('Location', '4_0_0/Patient/patient-identifier')`.\n\nType: 'String'  \nRequired: 'true'\n\n### remove\n\n> handler.remove(req, res, json);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nJSON for the response. Not required but contains the optional deleted property.\n\nType: `Object`  \nRequired: `false`\n\n#### `json.deleted`\n\nThe deleted property should be the id of the element deleted. For example, `handler.remove(req, res, { deleted: 'qwerty-123' })`. This allows us to add the identifier as a ETag in the response header.\n\nType: `Object`  \nRequired: `false`\n\n### history\n\n> handler.history(req, res, json);\n\n#### `req`\n\nExpress request.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `res`\n\nExpress response.\n\nType: `Express.req`  \nRequired: `true`\n\n#### `json`\n\nBundle FHIR resource.\n\nType: `Object`  \nRequired: `true`\n","readmeFilename":"README.md"}