|
1 | 1 | import React, { useState, useRef, useCallback } from "react"; |
2 | 2 | import { appClient } from "@/api/appClient"; |
3 | | -import { useMutation, useQueryClient } from "@tanstack/react-query"; |
| 3 | +import { useQueryClient } from "@tanstack/react-query"; |
4 | 4 | import { |
5 | 5 | Dialog, |
6 | 6 | DialogContent, |
@@ -29,44 +29,7 @@ import { |
29 | 29 | } from "lucide-react"; |
30 | 30 | import { parseFile, ACCEPTED_FILE_TYPES, FILE_TYPE_LABELS, extractRulesFromStructuredData, extractRulesFromText } from "@/lib/fileParser"; |
31 | 31 |
|
32 | | -const EXTRACTION_PROMPT = `You are an expert medical triage data extraction AI. Your task is to analyze a document containing transplant hospital criteria, paging rules, and triage protocols, then extract structured rules from it. |
33 | | -
|
34 | | -DOCUMENT CONTENT: |
35 | | -{DOCUMENT_TEXT} |
36 | | -
|
37 | | -INSTRUCTIONS: |
38 | | -1. Carefully read the entire document content above |
39 | | -2. Identify ALL triage rules, paging criteria, alert thresholds, escalation paths, and contact routing instructions |
40 | | -3. For each rule found, extract the structured fields listed below |
41 | | -4. If a field is not explicitly stated, infer it from context or mark it as empty |
42 | | -5. Pay special attention to: complaint categories, trigger criteria, paging numbers, escalation paths, urgency levels, organ types, patient types |
43 | | -
|
44 | | -Extract each rule as a JSON object. Return a JSON object with this exact structure: |
45 | | -{ |
46 | | - "rules": [ |
47 | | - { |
48 | | - "complaint_category": "The complaint or condition category (e.g., Fever, Pain, Bleeding, Medication Issue)", |
49 | | - "trigger_criteria": "Specific threshold or criteria that triggers this rule (e.g., Fever >100.5°F, Creatinine >2.0)", |
50 | | - "action_required": "What action to take / who to page / routing instructions", |
51 | | - "contact_method": "phone | secure_page | email | urgent_page", |
52 | | - "contact_info": "Phone/pager number if mentioned", |
53 | | - "escalation_path": "Who to escalate to if no response", |
54 | | - "priority": "routine | urgent | emergency", |
55 | | - "patient_type": "pre-transplant | post-transplant | non-transplant (if specified)", |
56 | | - "organ_type": "kidney | liver | kidney-pancreas (if specified)", |
57 | | - "documentation_notes": "Any required documentation or special instructions" |
58 | | - } |
59 | | - ], |
60 | | - "hospital_name": "Name of the hospital if mentioned in the document", |
61 | | - "summary": "Brief 2-3 sentence summary of what the document contains" |
62 | | -} |
63 | | -
|
64 | | -IMPORTANT: |
65 | | -- Extract EVERY rule you can find, even partial ones |
66 | | -- Use exact paging numbers and contact info from the document |
67 | | -- Preserve medical terminology exactly as written |
68 | | -- If the document has tabular data, treat each row as a potential rule |
69 | | -- Return valid JSON only`; |
| 32 | +// No external prompt needed — extraction is handled by the built-in file parser |
70 | 33 |
|
71 | 34 | function getFileIcon(fileName) { |
72 | 35 | const ext = fileName.split('.').pop().toLowerCase(); |
@@ -203,41 +166,10 @@ export default function ImportRulesDialog({ open, onOpenChange, hospitals }) { |
203 | 166 | setParseError(null); |
204 | 167 |
|
205 | 168 | try { |
206 | | - const docText = parsedContent.text.substring(0, 15000); |
207 | | - const prompt = EXTRACTION_PROMPT.replace('{DOCUMENT_TEXT}', docText); |
208 | | - |
209 | | - const result = await appClient.integrations.Core.InvokeLLM({ |
210 | | - prompt, |
211 | | - response_json_schema: { |
212 | | - type: "object", |
213 | | - properties: { |
214 | | - rules: { type: "array" }, |
215 | | - hospital_name: { type: "string" }, |
216 | | - summary: { type: "string" }, |
217 | | - }, |
218 | | - }, |
219 | | - }); |
220 | | - |
221 | | - let parsed; |
222 | | - try { |
223 | | - parsed = typeof result === 'string' ? JSON.parse(result) : result; |
224 | | - } catch { |
225 | | - parsed = { rules: [] }; |
226 | | - } |
227 | | - |
228 | | - if (parsed.rules && parsed.rules.length > 0) { |
229 | | - applyExtractionResult(parsed); |
230 | | - } else { |
231 | | - const offlineResult = extractOffline(); |
232 | | - applyExtractionResult(offlineResult); |
233 | | - } |
234 | | - } catch { |
235 | | - try { |
236 | | - const offlineResult = extractOffline(); |
237 | | - applyExtractionResult(offlineResult); |
238 | | - } catch (offlineErr) { |
239 | | - setParseError(`Extraction failed: ${offlineErr.message}`); |
240 | | - } |
| 169 | + const result = extractOffline(); |
| 170 | + applyExtractionResult(result); |
| 171 | + } catch (err) { |
| 172 | + setParseError(`Extraction failed: ${err.message}`); |
241 | 173 | } finally { |
242 | 174 | setIsExtracting(false); |
243 | 175 | } |
|
0 commit comments