Skip to content

Commit

Permalink
fix: fullUrl of history not complete
Browse files Browse the repository at this point in the history
- Add postfix `_history/${versionId}` for history bundle
- Use request properties to combine full url
  • Loading branch information
Chinlinlee committed Nov 21, 2022
1 parent 6d0da73 commit 519e1d6
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions models/FHIR/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ function getPreviousUrl(params, http = "http", resource) {
return baseUrl;
}

function getEntryFullUrl(item, http = "http", resource) {
let url = `${http}://${process.env.FHIRSERVER_HOST}:${process.env.FHIRSERVER_PORT}/${process.env.FHIRSERVER_APIPATH}/${resource}/${item.id}`;
return url;
/**
*
* @param {Object} item
* @param {import("express").Request} req
* @param {String} resourceType
* @param {String} type
* @returns
*/
function getEntryFullUrl(item, req, resourceType, type="searchset") {
let host = req.headers.host ? req.headers.host : `${process.env.FHIRSERVER_HOST}:${process.env.FHIRSERVER_PORT}`;
if (type === "history") {
return `${req.protocol}://${host}/${process.env.FHIRSERVER_APIPATH}/${resourceType}/${item.id}/_history/${item.meta.versionId}`;
} else {
return `${req.protocol}://${host}/${process.env.FHIRSERVER_APIPATH}/${resourceType}/${item.id}`;
}
}

/**
Expand Down Expand Up @@ -107,14 +119,14 @@ function createBundle(req, docs, count, skip, limit, resource, option) {
let responseObj = _.cloneDeep(docs[i].response);
delete docs[i].request;
delete docs[i].response;
let entry = new bundleClass.entry(getEntryFullUrl(docs[i], req.protocol, docs[i].resourceType), docs[i]);
let entry = new bundleClass.entry(getEntryFullUrl(docs[i], req, docs[i].resourceType, "history"), docs[i]);
entry.request = requestObj;
entry.response = responseObj;
bundle.entry.push(entry);
}
} else {
for (let i in docs) {
let entry = new bundleClass.entry(getEntryFullUrl(docs[i], req.protocol, docs[i].resourceType), docs[i]);
let entry = new bundleClass.entry(getEntryFullUrl(docs[i], req, docs[i].resourceType), docs[i]);
_.set(entry, "search.mode", "match");
if (_.get(docs[i], "myPointToCheckIsInclude")) {
delete docs[i]["myPointToCheckIsInclude"];
Expand Down

0 comments on commit 519e1d6

Please sign in to comment.