Skip to content
Merged

Dev #134

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ a) `REACT_APP_LAUNCH_URL=http://example.com PORT=6000 npm start` or b) by specif

Following are a list of modifiable paths:

| URI Name | Default |
| --------------- | ------------------------------------------ |
| AUTH_SERVER_URI | `http://localhost:8090` |
| HTTPS_CERT_PATH | `server.cert` |
| HTTPS_KEY_PATH | `server.key` |
| LOGGING_LEVEL | `debug` |
| MONGO_DB_NAME | `remsadmin` |
| MONGO_URL | `mongodb://rems-user:pass@127.0.0.1:27017` |
| PORT | `8090` |
| RESOURCE_SERVER | `http://localhost:8090` |
| SMART_ENDPOINT | `http://localhost:4040/launch` |
| USE_HTTPS | `false` |
| VSAC_API_KEY | `changeMe` |
| WHITELIST | `http://localhost, http://localhost:3005` |
| URI Name | Default | Description |
| --------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------|
| AUTH_SERVER_URI | `http://localhost:8090` | The base url of the auth server, currently set to the base url of this app. |
| HTTPS_CERT_PATH | `server.cert` | Path to a certificate for encryption, allowing HTTPS. Unnecessary if using HTTP. |
| HTTPS_KEY_PATH | `server.key` | Path to a key for encryption, allowing HTTPS. Unnecessary if using HTTP. |
| LOGGING_LEVEL | `debug` | Amount to output in the log, can be changed to verbose, info, warn, or error. |
| MONGO_DB_NAME | `remsadmin` | Name of the database table being used. Should be changed if not using the Mongo instructions below. |
| MONGO_URL | `mongodb://rems-user:pass@127.0.0.1:27017` | URL for the connection to the database, should be changed if not using the Mongo instructions below. |
| PORT | `8090` | Port that this server should run on, change if there are conflicts with port usage. |
| RESOURCE_SERVER | `http://localhost:8090` | Base URL of this server, should match with port. |
| SMART_ENDPOINT | `http://localhost:4040/launch` | Launch URL of associated SMART app, should be changed if not using the REMS Smart App. |
| USE_HTTPS | `false` | Change to true to enable HTTPS. Ensure that HTTPS_CERT_PATH and HTTPS_KEY_PATH are valid. |
| VSAC_API_KEY | `changeMe` | Replace with VSAC API key for pulling down ValueSets. Request an API Key from the [VSAC website](https://vsac.nlm.nih.gov/) |
| WHITELIST | `http://localhost, http://localhost:3005` | List of valid URLs for CORS. Should include any URLs the server accesses for resources. |

## Running the Mongo DB instance

Expand Down
4 changes: 2 additions & 2 deletions src/cards/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ interface Source {
url: URL;
icon?: URL;
}
interface Action {
export interface Action {
type: string;
description: string;
resource?: Resource | string;
}
interface Suggestion {
export interface Suggestion {
label: string;
uuid?: string;
actions: Action[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
},
{
"linkId": "6.11",
"text": "10. I will not give blood while taking isotretinoin or for 1 moth after I stop taking isotretinoin. I understand that if someone who is pregnant gets my donated blood, their baby may be exposed to isotretinoin and may be born with serious birth defects.",
"text": "10. I will not give blood while taking isotretinoin or for 1 month after I stop taking isotretinoin. I understand that if someone who is pregnant gets my donated blood, their baby may be exposed to isotretinoin and may be born with serious birth defects.",
"type": "boolean",
"required": true
},
Expand Down
99 changes: 95 additions & 4 deletions src/hooks/hookResources.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { MedicationRequest, Coding, FhirResource, Identifier } from 'fhir/r4';
import Card, { Link } from '../cards/Card';
import {
MedicationRequest,
Coding,
FhirResource,
Identifier,
Task,
Questionnaire,
Patient
} from 'fhir/r4';
import Card, { Link, Suggestion, Action } from '../cards/Card';
import {
HookPrefetch,
OrderSignPrefetch,
Expand All @@ -17,6 +25,16 @@ type HandleCallback = (
contextRequest: FhirResource | undefined,
patient: FhirResource | undefined
) => Promise<void>;

interface Requirement {
name: string;
description: string;
stakeholderType: string;
createNewCase: boolean;
resourceId: string;
requiredToDispense: boolean;
appContext?: string;
}
export interface CardRule {
links: Link[];
summary?: string;
Expand Down Expand Up @@ -364,6 +382,9 @@ export async function handleCardOrder(
card.addLink(
createSmartLink(requirement.name, requirement.appContext, contextRequest)
);
if (patient && patient.resourceType === 'Patient') {
createQuestionnaireSuggestion(card, requirement, patient);
}
smartLinkCount++;
}
}
Expand All @@ -372,6 +393,9 @@ export async function handleCardOrder(
card.addLink(
createSmartLink(requirement.name, requirement.appContext, contextRequest)
);
if (patient && patient.resourceType === 'Patient') {
createQuestionnaireSuggestion(card, requirement, patient);
}
smartLinkCount++;
}
} else {
Expand All @@ -380,6 +404,9 @@ export async function handleCardOrder(
card.addLink(
createSmartLink(requirement.name, requirement.appContext, contextRequest)
);
if (patient && patient.resourceType === 'Patient') {
createQuestionnaireSuggestion(card, requirement, patient);
}
smartLinkCount++;
}
}
Expand Down Expand Up @@ -421,14 +448,14 @@ export async function handleCard(
// verify ids
if (
patient?.id &&
patient.id.replace('Patient/', '') !== context.patientId.replace('Patient/', '')
patient.id.replace('Patient/', '') !== context.patientId?.replace('Patient/', '')
) {
res.json(buildErrorCard('Context patientId does not match prefetch Patient ID'));
return;
}
if (
practitioner?.id &&
practitioner.id.replace('Practitioner/', '') !== context.userId.replace('Practitioner/', '')
practitioner.id.replace('Practitioner/', '') !== context.userId?.replace('Practitioner/', '')
) {
res.json(buildErrorCard('Context userId does not match prefetch Practitioner ID'));
return;
Expand Down Expand Up @@ -463,3 +490,67 @@ export function handleHook(
res.json(buildErrorCard('Unknown Error'));
}
}

export function createQuestionnaireSuggestion(
card: Card,
requirement: Requirement,
patient: Patient
) {
if (requirement.appContext && requirement.appContext.includes('=')) {
const qArr = requirement.appContext.split('='); // break up into parts
let qUrl = null;
for (let i = 0; i < qArr.length; i++) {
if (qArr[i].toLowerCase() === 'questionnaire') {
if (i + 1 < qArr.length) {
// not at end of array
qUrl = qArr[i + 1];
}
}
}
if (qUrl) {
const action: Action = {
type: 'create',
description: `Create task for "completion of ${requirement.name} Questionnaire`,
resource: createQuestionnaireCompletionTask(requirement.name, qUrl, patient)
};
const suggestion: Suggestion = {
label: `Add "Completion of ${requirement.name} Questionnaire" to task list`,
actions: [action]
};
card.addSuggestion(suggestion);
}
}
}
export function createQuestionnaireCompletionTask(
questionnaireTitle: string,
questionnaireUrl: string,
patient: Patient
) {
const taskResource: Task = {
resourceType: 'Task',
status: 'ready',
intent: 'order',
code: {
coding: [
{
system: 'http://hl7.org/fhir/uv/sdc/CodeSystem/temp',
code: 'complete-questionnaire'
}
]
},
description: `Complete ${questionnaireTitle} Questionnaire`,
for: {
reference: `${patient.resourceType}/${patient.id}`
},
authoredOn: `${new Date(Date.now()).toISOString()}`,
input: [
{
type: {
text: 'questionnaire'
},
valueCanonical: `${questionnaireUrl}`
}
]
};
return taskResource;
}
2 changes: 1 addition & 1 deletion src/rems-cds-hooks