From c930e1bb4a1f4094fbb4b7f0e240f4bf18ab2b58 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Tue, 23 May 2023 19:50:50 +0100 Subject: [PATCH] fix: remove reference to pipe encoding and content-type --- README.md | 2 +- src/config/index.js | 4 ++-- src/plugins/hl7v2-to-json/index.js | 8 ++++---- src/routes/hl7v2/json/index.js | 6 +++--- src/routes/hl7v2/json/schema.js | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fa23b0769..8edad88bd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Docsmith is a RESTful API, built using Node.js and the [Fastify](https://fastify - DOC to TXT - DOCX to HTML - DOCX to TXT -- HL7v2 to JSON ("vertical bar" encoded) +- HL7 v2.x to JSON - HTML to TXT - PDF to HTML - PDF to TXT diff --git a/src/config/index.js b/src/config/index.js index 6f889c93c..cdbfe1d92 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -274,9 +274,9 @@ async function getConfig() { "Endpoints used for the conversion of DOCX documents", }, { - name: "HL7v2", + name: "HL7 v2.x", description: - 'Endpoints used for the conversion of "vertical bar" encoded HL7 v2.x messages', + "Endpoints used for the conversion of HL7 v2.x messages", }, { name: "HTML", diff --git a/src/plugins/hl7v2-to-json/index.js b/src/plugins/hl7v2-to-json/index.js index ffc8b567f..2cebea8cf 100644 --- a/src/plugins/hl7v2-to-json/index.js +++ b/src/plugins/hl7v2-to-json/index.js @@ -4,7 +4,7 @@ const hl7v2 = require("@redoxengine/redox-hl7-v2"); /** * @author Frazer Smith * @description Pre-handler plugin that uses redox-hl7-v2 to convert string containing - * "vertical bar" encoded HL7 v2.x in `req.body` to JSON. + * HL7 v2.x in `req.body` to JSON. * `req` object is decorated with `conversionResults.body` holding the converted document. * @param {object} server - Fastify instance. */ @@ -25,14 +25,14 @@ async function plugin(server) { // } try { - const results = parser.parse(req.body.toString()); + const results = parser.parse(req.body); req.conversionResults.body = results; - } catch (err) { + } catch { /** * redox-hl7-v2 will throw if the HL7 v2 message provided * by client is malformed or invalid, thus client error code */ - throw server.httpErrors.badRequest(err.message); + throw server.httpErrors.badRequest(); } }); } diff --git a/src/routes/hl7v2/json/index.js b/src/routes/hl7v2/json/index.js index fbafa5aa3..683d0d040 100644 --- a/src/routes/hl7v2/json/index.js +++ b/src/routes/hl7v2/json/index.js @@ -24,14 +24,14 @@ async function route(server, options) { } server.addContentTypeParser( - "text/plain", + "text/hl7v2", { parseAs: "string" }, async (_req, payload) => { /** * The Content-Type header can be spoofed so is not trusted implicitly, - * this checks the payload is a "vertical bar" encoded HL7 v2.x message + * this checks the payload is an HL7 v2.x message */ - if (!payload.startsWith("MSH|")) { + if (!payload.startsWith("MSH")) { throw server.httpErrors.unsupportedMediaType(); } diff --git a/src/routes/hl7v2/json/schema.js b/src/routes/hl7v2/json/schema.js index 1e315b594..60594f0c1 100644 --- a/src/routes/hl7v2/json/schema.js +++ b/src/routes/hl7v2/json/schema.js @@ -1,6 +1,6 @@ const S = require("fluent-json-schema"); -const tags = ["HL7v2"]; +const tags = ["HL7 v2.x"]; /** * Fastify uses AJV for JSON Schema Validation, @@ -11,11 +11,11 @@ const tags = ["HL7v2"]; */ const hl7v2ToJsonPostSchema = { tags, - summary: 'Convert "vertical bar" encoded HL7 v2.x message to JSON', + summary: "Convert HL7 v2.x message to JSON", description: - 'Returns the result of converting a "vertical bar" HL7 v2.x document to JSON format.', - operationId: "posthl7v2ToJson", - consumes: ["text/plain"], + "Returns the result of converting an HL7 v2.x message to JSON format.", + operationId: "postHl7v2ToJson", + consumes: ["text/hl7v2"], produces: ["application/json"], response: { 200: S.object().additionalProperties(true),