Skip to content

Commit

Permalink
fix: #11
Browse files Browse the repository at this point in the history
- Only check the type of first accept type
- If type is a value in the xml type list, change response type to xml,
instead of using `include` to determine whether to use xml
  • Loading branch information
Chinlinlee committed Feb 4, 2024
1 parent d8b5add commit ba2e2d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 11 additions & 2 deletions api/FHIRApiService/services/base.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ba2e2d8

Please sign in to comment.