Skip to content

llmEngine draft version (proof of concept) #13

Open
prabinrs wants to merge 10 commits into
i2b2:ml-deployfrom
prabinrs:prabin
Open

llmEngine draft version (proof of concept) #13
prabinrs wants to merge 10 commits into
i2b2:ml-deployfrom
prabinrs:prabin

Conversation

@prabinrs

Copy link
Copy Markdown

Added LLM engine

  • get notes from observation_facts()
  • call external llm openAI API compliant and check for the presence of given term
  • add the terms as observatuion_facts()

Files changes :

  • llmEngine
  • llmHelper
  • llmAPI
  • i2b2_cdi_app
  • test files
  • test_llm_api
  • Test_llm_engine

tested on the mock dataset

SET search_path = i2b2demodata;

-- 1. Add the patient
INSERT INTO patient_dimension (patient_num, sex_cd, age_in_years_num, sourcesystem_cd)
VALUES (99001, 'M', 45, 'TEST_LLM')
ON CONFLICT DO NOTHING;

-- 2. Add a patient_mapping entry (required for the fact loader)
INSERT INTO patient_mapping (patient_ide, patient_ide_source, patient_num, patient_ide_status, project_id, sourcesystem_cd)
VALUES ('99001', 'TEST_LLM', 99001, 'A', 'demo', 'TEST_LLM')
ON CONFLICT DO NOTHING;

-- 3. Add the note concept
INSERT INTO concept_dimension (concept_path, concept_cd, name_char, sourcesystem_cd)
VALUES ('/i2b2/Notes/ClinicalNotes/', 'NOTE:CLINICAL', 'Clinical Notes', 'TEST_LLM')
ON CONFLICT DO NOTHING;

-- 4. Add the output concept (parent only; child codes are auto-created by llmEngine)
INSERT INTO concept_dimension (concept_path, concept_cd, name_char, sourcesystem_cd)
VALUES ('/i2b2/LLM/NLP/Extract/', 'LLM:NLP:FOUND', 'LLM NLP Extraction', 'TEST_LLM')
ON CONFLICT DO NOTHING;

-- 5. Insert the clinical note as a fact
INSERT INTO observation_fact
    (encounter_num, patient_num, concept_cd, provider_id, start_date,
     modifier_cd, instance_num, observation_blob, sourcesystem_cd)
VALUES
    (1, 99001, 'NOTE:CLINICAL', '@', '2024-01-01 00:00:00',
     '@', 1,
     'Patient is a 45-year-old male with type 2 diabetes. Currently on metformin 500mg twice daily. Last HbA1c was 7.2%.',
     'TEST_LLM')
ON CONFLICT DO NOTHING;

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.

2 participants