From 183cfe78518437315bf97f3441142bbe3b2b10c9 Mon Sep 17 00:00:00 2001 From: Mohammad Jafari Date: Mon, 8 Apr 2024 17:55:28 -0700 Subject: [PATCH] rely on fhirBase rom the original request instead of the fullUrl link in the bundle entries which is an optional attribute. --- lib/consent-discovery.js | 13 +++++++++---- lib/consent-processor.js | 12 ++++++++---- lib/consent-provisions.js | 10 +++------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/consent-discovery.js b/lib/consent-discovery.js index d6b0b75..1e4faa0 100644 --- a/lib/consent-discovery.js +++ b/lib/consent-discovery.js @@ -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); diff --git a/lib/consent-processor.js b/lib/consent-processor.js index c2a88fb..4e18e34 100644 --- a/lib/consent-processor.js +++ b/lib/consent-processor.js @@ -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 { @@ -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 }; } } diff --git a/lib/consent-provisions.js b/lib/consent-provisions.js index 84df57a..7cd66d1 100644 --- a/lib/consent-provisions.js +++ b/lib/consent-provisions.js @@ -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" }) ); } @@ -85,7 +85,7 @@ function matchClass(provision, query) { async function processProvision( provision, query, - fullUrl, + fhirBase, overarchingDecision ) { if (!provision) { @@ -98,7 +98,7 @@ async function processProvision( const matchedActor = await matchActor( provision, query, - fhirBaseFromConsentUrl(fullUrl) + fhirBase ); const matchedClass = matchClass(provision, query); @@ -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