Wrapping a FHIR API Around a BERT Classification Model

FHIRFLYFHIRFLY
3 min read

In the world of healthcare and medicine, the ability to quickly and accurately classify queries as medical questions is an invaluable tool. As Natural Language Processing (NLP) and machine learning technology continue to develop, these tasks are becoming increasingly more attainable. This blog post will explain how to wrap a Fast Healthcare Interoperability Resources (FHIR) API around a BERT Classification model to answer the question, "Is this a medical question?"

To make this possible, we will be using FHIR Questionnaire and QuestionnaireResponse Resources, and the Bi-directional Encoder Representations from Transformers (BERT) Classification model. The FHIR standard allows for streamlined healthcare data exchange, while the BERT model, a transformer-based machine learning technique for NLP tasks, will provide us with the ability to effectively classify queries as medical questions.

The Questionnaire Resource

The FHIR Questionnaire resource defines metadata about a document, such as a structured set of questions intended to guide the collection of answers. Below is an example of the Questionnaire resource we will be using:

jsonCopy code{
    "id": "is-medical-question-questionnaire",
    "item": [
        {
            "answerOption": [
                {
                    "valueCoding": {
                        "code": "(0)",
                        "display": "This is not a medical question.",
                        "system": "http://fly.health/medicalquestions"
                    }
                },
                {
                    "valueCoding": {
                        "code": "(1)",
                        "display": "This is a medical question.",
                        "system": "http://fly.health/medicalquestions"
                    }
                }
            ],
            "linkId": "is-medical-question",
            "text": "Is this a medical question?",
            "type": "choice"
        },
        {
            "linkId": "user-question",
            "text": "What is your question?",
            "type": "string"
        }
    ],
    "name": "Medical Question Questionnaire",
    "resourceType": "Questionnaire",
    "status": "active",
    "title": "Medical Question Questionnaire"
}

This Questionnaire presents the user with two questions: "Is this a medical question?" and "What is your question?" and it provides two answer options for the first question: "This is not a medical question" and "This is a medical question."

The FHIR API

Our API is invoked by a POST request to /QuestionnaireResponse with the following payload in the body:

jsonCopy code{
    "resourceType": "QuestionnaireResponse",
    "questionnaire": "Questionnaire/is-medical-question-questionnaire",
    "status": "in-progress",
    "item": [
        {
            "linkId": "user-question",
            "text": "What is your question?",
            "answer": [
                {
                    "valueString": "Whats a good care plan for Diabetes?"
                }
            ]
        }
    ]
}

The payload includes the user's question and indicates that the status of the questionnaire is "in-progress".

Wrapping the BERT Model

Upon receiving a request, the API will invoke our BERT Classification model. This model will classify the question as a medical or non-medical question. The BERT model has been trained on a dataset of medical and non-medical questions, and it is highly accurate at distinguishing between the two types.

The API Response

Once the BERT model has made its classification, the API will return a 201 Created response, along with the FHIR QuestionnaireResponse. This will look something like this:

jsonCopy code{
    "meta": {
        "profile": [
            "http://hl7.org/fhir/us/core/StructureDefinition/us-core-questionnaireresponse"
        ]
    },
    "resourceType": "QuestionnaireResponse",
    "questionnaire": "Questionnaire/is-medical-question-questionnaire",
    "status": "completed",
    "subject": {
        "reference": "Patient/Unknown",
        "display": "Unknown"
    },
    "item": [
        {
            "linkId": "user-question",
            "text": "What is your question?",
            "answer": [
                {
                    "valueString": "Whats a good care plan for Diabetes?"
                }
            ]
        },
        {
            "linkId": "is-medical-question",
            "text": "Is this a medical question?",
            "answer": [
                {
                    "valueCoding": {
                        "system": "http://fly.health/medicalanswers/answer-codes",
                        "code": 1,
                        "display": "This is a medical question."
                    }
                }
            ]
        }
    ]
}

The returned QuestionnaireResponse confirms the user's question and provides the answer to "Is this a medical question?".

Conclusion

By wrapping a FHIR API around a BERT Classification model, we can utilize the power of machine learning and the interoperability of FHIR to accurately classify queries as medical questions. This system could have numerous applications in healthcare, from triaging patient questions to aiding research tasks. It demonstrates the exciting possibilities that emerge when we combine advanced NLP techniques with healthcare-focused data standards.

0
Subscribe to my newsletter

Read articles from FHIRFLY directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

FHIRFLY
FHIRFLY

Hello, I'm Richard Braman, aka FHIRFLY, a dedicated healthcare professional deeply passionate about leveraging modern technology to improve patient outcomes and streamline healthcare operations. I'm fascinated by the interplay of healthcare, Fast Healthcare Interoperability Resources (FHIR), and machine learning, and I continually explore how these fields intersect to transform the health landscape. Over the years, I have gained in-depth expertise in FHIR, a game-changing framework designed to enhance data interoperability in healthcare. My passion for this versatile standard stems from its profound potential to simplify health data exchange and provide a seamless healthcare experience for patients and providers alike. My interest extends beyond data exchange standards to the broader field of healthcare. I am committed to understanding the intricacies of patient care, hospital management, and medical ethics. This holistic understanding of the health ecosystem guides my approach to integrating technology into healthcare, always with a focus on enhancing patient care and ensuring ethical practices. As an enthusiast of machine learning and AI, I am constantly amazed at their potential to revolutionize healthcare. From predictive analytics in patient care to intelligent automation in hospital operations, I believe these technologies hold the key to a new era of healthcare delivery. But above all, I see myself as a lifelong learner. I am always on the lookout for new developments and breakthroughs in these areas. I believe that continuous learning and innovation are crucial to navigating the evolving landscape of healthcare technology. In my blog, you will find articles that reflect my passion for these subjects and my efforts to promote the transformative potential of FHIR, healthcare, and machine learning. Join me as we explore the future of healthcare together.