Extracting Covid-19 Vaccination Records from the GP record

by Hadley Bradley

Covid-19 Vaccination Records

I’ve been investigating the possibility of automating the extraction of Covid-19 vaccination records for a cohort of patients. Having the vaccination record would help pharmacy departments plan and prepare treatment for these identified patients.

To achieve this I used the Patient Identifier Cross Referencing (PIX) profile of the regional Health Information Exchange to lookup a patients NHS numbers based on the supplied local hospital medical record number. Once I had the NHS number I could use Healthcare Gateway’s detailed care record API to retrieve the Medications HTML view.

Once I had the medications view, I needed to parse out the vaccination records from all the medications listed within the HTML tables returned. Usually, I wouldn’t attempt to parse information out of an HTML table. Fortunately, the HTML returned by the MIG has enough structure to parse out the information we needed. For example, the HTML returned contains CSS class names on the table cells, which allowed me to determine which cells had the date and which cells had the vaccination type.

I coded the server-side API in the open-source programming language, Go. I also used the goquery package to do the heavy lifting of parsing the HTML. goquery brought a syntax and a set of features similar to jQuery to the Go language and made it easy to achieve this task.

Parsing the Medications Records

The Go code below shows how the detailed care record response is passed into a new goquery document. It also demonstrates using goquery to iterate through each HTML table and each row within each table.

doc, err := goquery.NewDocumentFromReader(strings.NewReader(DCRV2Response))
if err != nil {
    fmt.Println("Error parsing supplied HTML")
    log.Fatal(err.Error())
}

// find each table within the HTML
doc.Find("table").Each(func(index int, tablehtml *goquery.Selection) {

    // loop over each row within the table
    tablehtml.Find("tr").Each(func(indextr int, rowhtml *goquery.Selection) {

    })
})

Next, I needed to make sure that I only processed rows which contained an actual Covid-19 vaccination record.

Dictionary of medicines and devices (dm+d)

The dm+d is a dictionary of descriptions and codes which represent medicines and devices in use across the NHS. The following dm+d AMP labels are used for the different vaccination types currently given within the United Kingdom:

So I encapsulated this into a function that would return true/false if the supplied record contained one of the dm+d labels:

func isVaccinationRecord(record string) bool {
    if strings.Contains(record, "COVID-19 mRNA (nucleoside modified) Vaccine Moderna") {
        return true
    }
    if strings.Contains(record, "COVID-19 Vaccine AstraZeneca") {
        return true
    }
    if strings.Contains(record, "COVID-19 mRNA Vaccine Pfizer-BioNTech") {
        return true
    }
    return false
}

Parsing the Vaccination Records

Here we’ve plugged the isVaccinationRecord() into the loop and only if true do we proceed to extract the date and vaccine given. From the code sample below, you can see that I’m using the existence of the CSS classes to determine which table cell holds the date. If the table cell has the CSS class name of onsetdate then we extract the table cell as a date. The CSS class name of term is used to extract the name of the vaccination given.

// find each table within the HTML
doc.Find("table").Each(func(index int, tablehtml *goquery.Selection) {
    tablehtml.Find("tr").Each(func(indextr int, rowhtml *goquery.Selection) {

        // only process rows which have
        // dm+d COVID-19 vaccine entries
        if isVaccinationRecord(rowhtml.Text()) {

            rowhtml.Find("td").Each(func(indexth int, tablecell *goquery.Selection) {
                if tablecell.HasClass("onsetdate") {
                    fmt.Println("Date Given: " + tablecell.Text())
                }

                if tablecell.HasClass("term") {
                    fmt.Println("Vaccine Given: " + tablecell.Text())
                }
            })
        }
    })
})

Need Help or Advice

If you need any help or advice in implementing something similar then please get in touch I’d be happy to help.