In the rapidly evolving world of Generative AI (GenAI), efficiency and modularity are key. MedPromptJS is an npm package that provides a set of base classes to simplify GenAI application development, making it easier to build robust and scalable AI-powered applications.

III. MedPromptJS: Simplifying GenAI Application Development
Image credit: Martin Vorel, CC BY-SA 4.0 https://creativecommons.org/licenses/by-sa/4.0, via Wikimedia Commons

MedPromptJS is a TypeScript-based library designed to enhance AI workflows by introducing base classes for Chains, Agents, and Tools. These abstractions facilitate an organized approach to AI-driven tasks, ensuring flexibility and ease of development.

Chains help structure AI workflows by enabling the modular execution of tasks. Agents act as autonomous controllers that utilize Chains and Tools to execute complex AI tasks. They make dynamic decisions based on user inputs and system responses, ensuring adaptability in AI-driven interactions. Tools are specialized utilities that perform distinct functions within AI applications. They range from data transformation helpers to external API integrators, ensuring the AI system has access to the necessary capabilities to fulfill user queries.

Installing MedPromptJS is as simple as running:

npm i --save medpromptjs

Once installed, developers can leverage its structured components to build intuitive and scalable AI applications.

MedpromptJS package implements the LLM-in-the-Loop pattern for adding support for CQL concerning unstructured data elements. Current Clinical Query Language (CQL) execution engines are designed to handle structured data — such as standardized electronic health record (EHR) fields —making them ineffective at interpreting unstructured clinical notes, which often contain crucial patient information in free-text form. This limitation poses a challenge for healthcare providers who rely on nuanced data from clinical narratives to make informed decisions. Read more ..

To address this gap, we propose an innovative method that integrates LLMs into CQL execution engines, enabling them to process unstructured clinical text effectively. By leveraging the pattern-recognition capabilities of LLMs, this approach enhances the adaptability of CDS systems, allowing healthcare professionals to extract meaningful insights from free-text notes without manual review. The integration of LLMs ensures that unstructured data — such as physician notes, radiology reports, and discharge summaries — can be used alongside structured EHR data, providing a more comprehensive view of a patient’s medical history.

The MedpromptJS library provides an implementation of this method in three steps. The first step is to convert the CQL statement referring to an unstructured FHIR resource to its natural language representation using an LLM. In this step, we use in-context learning in the prompt. In the next step, the unstructured data source is split into chunks of appropriate size according to the context window size of the LLM. The LLM then maps the chunks into facts. In the third and final step, the LLM generates a yes/no answer for the natural language query from step 1 based on the facts from step 2. You can see the full implementation of the chain here:

Part IV describes how we added a hook pattern into the CQL execution engine that will be triggered when DocumentReference is encountered.

Bell Eapen
Follow Me