This app ingests clinical documents, structures key clinical fields, generates an HPI narrative, and stores a versioned HPI history per case. It also supports importing MCG-style criteria documents (mapped by disease/pathway) separately from cases.
Open /cases.
- Create a new case:
/cases/new. - Upload clinical documents (PDF or DOCX) for the case.
- The system auto-classifies document type (ER_NOTE / HP_NOTE / OTHER), extracts text, and produces
structuredRawData. - In the case page, click
Generate HPIto create an HPI and append it to thegeneratedHPIhistory. - For each generated HPI entry:
Reviewruns a payer/UM score + missing points + inconsistencies + improvements.Regenerate reviewregenerates a new HPI using the review output.Regenerate HPIbased on the review, user can select the point at to the prompt, and also manually input, to regenerate a new version of HPI.Editallows direct modification with a simple choice:Update this HPI: modifies the current entry, setstype: human_revise, and clears score/review fields.Save as new HPI: creates a new entry withtype: human_reviseand clears score/review fields for the new one.
Deleteremoves the entry from history.
Auto generate loopruns a hybrid loop (generate 2 candidates, review both, then refine up to 10 times with early stopping). It saves only the final best-scoring HPI once.
Open /mcg.
- Upload an MCG guideline PDF or DOCX.
- The system extracts a structured JSON criteria map keyed by disease/pathway identifiers.
- View the extracted criteria in
/mcg/[id].
- Node.js (Node 20+ recommended)
- MongoDB connection string
- OpenAI API key
Create .env.local with:
MONGODB_URI=your_mongodb_connection_string
OPENAI_API_KEY=your_openai_keynpm install
npm run devThen open http://localhost:3000.
- Next.js App Router under
src/app/ - Case UI:
src/app/cases/[id]/page.tsx: loads case detail and renders main sectionssrc/app/cases/[id]/merged-hpi-summary.tsx: HPI generation/review/regenerate/edit UI
src/app/api/cases/[id]/ingest/route.ts: upload PDFs/DOCX and structure intostructuredRawDatasrc/app/api/cases/[id]/generate-hpi/route.ts: generate HPI and append togeneratedHPIsrc/app/api/cases/[id]/generated-hpi/route.ts:DELETEdeletes an HPI entryPATCHedits an HPI entry (update current or save new)
src/app/api/cases/[id]/generated-hpi/review/route.ts: payer/UM review stored asscore+improvementsrc/app/api/cases/[id]/regenerate-hpi/route.ts: regenerates using review instructionssrc/app/api/cases/[id]/auto-generate-hpi-loop/route.ts: server-side loop; saves only the final HPI
- HPI generation:
src/lib/generate-hpi-from-summary-gpt.ts - Review:
src/lib/generate-hpi-review-gpt.ts - Regeneration:
src/lib/generate-hpi-regenerate-gpt.ts - Auto-loop orchestration (in-memory):
src/lib/auto-hpi-loop.ts - MongoDB persistence:
src/lib/cases-db.ts
src/lib/structure-mcg-gpt.tsandsrc/lib/mcg-db.ts- UI:
src/app/mcg/page.tsxandsrc/app/mcg/[id]/page.tsx
- AWS Amplify Console -> Create app
- Connect Git provider (GitHub, GitLab, etc.)
- Select branch (e.g.
main)
Set:
- Build command:
npm run build - Start command:
npm run start
Amplify usually detects Next.js automatically; if not, choose the Next.js framework preset.
Add:
MONGODB_URIOPENAI_API_KEY
Then redeploy.