Skip to content

Commit

Permalink
fix: xml is not working
Browse files Browse the repository at this point in the history
# 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`
  • Loading branch information
Chinlinlee committed Sep 5, 2023
1 parent 8445799 commit 1819305
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/FHIRApiService/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
12 changes: 10 additions & 2 deletions api/FHIRApiService/services/base.service.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1819305

Please sign in to comment.