From 18193053e3cf3fb3e0bfdb39b62b8d16ff8a097c Mon Sep 17 00:00:00 2001 From: chin Date: Tue, 5 Sep 2023 20:13:03 +0800 Subject: [PATCH] fix: xml is not working # Problems - Fhir package is updated, but code incorrect - Cause XML conversation raise error # Solutions - Change correct name for FHIR package - Default use item to convert to xml in `doResponse` --- api/FHIRApiService/read.js | 2 +- api/FHIRApiService/services/base.service.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/FHIRApiService/read.js b/api/FHIRApiService/read.js index ce052cd1..a56d8297 100644 --- a/api/FHIRApiService/read.js +++ b/api/FHIRApiService/read.js @@ -13,5 +13,5 @@ module.exports = async function (req, res, resourceType) { return readService.doFailureResponse(result, code); } - return readService.doSuccessResponse(result); + return readService.doSuccessResponse(result._doc); }; diff --git a/api/FHIRApiService/services/base.service.js b/api/FHIRApiService/services/base.service.js index 7344838f..5d1b8062 100644 --- a/api/FHIRApiService/services/base.service.js +++ b/api/FHIRApiService/services/base.service.js @@ -1,5 +1,5 @@ const mongoose = require("mongoose"); -const FHIR = require("fhir").FHIR; +const FHIR = require("fhir").Fhir; const _ = require("lodash"); const uuid = require('uuid'); @@ -15,8 +15,11 @@ const { logger } = require("@root/utils/log"); class BaseFhirApiService { constructor(req, res, resourceType) { + /** @type { import("express").Request } */ this.request = req; + /** @type { import("express").Response } */ this.response = res; + /** @type { string } */ this.resourceType = resourceType; } @@ -69,9 +72,14 @@ class BaseFhirApiService { } doResponse(code, item) { + let responseResourceType = _.get(item, "resourceType"); + if (!responseResourceType) { + item = handleError.processing(item); + } + if (this.response.getHeader("content-type").includes("xml")) { let fhir = new FHIR(); - let xmlItem = fhir.objToXml(item._doc); + let xmlItem = fhir.objToXml(item); return this.response.status(code).send(xmlItem); } return this.response.status(code).send(item);