Skip to content

AI prompt pipeline implemented#2467

Open
idkcoder93 wants to merge 79 commits into
openo-beta:mainfrom
idkcoder93:main
Open

AI prompt pipeline implemented#2467
idkcoder93 wants to merge 79 commits into
openo-beta:mainfrom
idkcoder93:main

Conversation

@idkcoder93

@idkcoder93 idkcoder93 commented Jun 8, 2026

Copy link
Copy Markdown

This PR implements the OCR and data processing pipeline, including context windowing to improve LLM ingestion accuracy. It also adds an LLM endpoint for extracting patient data from processed documents.

Changes:

  • Implemented OCR pipeline for document text extraction.
  • Added data processing and normalization.
  • Introduced context windowing for improved LLM context handling.
  • Added patient data extraction endpoint.

Summary by cubic

Implements an OCR + PDF text caching pipeline with context windowing and a new /llm/export endpoint to return patient data for LLM processing. Adds an “AI Summary” link in Chart Notes to open the prompter for the current patient.

  • New Features

    • Caches extracted PDF text in llm_document_text keyed by SHA-256; bulk loads per patient.
    • REST endpoint /llm/export returns demographics, meds, allergies, measurements, labs, documents, and notes as JSON.
    • OCR/text extraction via PDFBox with context windowing to improve downstream LLM ingestion.
    • Validates Ocean eReferral attachments belong to the current patient across documents, labs, eForms, and HRM.
    • Adds an “AI Summary” button in Chart Notes to open the prompter for the current patient.
  • Migration

    • Run DB updates to create llm_document_text and add new codes:
      • NRTF measurement and diabetes flowsheet updates (OMD DE16.066).
      • OMA uninsured service fee codes for Ontario private billing (PC13.19).
    • No config changes required; LLMExtractorEndpoint is registered via Spring.

Written for commit c22f7fd. Summary will update on new commits.

Review in cubic

LiamStanziani and others added 30 commits March 18, 2026 11:58
…echanism that was only used to archive re-staged medications after re-editing
…th CSRF and POST fetch, update JSDoc to align with uncheckReRxForExistingPrescribedDrug parameters
…o searchDrug3.jsp, updated javadoc in delete action, added drugList null or empty check
  Unchecking a ReRx checkbox after staging failed to remove the UI card
  because removeDrugFromReRxList looked up the card by prescription ID
  (set_<prescriptIdInt>) but the card uses a randomId (set_<randomId>).
  Added data-drug-ref-id attribute to staged card fieldsets and updated
  the lookup to use querySelector with that attribute.
  Relabel existing FTLS field from Monofilament 10g to
  Neurological exam: 10g monofilament and add new NRTF
  measurement Neurological exam: 128Hz tuning fork D1 to
  all three diabetes flowsheets (diab, diab2, diab3) to meet
  OMD DE16.066 compliance.
…and initial test data to be replaced with the new data added into ctl_billingservice, archived if using migration file to avoid removing anything that uses the same values that are not test data
… resolution order, add eclipse ide files to gitignore file
…checking-and-forward-iteration-deletion-loop-medications

Fix: String object comparison and forward-iteration deletion in medication stash, missing GCN_SEQNO for drug search flow, and drug name encoding on input
…asses-wrong-id-unmasks-archival-bug

Fix: medication X button passes wrong ID and removed flawed archival mechanism that was only used to archive re-staged medications after re-editing
…checking-removes-only-server-side-stash-entry

Fix: resolve ghost card when unchecking ReRx checkbox after staging
…t-script-reload

fix: MDS queue doc count not updating after Save & Next
…-fork-measurement-diabetes-flowsheet

Fix: missing tuning fork measurement diabetes flowsheet
LiamStanziani and others added 20 commits April 15, 2026 15:02
…anged to be in ascending order instead of previous descending order)
…ate to match original behaviour instead of enetered date
… Date is unknown, to match the previous server side sorting behaviour
…age data changing the default sort order, since changes have not been added to prod, so this issue doesn't currently cause issues
…r-erase-selected-coimpletely-not-working

Fix: Tickler Manager - "Erase Selected Completely" button doesn't work
…tions-field-reference-rx-cannot-be-closed

Fix: The Instructions Field Reference popup in the Rx module cannot be closed
…rofile-view-legend-searchdrug3

fix: restore drug profile legend and filter tab functionality broken by DataTables upgrade
…each medication, and underlines on specifically singular medication reprints
…-no-longer-works

Fix: "Reprint" button in Rx module no longer works
…ion-list-rx-module-wrong-order

Fix: Medication list in rx module is sorted in the wrong order
…rendering-and-missing-labels

fix: restore <br> rendering and fix missing labels in RxPreview
…on and more, updated spring for api intiailization
merging changes from my branch
OCR and caching implemented, adjusted LLM endpoint to send data in json.
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @idkcoder93, your pull request is larger than the review limit of 150000 diff characters

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an AI-ready patient export feature, including a new REST endpoint (/llm/export), an extraction service (LLMExtractorService), and a two-layer caching mechanism (LlmDocumentTextService) for extracted PDF text. It also adds attachment validation for Ocean eReferrals, introduces the NRTF measurement type for diabetes flowsheet compliance, and refactors client-side drug profile filtering and Tickler restore actions. The review feedback highlights several robustness improvements, including converting a query parameter to a string to avoid type mismatches, adding defensive null checks for array parameters and note results, handling potential parsing exceptions for demographic numbers, and correcting a cache sentinel return value mismatch.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/main/java/ca/openosp/openo/commn/dao/DocumentDaoImpl.java Outdated
Comment thread src/main/java/ca/openosp/openo/managers/LlmDocumentTextService.java
Comment thread src/main/java/ca/openosp/openo/webserv/rest/LLMExtractorService.java Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues found across 56 files

Confidence score: 2/5

  • Multiple high-confidence, user-impacting issues are present (sev 6–7), including historical data misclassification in src/main/resources/oscar/oscarEncounter/oscarMeasurements/flowsheets/diabetesQueensFlowsheet.xml and invalid document payloads being accepted in src/main/java/ca/openosp/openo/documentManager/DocumentAttachmentManagerImpl.java, which makes this a high-risk merge.
  • src/main/webapp/js/custom/ocean/conreq.js uses synchronous AJAX (async: false), which can block the browser UI during attachment validation and cause hung referral workflows.
  • src/main/java/ca/openosp/openo/encounter/oceanEReferal/pageUtil/ERefer2Action.java can throw NumberFormatException for malformed demographicNo, and src/main/java/ca/openosp/openo/managers/LlmDocumentTextService.java returns "" instead of null on cache hits, creating request-failure and contract-consistency risks.
  • Pay close attention to src/main/resources/oscar/oscarEncounter/oscarMeasurements/flowsheets/diabetesQueensFlowsheet.xml, src/main/java/ca/openosp/openo/documentManager/DocumentAttachmentManagerImpl.java, src/main/webapp/js/custom/ocean/conreq.js, src/main/java/ca/openosp/openo/encounter/oceanEReferal/pageUtil/ERefer2Action.java, src/main/java/ca/openosp/openo/managers/LlmDocumentTextService.java - they contain the highest-impact correctness, validation, and UX stability risks.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/main/java/ca/openosp/openo/documentManager/DocumentAttachmentManagerImpl.java">

<violation number="1" location="src/main/java/ca/openosp/openo/documentManager/DocumentAttachmentManagerImpl.java:686">
P1: Malformed or unknown document tokens are silently skipped in validateDocumentsBelongToPatient, allowing invalid payloads to incorrectly return true.</violation>
</file>

<file name="src/main/webapp/js/custom/ocean/conreq.js">

<violation number="1" location="src/main/webapp/js/custom/ocean/conreq.js:41">
P1: Synchronous AJAX (`async: false`) blocks the UI thread during attachment validation, risking frozen/hung referral interactions.</violation>
</file>

<file name="src/main/java/ca/openosp/openo/encounter/oceanEReferal/pageUtil/ERefer2Action.java">

<violation number="1" location="src/main/java/ca/openosp/openo/encounter/oceanEReferal/pageUtil/ERefer2Action.java:126">
P2: Handle invalid `demographicNo` values before parsing; a malformed request can currently throw `NumberFormatException` and fail the request.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +686 to +690
switch (type) {
case 'D': docIds.add(id); break;
case 'L': labIds.add(id); break;
case 'E': eformIds.add(id); break;
case 'H': hrmIds.add(id); break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Malformed or unknown document tokens are silently skipped in validateDocumentsBelongToPatient, allowing invalid payloads to incorrectly return true.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main/java/ca/openosp/openo/documentManager/DocumentAttachmentManagerImpl.java, line 686:

<comment>Malformed or unknown document tokens are silently skipped in validateDocumentsBelongToPatient, allowing invalid payloads to incorrectly return true.</comment>

<file context>
@@ -663,4 +669,48 @@ public void flattenPDFFormFields(Path pdfPath) throws PDFGenerationException {
+            char type = doc.charAt(0);
+            try {
+                int id = Integer.parseInt(doc.substring(1));
+                switch (type) {
+                    case 'D': docIds.add(id); break;
+                    case 'L': labIds.add(id); break;
</file context>
Suggested change
switch (type) {
case 'D': docIds.add(id); break;
case 'L': labIds.add(id); break;
case 'E': eformIds.add(id); break;
case 'H': hrmIds.add(id); break;
switch (type) {
case 'D': docIds.add(id); break;
case 'L': labIds.add(id); break;
case 'E': eformIds.add(id); break;
case 'H': hrmIds.add(id); break;
default: return false;
}

let valid = false;
jQuery.ajax({
type: 'POST',
async: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Synchronous AJAX (async: false) blocks the UI thread during attachment validation, risking frozen/hung referral interactions.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main/webapp/js/custom/ocean/conreq.js, line 41:

<comment>Synchronous AJAX (`async: false`) blocks the UI thread during attachment validation, risking frozen/hung referral interactions.</comment>

<file context>
@@ -34,20 +34,38 @@ jQuery(document).ready(function () {
+    let valid = false;
+    jQuery.ajax({
+        type: 'POST',
+        async: false,
+        url: document.getElementById("contextPath").value + '/oscarEncounter/eRefer.do',
+        data: "demographicNo=" + demographicNo + "&method=validateDocuments&" + jQuery.param({documents: docs}, true),
</file context>

Comment thread src/main/java/ca/openosp/openo/managers/LlmDocumentTextService.java Outdated
Comment on lines +126 to +128
boolean valid = documentAttachmentManager.validateDocumentsBelongToPatient(
loggedInInfo, Integer.parseInt(demographicNo), documents);
writeResponse(valid);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Handle invalid demographicNo values before parsing; a malformed request can currently throw NumberFormatException and fail the request.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/main/java/ca/openosp/openo/encounter/oceanEReferal/pageUtil/ERefer2Action.java, line 126:

<comment>Handle invalid `demographicNo` values before parsing; a malformed request can currently throw `NumberFormatException` and fail the request.</comment>

<file context>
@@ -92,11 +94,40 @@ public String execute() {
+            writeResponse(true);
+            return;
+        }
+        boolean valid = documentAttachmentManager.validateDocumentsBelongToPatient(
+                loggedInInfo, Integer.parseInt(demographicNo), documents);
+        writeResponse(valid);
</file context>
Suggested change
boolean valid = documentAttachmentManager.validateDocumentsBelongToPatient(
loggedInInfo, Integer.parseInt(demographicNo), documents);
writeResponse(valid);
try {
int demoNo = Integer.parseInt(demographicNo);
boolean valid = documentAttachmentManager.validateDocumentsBelongToPatient(
loggedInInfo, demoNo, documents);
writeResponse(valid);
} catch (NumberFormatException e) {
writeResponse(false);
}

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: idkcoder93 <113472355+idkcoder93@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3fa8573f-9228-4c2c-a5f0-bca84afb075f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

idkcoder93 and others added 4 commits June 8, 2026 16:30
….java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: idkcoder93 <113472355+idkcoder93@users.noreply.github.com>
…e.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: idkcoder93 <113472355+idkcoder93@users.noreply.github.com>
added link to our AI prompter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants