diff --git a/api/FHIRApiService/services/base.service.js b/api/FHIRApiService/services/base.service.js index 120bdcd5..083feb32 100644 --- a/api/FHIRApiService/services/base.service.js +++ b/api/FHIRApiService/services/base.service.js @@ -88,8 +88,17 @@ class BaseFhirApiService { item = handleError.processing(item); } - if ((this.response.getHeader("content-type").includes("xml") || - this.request.get("accept").includes("xml")) || + const xmlContentTypes = [ + "application/fhir+xml", + "application/xml", + "xml" + ]; + let firstAcceptType = this.request.headers.accept.split(",").pop(); + + if (( + this.response.getHeader("content-type").includes("xml") || + xmlContentTypes.includes(firstAcceptType) + ) || this.response.locals?._format?.toLowerCase() === "xml" ) { let fhir = new FHIR(); diff --git a/routes.js b/routes.js index b1c32219..eff86de5 100644 --- a/routes.js +++ b/routes.js @@ -85,14 +85,11 @@ module.exports = function (app) { "application/fhir+xml", "xml" ]; - - for(let i = 0 ; i< xmlAcceptList.length ; i++) { - let xmlAccept = xmlAcceptList[i]; - if (req.headers.accept.includes(xmlAccept)) { - res.set("Content-Type", "application/fhir+xml"); - } else { - res.set("Content-Type", "application/fhir+json"); - } + let firstAcceptType = req.headers.accept.split(",").pop(); + if (xmlAcceptList.includes(firstAcceptType)) { + res.set("Content-Type", "application/fhir+xml"); + } else { + res.set("Content-Type", "application/fhir+json"); } setFormatWhenQuery(req, res);