Skip to content

Commit

Permalink
Merge pull request #149 from sdhealthconnect/fix/issues-with-tests
Browse files Browse the repository at this point in the history
Fix/issues with tests
  • Loading branch information
mojitoj authored Apr 27, 2024
2 parents 6c626fd + 44170fb commit 1659037
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 52 deletions.
17 changes: 12 additions & 5 deletions lib/consent-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const CONSENT_FHIR_SERVERS = (process.env.CONSENT_FHIR_SERVERS || "")
.split(",")
.map((res) => res.trim());

const addFhirBaseToEntry = (entry, url) => ({
...entry,
fhirBase: url
});

const addFhirBaseToEntries = (entries, url) =>
entries.map((entry) => addFhirBaseToEntry(entry, url));

async function fetchConsents(patientIdentifiers, category) {
try {
const patientFhirIds = await patientIds(patientIdentifiers);
Expand All @@ -17,18 +25,17 @@ async function fetchConsents(patientIdentifiers, category) {

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

return resolvedConsents;
} catch (e) {
console.log(e);
logger.warn(e);
throw {
httpCode: 503,
Expand Down
7 changes: 3 additions & 4 deletions lib/consent-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ function provisions(consent) {

async function consentDecision(entry, query) {
const consent = entry?.resource;
const fullUrl = `${entry.fhirBase}/Consent/${consent?.id}`;

const baseDecision = defaultDecision(consent);

const provisionsDecisionPromises = provisions(consent).map((provision) =>
Expand All @@ -158,7 +160,6 @@ async function consentDecision(entry, query) {

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

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

return {
...adjustedDecision,
Expand All @@ -169,9 +170,7 @@ async function consentDecision(entry, query) {
};
} catch (e) {
console.log(e);
logger.warn(
`invalid consent: ${fullUrl} ${e}`
);
logger.warn(`invalid consent: ${fullUrl} ${e}`);

return {
decision: NO_CONSENT,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"nodemon": "^3.1.0",
"precise-commits": "^1.0.2",
"prettier": "^3.2.5",
"supertest": "^6.3.4"
"supertest": "^7.0.0"
},
"dependencies": {
"ajv": "^8.12.0",
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/consents/r5/consent-boris-provision-array.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
]
},
{
"type": "deny",
"securityLabel": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-Confidentiality",
Expand All @@ -109,7 +108,6 @@
]
},
{
"type": "deny",
"purpose": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-ActReason",
Expand Down
22 changes: 22 additions & 0 deletions test/lib/consent-processor-r4.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ it("active optin consent", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT
}
Expand Down Expand Up @@ -113,6 +114,7 @@ it("active optin consent with no scope in query", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT
}
Expand All @@ -139,6 +141,7 @@ it("active optin consent with scope stored in category[0]", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT
}
Expand All @@ -165,6 +168,7 @@ it("active but expired optin consent", async () => {
let decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: EXPIRED_PRIVACY_CONSENT
}
Expand All @@ -190,6 +194,7 @@ it("active but not yet valid optin consent", async () => {
decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: NOT_YET_VALID_PRIVACY_CONSENT
}
Expand Down Expand Up @@ -217,6 +222,7 @@ it("active optin consent with blacklisted recipient actor", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT
}
Expand Down Expand Up @@ -258,6 +264,7 @@ it("active optin consent with blacklisted recipient actor based on one of the mu
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT
}
Expand Down Expand Up @@ -302,6 +309,7 @@ it("active optin consent with blacklisted recipient actor of type practitioner",
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: CONSENT_DENY_PRACTITIONER
}
Expand Down Expand Up @@ -344,6 +352,7 @@ it("active optin consent with blacklisted purpose of use", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: CONSENT_WITH_POU_PROVISION
}
Expand Down Expand Up @@ -384,6 +393,7 @@ it("active optin consent with security label provision", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_SEC_LABEL_PROVISION
}
Expand Down Expand Up @@ -434,6 +444,7 @@ it("active optin consent with multiple security label provision", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_MULTIPLE_SEC_LABEL_PROVISION
}
Expand Down Expand Up @@ -498,6 +509,7 @@ it("active optin consent with array of security label provisions", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_PROVISION_ARRAY
}
Expand Down Expand Up @@ -562,6 +574,7 @@ it("active optin consent with security label and content class provisions", asyn
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_CONTENT_CLASS_PROVISION
}
Expand Down Expand Up @@ -626,6 +639,7 @@ it("active optin consent with content class provisions and sec label with reques
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource:
ACTIVE_PRIVACY_CONSENT_WITH_CONTENT_CLASS_PROVISION_AND_SEC_LABEL
Expand Down Expand Up @@ -693,6 +707,7 @@ it("active optin consent with content class provisions with request including a
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_CONTENT_CLASS_PROVISION
}
Expand Down Expand Up @@ -740,6 +755,7 @@ it("active optin consent with clinical code provisions", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_CLINICAL_CODE_PROVISION
}
Expand Down Expand Up @@ -797,6 +813,7 @@ it("active optin consent with array of provisions", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_PROVISION_ARRAY
}
Expand Down Expand Up @@ -827,6 +844,7 @@ it("active optin consent with purpose in root provision not matching the request
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_POU_IN_ROOT_ROVISION
}
Expand Down Expand Up @@ -857,6 +875,7 @@ it("active optin consent with purpose in root provision matching the request pur
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_POU_IN_ROOT_ROVISION
}
Expand Down Expand Up @@ -887,6 +906,7 @@ it("active optin consent with array of provisions matching some of the request p
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_PRIVACY_CONSENT_WITH_POU_IN_ROOT_ROVISION
}
Expand Down Expand Up @@ -923,6 +943,7 @@ it("no active optin consent", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: INACTIVE_PRIVACY_CONSENT
}
Expand All @@ -949,6 +970,7 @@ it("active optin consent with different scope", async () => {
const decision = await processDecision(
[
{
fhirBase: CONSENT_FHIR_SERVERS[0],
fullUrl: `${CONSENT_FHIR_SERVERS[0]}/Consent/1`,
resource: ACTIVE_RESEARCH_CONSENT
}
Expand Down
Loading

0 comments on commit 1659037

Please sign in to comment.