Skip to content

Commit

Permalink
rely on fhirBase rom the original request instead of the fullUrl link…
Browse files Browse the repository at this point in the history
… in the bundle entries which is an optional attribute.
  • Loading branch information
mojitoj committed Apr 9, 2024
1 parent 6ed39c1 commit 183cfe7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
13 changes: 9 additions & 4 deletions lib/consent-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ async function fetchConsents(patientIdentifiers, category) {
);

const consentSearchResults = await Promise.all(consentSearchQueries);

const resolvedConsents = consentSearchResults
.filter(({ body }) => body.entry.length)
.map(({ body }) => body.entry)
.map(({ body }, index) => ({
...body,
entry: body.entry.map((entry) => ({
...entry,
fhirBase: patientFhirIds[index].fhirBase
}))
}))
.filter((bundle) => bundle?.entry?.length)
.map((bundle) => bundle.entry)
.flat();

return resolvedConsents;
} catch (e) {
logger.warn(e);
Expand Down
12 changes: 8 additions & 4 deletions lib/consent-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function consentDecision(entry, query) {
const baseDecision = defaultDecision(consent);

const provisionsDecisionPromises = provisions(consent).map((provision) =>
processProvision(provision, query, entry.fullUrl, baseDecision)
processProvision(provision, query, entry.fhirBase, baseDecision)
);

try {
Expand All @@ -158,22 +158,26 @@ async function consentDecision(entry, query) {

const adjustedDecision = adjustDecision(query, decision, obligations);

const fullUrl = `${entry.fhirBase}/Consent/${consent?.id}`;

return {
...adjustedDecision,
dateTime: date(consent),
fullId: entry.fullUrl,
fullId: fullUrl,
id: `Consent/${consent?.id}`,
patientId: patient(consent)
};
} catch (e) {
console.log(e);
logger.warn(`invalid consent: ${entry.fullUrl} ${e}`);
logger.warn(
`invalid consent: ${fullUrl} ${e}`
);

return {
decision: NO_CONSENT,
obligations: [],
dateTime: date(consent),
id: entry.fullUrl
id: fullUrl
};
}
}
Expand Down
10 changes: 3 additions & 7 deletions lib/consent-provisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function matchPurposeOfUse(provision, query) {
async function fetchActor(actorReference, fhirBase) {
return maybeAddAuth(
superagent
.get(`${fhirBase}${actorReference}`)
.get(`${fhirBase}/${actorReference}`)
.set({ Accept: "application/json, application/fhir+json" })
);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ function matchClass(provision, query) {
async function processProvision(
provision,
query,
fullUrl,
fhirBase,
overarchingDecision
) {
if (!provision) {
Expand All @@ -98,7 +98,7 @@ async function processProvision(
const matchedActor = await matchActor(
provision,
query,
fhirBaseFromConsentUrl(fullUrl)
fhirBase
);

const matchedClass = matchClass(provision, query);
Expand Down Expand Up @@ -139,10 +139,6 @@ function determineObligations(query, decision, provision) {
return allCodes.length && obligation ? [obligation] : [];
}

function fhirBaseFromConsentUrl(fullUrl) {
return !fullUrl ? "" : fullUrl.substring(0, fullUrl.indexOf("Consent"));
}

module.exports = {
processProvision,
matchPurposeOfUse
Expand Down

0 comments on commit 183cfe7

Please sign in to comment.