DEV Community

Paul Bradley
Paul Bradley

Posted on • Originally published at

Building a digital wingman to assist busy clinical staff

Building a digital wingman to assist busy clinical staff

I've been working on creating a "digital wingman" to assist busy clinical staff, by detecting if particular drugs have been missed off a discharge letter.

Sorry, the video doesn't have any voice over so this is what you're seeing:

  • An unstructured discharge letter is sent to AWS's Medical Comprehend AI
  • A list of medications, dosage and route information is detected within the text, along with forty items of interest. These include medical procedurals and diagnosis.
  • A visual model of the medical terms and their relationship with each other is then produced and displayed.
  • We then remove the drug that treats hypertension (high blood pressure) and rerun the program. As hypertension is mentioned within the clinical narrative the system then checks all possible drugs that could be prescribed to treat hypertension.
  • Not finding one, it then sends an alert to the caregiver for investigation.

AWS medical comprehend

The medical comprehend API is a recent offering from AWS which accepts unstructured medical text and returns a JSON object outlining all the medical, procedural and diagnosis terms found within the text. For medications, it also returns the dose, route and frequency if found within the text. For each medical term found a confidence score is returned to help you decided if you should trust the value. An offset position is also returned indicating the starting point for the medical term found.

Example using Go

The first step is to install the AWS software development kit (SDK) for Go. This is done by using the following Go get command issued at the terminal or command prompt.

go get
Enter fullscreen mode Exit fullscreen mode

Once the AWS SDK has been installed, you’ll then need to import the relevant sections into your program to be able to interact with the medical comprehend API.

package main

import (

Enter fullscreen mode Exit fullscreen mode

You’ll need to create an AWS session select a region which supports the medical comprehend API (not all do). In the example below the newly created session is assigned to the s variable. The session object is created by passing in the region identifier and your AWS credentials for id and secret key. Your id and secret key can be obtained from your AWS account.

func main() {

    // create an AWS session which can be
    // reused if we're uploading many files
    s, err := session.NewSession(&aws.Config{
        Region: aws.String("us-east-1"),
        Credentials: credentials.NewStaticCredentials(

    if err != nil {

    client := comprehendmedical.New(s)
    input  := comprehendmedical.DetectEntitiesInput{}

        Pt is 40yo mother, highschool teacher
        HPI   : Sleeping trouble on present dosage of Clonidine.
                Severe Rash  on face and leg, slightly itchy
        Meds  : Vyvanse 50 mgs po at breakfast daily,
                Clonidine 0.2 mgs -- 1 and 1 / 2 tabs po qhs
        HEENT : Boggy inferior turbinates, No oropharyngeal lesion
        Lungs : clear
        Heart : Regular rhythm
        Skin  : Mild erythematous eruption to hairline

    result, err := client.DetectEntities(&input)

    if err != nil {
Enter fullscreen mode Exit fullscreen mode

Start by defining a medical comprehend client using the New function passing in your AWS session variable s. Then define an input object and use the SetText function to define the medical text you want to process. The processing of the medical text is done when the DetectEntities function is called and the results are stored in the results variable.

To get the JSON string returned you can use the GoString function as shown below. This is useful if you want to store the JSON in a Postgres JSONB database field to perform search queries across many patients.

Enter fullscreen mode Exit fullscreen mode

You can loop over the detected terms and only print out the medications found by using the following pattern:

for _, entity := range result.Entities {
    if *entity.Category == "MEDICATION" {
Enter fullscreen mode Exit fullscreen mode

Which will output the following results:

Enter fullscreen mode Exit fullscreen mode


Other useful category names include:-


Top comments (0)