Cardclasses. We'll use these to create our decision support service and to describe our responses to inbound requests. We also import an helper class,
NoDecisionResponse, used to reply with a standard "no comment" response. We're also importing
Hooks- which are TypeScript declarations. Lastly, we import our helper method for the GoodRx API.
/cds-services. We define an options object that we will use in the construction of
Service. Importantly, we declare that the
Serviceexpects to respond to the
draftOrderskey will exist on
request.contextand that it will be shaped like a FHIR Bundle (we're using the
@types/fhirto annotate that here).
order-selecthook requires that a Bundle of FHIR Resources be provided at
draftOrders, but those resources could be
VisionPrescriptionin addition to the one we care about:
MedicationRequest. We filter the
MedicationRequestwas found, we throw a
NoDecisionResponsebecause we can only provide decision support when one is present. This thrown error is handled by Sero automatically, sending back response the CDS Hooks specification expects:
MedicationRequest, so let's use the text associated with the request (i.e. the "name" of the drug) to make a price comparison request to the GoodRx Compare Price API (here we have abstracted the API requirements into a small utility library). The utility uses
async/awaitbut we can also make use of
MedicationRequest. We create an return a
Cardcontaining a summary of the low/high price, the brand name, generic names, the cheapest pharmacy, and an associated coupon.
Dockerfileto build and run the project in isolation. Note that in order to actually successfully make requests to the Good RX Compare Price API you must set two environment variables
GOOD_RX_SECRET_KEYwhich only GoodRx can issue.