Skip to content

Add database schema for complete UI-to-database field mapping#10

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/create-database-structure
Draft

Add database schema for complete UI-to-database field mapping#10
Copilot wants to merge 4 commits into
mainfrom
copilot/create-database-structure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 17, 2025

UI forms capture 50+ fields across patient registration and clinical encounters, but only ~60% had proper database tables. Data was stored in file servers or JSON blobs, breaking relational integrity and query capability.

Changes

New Tables (8)

Patient Domain:

  • patient_emergency_contacts - Multiple contacts with primary flag constraint
  • patient_insurance - Multi-policy coverage with priority ordering (1=Primary, 2=Secondary, 3=Tertiary)
  • patient_consents - HIPAA-compliant consent tracking (email, SMS, data sharing)

Clinical Domain:

  • encounter_vitals - Vital signs with unit tracking (F/C, kg/lbs) and auto-calculated BMI
  • encounter_diagnoses - ICD-10 codes with type (primary/secondary/differential) and status tracking
  • encounter_procedures - CPT codes with workflow states (preparation → in-progress → completed)
  • lab_orders - LOINC-coded orders with complete workflow (ordered → collected → resulted) and abnormal/critical flags
  • allergies_intolerances - Medication safety with criticality levels and category-specific indexing

Migration Features

  • Multi-tenant isolation (org_id on all tables)
  • 20+ composite indexes for common query patterns
  • Check constraints for data validation
  • Audit triggers where applicable
  • Full rollback support

Documentation

  • Complete ER diagram with visual Mermaid representations (79 total tables)
  • UI-to-database field mapping for all form sections
  • Implementation guide with service/route code examples

Example Usage

// Before: Data in file storage
POST /api/patients { ...allFieldsInOneBlob }

// After: Proper relational structure
const patient = await patientService.createPatient(data);
await patientService.addEmergencyContact(patient.id, contact);
await patientService.addInsurance(patient.id, insurance);
await patientService.updateConsents(patient.id, consents);

// Clinical documentation
await encounterService.recordVitals(encounterId, vitals);
await encounterService.addDiagnosis(encounterId, { icd10_code, type: 'primary' });
await encounterService.orderLab(encounterId, { loinc_code, priority: 'stat' });

Database Impact

  • Tables: 71 → 79
  • Foreign key relationships maintain referential integrity
  • GIN indexes on JSONB fields for FHIR resource queries
  • Special index on allergies_intolerances for active medication safety checks

Implementation Path

  1. Run migration: npm run db:setup
  2. Update services per implementation guide
  3. Estimated: 14-19 hours total implementation
Original prompt

I actually want to have a proper ER integration diagram with actual database field mapping with whatever I have in the UI with all the healthcare things which Epic Surgeon may have. It should map whatever my APIs are right now jumping in one file server but which is wrong. On the UI has so much data points; I want each and every one should have a table associated with it so we can actually build APIs and implement changes.

Can do that for me. The task for you is to build a database structure for me and then we'll move ahead


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 17, 2025 12:40
- Create detailed ER diagram with UI-to-database field mapping
- Add migration for 8 missing tables (patient_emergency_contacts, patient_insurance, patient_consents, encounter_vitals, encounter_diagnoses, encounter_procedures, lab_orders, allergies_intolerances)
- Document complete database structure with 79 tables
- Provide visual Mermaid diagrams for all relationships
- Map all 50+ UI form fields to database columns
- Address issue of APIs using file storage instead of proper tables

Co-authored-by: jitendrachoudhary9623 <11938728+jitendrachoudhary9623@users.noreply.github.com>
- Add comprehensive implementation guide with step-by-step instructions
- Add executive summary of entire database structure task
- Include code examples for API services and routes
- Provide testing checklist and rollback plan
- Document timeline and success criteria

Co-authored-by: jitendrachoudhary9623 <11938728+jitendrachoudhary9623@users.noreply.github.com>
- Create comprehensive visual diagram of complete solution
- Show before/after comparison with clear benefits
- Visualize UI-to-database mapping for all forms
- Provide implementation roadmap with timeline
- Include success metrics and deliverables overview

Co-authored-by: jitendrachoudhary9623 <11938728+jitendrachoudhary9623@users.noreply.github.com>
Copilot AI changed the title [WIP] Build database structure for healthcare integration Add database schema for complete UI-to-database field mapping Dec 17, 2025
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