Skip to content

Commit

Permalink
Merge pull request #7 from mcode/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
smalho01 authored Sep 12, 2023
2 parents 706b2e8 + b782556 commit 7abfd4a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
16 changes: 12 additions & 4 deletions prefetch/PrefetchHydrator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hook, HookPrefetch } from '../resources/HookTypes';
import { Hook, HookPrefetch, TypedRequestBody } from '../resources/HookTypes';
import { ServicePrefetch } from '../resources/CdsService';
import { FhirResource } from 'fhir/r4';
function jsonPath(json: any, path: string) {
Expand Down Expand Up @@ -47,11 +47,19 @@ function replaceTokens(str: string, json: Hook): string {
// Return the modified string
return str;
}
function resolveToken(token: string, callback: (token: string) => Promise<any>, hook: Hook) {
function resolveToken(
token: string,
callback: (token: string, req: TypedRequestBody) => Promise<any>,
hook: Hook
) {
const fulfilledToken = replaceTokens(token, hook);
return callback(fulfilledToken);
return callback(fulfilledToken, { body: hook });
}
function hydrate(callback: (token: string) => Promise<any>, template: ServicePrefetch, hook: Hook) {
function hydrate(
callback: (token: string, req: TypedRequestBody) => Promise<any>,
template: ServicePrefetch,
hook: Hook
) {
// Generally the EHR should define the prefetch requests it will/won't
// fulfill, but in this case we can just attempt to fill everything
// we can.
Expand Down
29 changes: 26 additions & 3 deletions resources/HookTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Bundle, FhirResource, Patient, Practitioner } from 'fhir/r4';

export enum SupportedHooks {
ORDER_SIGN = 'order-sign'
ORDER_SIGN = 'order-sign',
ORDER_SELECT = 'order-select'
}

export interface FhirAuthorization {
Expand All @@ -13,7 +14,7 @@ export interface FhirAuthorization {
}

export interface HookContext {
[key: string]: string | Bundle | undefined;
[key: string]: string | string[] | Bundle | undefined;
}

export interface HookPrefetch {
Expand All @@ -24,6 +25,11 @@ export interface OrderSignPrefetch extends HookPrefetch {
practitioner?: Practitioner;
patient?: Patient;
}

export interface OrderSelectPrefetch extends HookPrefetch {
practitioner?: Practitioner;
patient?: Patient;
}
export interface Hook {
hook: SupportedHooks;
hookInstance: string;
Expand All @@ -40,13 +46,26 @@ export interface OrderSignContext extends HookContext {
encounterId?: string;
draftOrders: Bundle;
}

// https://cds-hooks.org/hooks/order-select/#context
export interface OrderSelectContext extends HookContext {
userId: string;
patientId: string;
encounterId?: string;
selections: string[];
draftOrders: Bundle;
}
// https://cds-hooks.hl7.org/1.0/#calling-a-cds-service
export interface OrderSignHook extends Hook {
hook: SupportedHooks.ORDER_SIGN;
context: OrderSignContext;
prefetch?: OrderSignPrefetch;
}

export interface OrderSelectHook extends Hook {
context: OrderSelectContext;
prefetch?: OrderSelectPrefetch;
}

export interface Coding {
/**
* The code for what is being represented
Expand Down Expand Up @@ -263,3 +282,7 @@ export interface Card {
*/
links?: Link[];
}

export interface TypedRequestBody extends Express.Request {
body: Hook;
}
35 changes: 35 additions & 0 deletions resources/OrderSelect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Bundle } from 'fhir/r4';
import CdsHook from './CdsHook';
import { OrderSelectContext, OrderSelectHook, SupportedHooks } from './HookTypes';

export default class OrderSelect extends CdsHook {
patientId: string;
userId: string;
draftOrders: Bundle;
selections: string[];

constructor(patientId: string, userId: string, draftOrders: Bundle, selections: string[]) {
super(SupportedHooks.ORDER_SIGN);
this.patientId = patientId;
this.userId = userId;
this.draftOrders = draftOrders;
this.selections = selections;
}

generate(): OrderSelectHook {
return {
hook: this.hookType,
hookInstance: this.hookInstance,
context: this.generateContext(),
prefetch: {}
};
}
generateContext(): OrderSelectContext {
return {
userId: this.userId,
patientId: this.patientId,
draftOrders: this.draftOrders,
selections: this.selections
};
}
}

0 comments on commit 7abfd4a

Please sign in to comment.