@omniradiology/omnirad 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +438 -0
  2. package/app/api/ai-config/route.ts +131 -0
  3. package/app/api/ai-config/test/route.ts +49 -0
  4. package/app/api/auth/auto-login/route.ts +66 -0
  5. package/app/api/auth/check/route.ts +17 -0
  6. package/app/api/auth/login/route.ts +72 -0
  7. package/app/api/auth/logout/route.ts +25 -0
  8. package/app/api/auth/me/route.ts +75 -0
  9. package/app/api/auth/password/route.ts +49 -0
  10. package/app/api/auth/setup/route.ts +63 -0
  11. package/app/api/auth/users/route.ts +100 -0
  12. package/app/api/auth/wipe/route.ts +27 -0
  13. package/app/api/compliance/anonymize/patient/[id]/route.ts +104 -0
  14. package/app/api/compliance/audit/route.ts +110 -0
  15. package/app/api/compliance/export/patient/[id]/route.ts +108 -0
  16. package/app/api/compliance/restrict/patient/[id]/route.ts +59 -0
  17. package/app/api/compliance/settings/route.ts +93 -0
  18. package/app/api/copilot/annotate/route.ts +94 -0
  19. package/app/api/copilot/chat/route.ts +238 -0
  20. package/app/api/copilot/history/route.ts +95 -0
  21. package/app/api/copilot/reports/route.ts +81 -0
  22. package/app/api/fhir/Bundle/report/[id]/route.ts +85 -0
  23. package/app/api/fhir/DiagnosticReport/[id]/route.ts +45 -0
  24. package/app/api/fhir/ImagingStudy/[id]/route.ts +57 -0
  25. package/app/api/fhir/Patient/[id]/route.ts +26 -0
  26. package/app/api/fhir/ServiceRequest/route.ts +85 -0
  27. package/app/api/fhir/config/route.ts +102 -0
  28. package/app/api/fhir/config/test-connection/route.ts +49 -0
  29. package/app/api/fhir/metadata/route.ts +51 -0
  30. package/app/api/pacs/metadata/route.ts +32 -0
  31. package/app/api/pacs/qido/instances/route.ts +39 -0
  32. package/app/api/pacs/qido/series/route.ts +38 -0
  33. package/app/api/pacs/qido/studies/route.ts +37 -0
  34. package/app/api/pacs/test/route.ts +30 -0
  35. package/app/api/pacs/wado/render/route.ts +51 -0
  36. package/app/api/patients/[id]/reports/route.ts +18 -0
  37. package/app/api/patients/[id]/route.ts +43 -0
  38. package/app/api/patients/merge/route.ts +57 -0
  39. package/app/api/patients/route.ts +67 -0
  40. package/app/api/patients/search/route.ts +25 -0
  41. package/app/api/reports/[id]/route.ts +84 -0
  42. package/app/api/reports/[id]/status/route.ts +87 -0
  43. package/app/api/reports/clear/route.ts +16 -0
  44. package/app/api/reports/route.ts +112 -0
  45. package/app/api/segmentation-config/route.ts +238 -0
  46. package/app/api/settings/route.ts +245 -0
  47. package/app/api/settings/test-supabase/route.ts +103 -0
  48. package/app/api/upload/route.ts +48 -0
  49. package/app/copilot/page.tsx +30 -0
  50. package/app/globals.css +141 -0
  51. package/app/history/page.tsx +242 -0
  52. package/app/icon.svg +3 -0
  53. package/app/layout.tsx +47 -0
  54. package/app/login/page.tsx +175 -0
  55. package/app/pacs/page.tsx +78 -0
  56. package/app/page.tsx +125 -0
  57. package/app/patients/[id]/page.tsx +315 -0
  58. package/app/patients/page.tsx +110 -0
  59. package/app/profile/page.tsx +208 -0
  60. package/app/reports/page.tsx +432 -0
  61. package/app/settings/page.tsx +454 -0
  62. package/app/setup/page.tsx +199 -0
  63. package/components/admin/AuditLogTable.tsx +293 -0
  64. package/components/copilot/ActivityIndicator.tsx +215 -0
  65. package/components/copilot/ChatHistoryPanel.tsx +140 -0
  66. package/components/copilot/ChatMessage.tsx +251 -0
  67. package/components/copilot/ClickableReference.tsx +40 -0
  68. package/components/copilot/CopilotCornerstoneViewer.tsx +562 -0
  69. package/components/copilot/CopilotPanel.tsx +311 -0
  70. package/components/copilot/FindingsList.tsx +75 -0
  71. package/components/copilot/ViewerPanel.tsx +460 -0
  72. package/components/copilot/WorkspaceLayout.tsx +398 -0
  73. package/components/dashboard/AIConfigPanel.tsx +339 -0
  74. package/components/dashboard/AppearancePanel.tsx +491 -0
  75. package/components/dashboard/ApprovalModal.tsx +163 -0
  76. package/components/dashboard/CollaborationPanel.tsx +134 -0
  77. package/components/dashboard/CopilotConfigPanel.tsx +337 -0
  78. package/components/dashboard/DicomViewer.tsx +645 -0
  79. package/components/dashboard/FhirIntegrationPanel.tsx +331 -0
  80. package/components/dashboard/FullReportOverlay.tsx +269 -0
  81. package/components/dashboard/ImageViewer.tsx +541 -0
  82. package/components/dashboard/PatientForm.tsx +597 -0
  83. package/components/dashboard/RejectionModal.tsx +74 -0
  84. package/components/dashboard/ReportEditor.tsx +160 -0
  85. package/components/dashboard/ReportTemplates.tsx +729 -0
  86. package/components/dashboard/ReportView.tsx +539 -0
  87. package/components/dashboard/SegmentationConfigPanel.tsx +490 -0
  88. package/components/dashboard/StudyPlaceholder.tsx +17 -0
  89. package/components/dashboard/SupabaseIntegrationPanel.tsx +345 -0
  90. package/components/dashboard/UserManagementPanel.tsx +272 -0
  91. package/components/layout/ClientLayout.tsx +39 -0
  92. package/components/layout/Header.tsx +20 -0
  93. package/components/layout/Sidebar.tsx +119 -0
  94. package/components/pacs/PacsImageViewerModal.tsx +121 -0
  95. package/components/pacs/PacsSearchFilters.tsx +117 -0
  96. package/components/pacs/PacsSeriesViewer.tsx +190 -0
  97. package/components/pacs/PacsStudyTable.tsx +113 -0
  98. package/components/patients/patient-card.tsx +117 -0
  99. package/components/patients/patient-header.tsx +122 -0
  100. package/components/patients/patient-search.tsx +137 -0
  101. package/components/patients/patient-timeline.tsx +153 -0
  102. package/components/settings/ComplianceSettingsPanel.tsx +278 -0
  103. package/components/settings/SecurityPanel.tsx +418 -0
  104. package/components/ui/badge.tsx +19 -0
  105. package/components/ui/basic.tsx +156 -0
  106. package/db/index.ts +350 -0
  107. package/db/migrations/0000_odd_quasimodo.sql +117 -0
  108. package/db/migrations/meta/0000_snapshot.json +778 -0
  109. package/db/migrations/meta/_journal.json +13 -0
  110. package/db/schema.ts +239 -0
  111. package/drizzle.config.ts +10 -0
  112. package/lib/api.ts +689 -0
  113. package/lib/auth.ts +22 -0
  114. package/lib/copilot/action-executor.ts +94 -0
  115. package/lib/copilot/action-types.ts +72 -0
  116. package/lib/copilot/coordinate-mapper.ts +84 -0
  117. package/lib/dicomImageExtractor.ts +103 -0
  118. package/lib/dicomMetadataParser.ts +111 -0
  119. package/lib/fhir/client.ts +25 -0
  120. package/lib/fhir/constants.ts +21 -0
  121. package/lib/fhir/diagnostic-report.ts +88 -0
  122. package/lib/fhir/helpers.ts +73 -0
  123. package/lib/fhir/imaging-study.ts +49 -0
  124. package/lib/fhir/patient.ts +55 -0
  125. package/lib/fhir/service-request.ts +85 -0
  126. package/lib/fhir.ts +6 -0
  127. package/lib/pacs/dicom-utils.ts +72 -0
  128. package/lib/pacs/dicomweb.ts +72 -0
  129. package/lib/pacs/server-utils.ts +37 -0
  130. package/lib/patients.ts +25 -0
  131. package/lib/pdfHelper.ts +119 -0
  132. package/lib/reportHtmlGenerator.ts +581 -0
  133. package/lib/security/audit.ts +180 -0
  134. package/lib/security/authz.ts +246 -0
  135. package/lib/security/phi-redaction.ts +156 -0
  136. package/lib/security/rate-limit.ts +106 -0
  137. package/lib/security/secrets.ts +179 -0
  138. package/lib/supabase.ts +72 -0
  139. package/lib/utils.ts +6 -0
  140. package/next.config.ts +35 -0
  141. package/package.json +76 -0
  142. package/public/file.svg +1 -0
  143. package/public/globe.svg +1 -0
  144. package/public/logo.svg +8 -0
  145. package/public/next.svg +1 -0
  146. package/public/omnirad-favicon.svg +8 -0
  147. package/public/vercel.svg +1 -0
  148. package/public/window.svg +1 -0
  149. package/tsconfig.json +34 -0
  150. package/types/copilot-viewer.ts +155 -0
  151. package/types/copilot.ts +105 -0
  152. package/types/fhir.ts +21 -0
  153. package/types/html2pdf.d.ts +20 -0
  154. package/types/index.ts +139 -0
  155. package/types/pacs.ts +41 -0
@@ -0,0 +1,13 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "sqlite",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "6",
8
+ "when": 1775692396390,
9
+ "tag": "0000_odd_quasimodo",
10
+ "breakpoints": true
11
+ }
12
+ ]
13
+ }
package/db/schema.ts ADDED
@@ -0,0 +1,239 @@
1
+ import { sqliteTable, text, integer, real } from "drizzle-orm/sqlite-core";
2
+
3
+ // ─── Patients Table ────────────────────────────────────────────────────────────
4
+ export const patients = sqliteTable("patients", {
5
+ id: text("id").primaryKey(),
6
+ patientIdNumber: text("patient_id_number"),
7
+ patientName: text("patient_name").notNull(),
8
+ dob: text("date_of_birth"),
9
+ age: integer("age"),
10
+ gender: text("gender"),
11
+ mobile: text("mobile"),
12
+ address: text("address"),
13
+ contactInfo: text("contact_info"),
14
+ notes: text("notes"),
15
+ createdAt: text("created_at").notNull(),
16
+ updatedAt: text("updated_at")
17
+ });
18
+
19
+ // ─── Reports Table ───────────────────────────────────────────────────────────
20
+ export const reports = sqliteTable("reports", {
21
+ id: text("id").primaryKey(),
22
+ patientId: text("patient_id").references(() => patients.id, { onDelete: 'cascade' }),
23
+ patientName: text("patient_name"),
24
+ modality: text("modality"),
25
+ urgency: text("urgency"),
26
+ reportStatus: text("report_status").default("Pending"),
27
+ reportData: text("report_data").notNull(), // JSON string of ReportData
28
+ imageData: text("image_data"), // base64 image (can be large)
29
+ pacsStudyUid: text("pacs_study_uid"),
30
+ pacsSeriesUid: text("pacs_series_uid"),
31
+ pacsSource: text("pacs_source"),
32
+ createdAt: text("created_at").notNull(),
33
+ });
34
+
35
+ // ─── Config Table (singleton) ────────────────────────────────────────────────
36
+ export const config = sqliteTable("config", {
37
+ id: integer("id").primaryKey().default(1),
38
+ n8nWebhookUrl: text("n8n_webhook_url").default(""),
39
+ supabaseUrl: text("supabase_url").default(""),
40
+ supabaseAnonKey: text("supabase_anon_key").default(""),
41
+ pacsOrthancUrl: text("pacs_orthanc_url").default(""),
42
+ pacsAuthType: text("pacs_auth_type").default("none"),
43
+ pacsUsername: text("pacs_username").default(""),
44
+ pacsPassword: text("pacs_password").default(""),
45
+ pacsBearerToken: text("pacs_bearer_token").default(""),
46
+ pacsAeTitle: text("pacs_ae_title").default(""),
47
+ });
48
+
49
+ // ─── Profile Table (singleton) ───────────────────────────────────────────────
50
+ export const profile = sqliteTable("profile", {
51
+ id: integer("id").primaryKey().default(1),
52
+ fullName: text("full_name").default(""),
53
+ role: text("role").default(""),
54
+ hospitalName: text("hospital_name").default(""),
55
+ department: text("department").default(""),
56
+ });
57
+
58
+ // ─── Appearance Table (singleton) ────────────────────────────────────────────
59
+ export const appearance = sqliteTable("appearance", {
60
+ id: integer("id").primaryKey().default(1),
61
+ theme: text("theme").default("dark"),
62
+ template: text("template").default("standard"),
63
+ hospitalName: text("hospital_name").default(""),
64
+ logo: text("logo").default(""),
65
+ });
66
+
67
+ // ─── Security Table (singleton) ──────────────────────────────────────────────
68
+ export const security = sqliteTable("security", {
69
+ id: integer("id").primaryKey().default(1),
70
+ appLockEnabled: integer("app_lock_enabled", { mode: 'boolean' }).default(true), // true = locked (login required)
71
+ defaultUserId: text("default_user_id"), // user to auto-login when unlocked (null = first admin)
72
+ updatedBy: text("updated_by"), // user ID of admin who last changed this
73
+ updatedAt: text("updated_at"), // ISO timestamp of last change
74
+ });
75
+
76
+ // ─── Users Table ─────────────────────────────────────────────────────────────
77
+ export const users = sqliteTable("users", {
78
+ id: text("id").primaryKey(),
79
+ fullName: text("full_name").notNull(),
80
+ username: text("username").notNull().unique(),
81
+ email: text("email").notNull().unique(),
82
+ passwordHash: text("password_hash").notNull(),
83
+ role: text("role").default("User"), // Admin or User
84
+ position: text("position").default(""), // Doctor, Nurse, Technician etc
85
+ createdAt: text("created_at").notNull(),
86
+ });
87
+
88
+ // ─── Sessions Table ──────────────────────────────────────────────────────────
89
+ export const sessions = sqliteTable("sessions", {
90
+ id: text("id").primaryKey(),
91
+ userId: text("user_id").notNull().references(() => users.id),
92
+ expiresAt: integer("expires_at").notNull() // Unix timestamp
93
+ });
94
+
95
+ // ─── AI Settings & LangGraph Logs ───────────────────────────────────────────
96
+ export const aiConfigurations = sqliteTable("ai_configurations", {
97
+ id: text("id").primaryKey(),
98
+ providerType: text("provider_type").notNull(), // 'cloud_api' | 'ollama' | 'custom_endpoint'
99
+ providerName: text("provider_name").notNull(), // e.g. "Google Gemini"
100
+ apiEndpointUrl: text("api_endpoint_url"),
101
+ apiSecretKey: text("api_secret_key"),
102
+ modelName: text("model_name").notNull(),
103
+ isActive: integer("is_active", { mode: 'boolean' }).default(false),
104
+ isVisionCapable: integer("is_vision_capable", { mode: 'boolean' }).default(false),
105
+ maxTokens: integer("max_tokens").default(4096),
106
+ temperature: real("temperature").default(0.3),
107
+ timeoutSeconds: integer("timeout_seconds").default(120),
108
+ purpose: text("purpose").default("report_generation"), // 'report_generation' | 'copilot'
109
+ langsmithApiKey: text("langsmith_api_key"),
110
+ langsmithProject: text("langsmith_project"),
111
+ createdAt: text("created_at").notNull(),
112
+ updatedAt: text("updated_at")
113
+ });
114
+
115
+ export const promptTemplates = sqliteTable("prompt_templates", {
116
+ id: text("id").primaryKey(),
117
+ name: text("name").notNull(),
118
+ template: text("template").notNull(),
119
+ isActive: integer("is_active", { mode: 'boolean' }).default(false),
120
+ createdAt: text("created_at").notNull(),
121
+ updatedAt: text("updated_at")
122
+ });
123
+
124
+ export const reportGenerationLogs = sqliteTable("report_generation_logs", {
125
+ id: text("id").primaryKey(),
126
+ reportId: text("report_id"),
127
+ aiConfigId: text("ai_config_id").references(() => aiConfigurations.id),
128
+ modelUsed: text("model_used"),
129
+ promptTemplateId: text("prompt_template_id"),
130
+ rawLlmResponse: text("raw_llm_response"),
131
+ parsedSuccessfully: integer("parsed_successfully", { mode: 'boolean' }),
132
+ retryCount: integer("retry_count"),
133
+ generationTimeMs: integer("generation_time_ms"),
134
+ errorMessage: text("error_message"),
135
+ createdAt: text("created_at").notNull()
136
+ });
137
+
138
+ // ─── Chat Messages Table (AI Copilot) ────────────────────────────────────────
139
+ export const chatMessages = sqliteTable("chat_messages", {
140
+ id: integer("id").primaryKey({ autoIncrement: true }),
141
+ sessionId: text("session_id").notNull(),
142
+ role: text("role").notNull(), // 'user' | 'assistant'
143
+ content: text("content").notNull(),
144
+ viewerActions: text("viewer_actions"), // JSON string of ViewerAction[]
145
+ references: text("references"), // JSON string of Reference[]
146
+ patientId: text("patient_id"),
147
+ createdAt: text("created_at").default("CURRENT_TIMESTAMP"),
148
+ });
149
+
150
+ // ─── Compliance Settings Table (singleton) ───────────────────────────────────
151
+ export const complianceSettings = sqliteTable("compliance_settings", {
152
+ id: integer("id").primaryKey().default(1),
153
+ dataRetentionDays: integer("data_retention_days").default(2555),
154
+ auditRetentionDays: integer("audit_retention_days").default(2555),
155
+ sessionTimeoutMinutes: integer("session_timeout_minutes").default(15),
156
+ idleTimeoutMinutes: integer("idle_timeout_minutes").default(30),
157
+ enableGdprExport: integer("enable_gdpr_export", { mode: 'boolean' }).default(true),
158
+ enableGdprAnonymize: integer("enable_gdpr_anonymize", { mode: 'boolean' }).default(true),
159
+ enableGdprRestriction: integer("enable_gdpr_restriction", { mode: 'boolean' }).default(true),
160
+ legalBasis: text("legal_basis").default("legitimate_interest"),
161
+ privacyPolicyUrl: text("privacy_policy_url"),
162
+ dpoContactEmail: text("dpo_contact_email"),
163
+ updatedAt: text("updated_at"),
164
+ });
165
+
166
+ // ─── FHIR Integration Config Table (singleton) ──────────────────────────────
167
+ export const fhirIntegrationConfig = sqliteTable("fhir_integration_config", {
168
+ id: integer("id").primaryKey().default(1),
169
+ enabled: integer("enabled", { mode: 'boolean' }).default(false),
170
+ publicBaseUrl: text("public_base_url").default(""),
171
+ authMode: text("auth_mode").default("bearer_token"),
172
+ inboundServiceRequestEnabled: integer("inbound_service_request_enabled", { mode: 'boolean' }).default(false),
173
+ outboundReadEnabled: integer("outbound_read_enabled", { mode: 'boolean' }).default(true),
174
+ externalFhirBaseUrl: text("external_fhir_base_url").default(""),
175
+ externalFhirAuthType: text("external_fhir_auth_type").default("none"),
176
+ externalFhirClientId: text("external_fhir_client_id").default(""),
177
+ externalFhirClientSecret: text("external_fhir_client_secret"),
178
+ externalFhirBearerToken: text("external_fhir_bearer_token"),
179
+ apiTokenHash: text("api_token_hash"),
180
+ createdAt: text("created_at"),
181
+ updatedAt: text("updated_at"),
182
+ });
183
+
184
+ // ─── Worklist Orders Table (FHIR ServiceRequest inbound) ─────────────────────
185
+ export const worklistOrders = sqliteTable("worklist_orders", {
186
+ id: text("id").primaryKey(),
187
+ sourceSystem: text("source_system").default("FHIR"),
188
+ fhirServiceRequestId: text("fhir_service_request_id"),
189
+ patientId: text("patient_id").references(() => patients.id, { onDelete: 'cascade' }),
190
+ patientName: text("patient_name"),
191
+ patientIdentifier: text("patient_identifier"),
192
+ status: text("status").default("active"),
193
+ intent: text("intent").default("order"),
194
+ priority: text("priority").default("routine"),
195
+ urgency: text("urgency").default("Routine"),
196
+ modality: text("modality"),
197
+ requestedProcedure: text("requested_procedure"),
198
+ reason: text("reason"),
199
+ authoredOn: text("authored_on"),
200
+ requesterDisplay: text("requester_display"),
201
+ rawFhir: text("raw_fhir"),
202
+ createdAt: text("created_at").notNull(),
203
+ updatedAt: text("updated_at"),
204
+ });
205
+
206
+ // ─── Patient Privacy Controls Table (GDPR compliance tracking) ───────────────
207
+ export const patientPrivacyControls = sqliteTable("patient_privacy_controls", {
208
+ id: text("id").primaryKey(),
209
+ patientId: text("patient_id").notNull().references(() => patients.id, { onDelete: 'cascade' }),
210
+ restriction: text("restriction"),
211
+ consentStatus: text("consent_status"),
212
+ anonymizedAt: text("anonymized_at"),
213
+ anonymizedBy: text("anonymized_by"),
214
+ lastExportedAt: text("last_exported_at"),
215
+ lastExportedBy: text("last_exported_by"),
216
+ createdAt: text("created_at").notNull(),
217
+ updatedAt: text("updated_at"),
218
+ });
219
+
220
+ // ─── Audit Logs Table ────────────────────────────────────────────────────────
221
+ export const auditLogs = sqliteTable("audit_logs", {
222
+ id: text("id").primaryKey(),
223
+ actorUserId: text("actor_user_id"),
224
+ actorRole: text("actor_role"),
225
+ actorType: text("actor_type").default("user"),
226
+ action: text("action").notNull(),
227
+ resourceType: text("resource_type").notNull(),
228
+ resourceId: text("resource_id"),
229
+ patientId: text("patient_id"),
230
+ ipAddress: text("ip_address"),
231
+ userAgent: text("user_agent"),
232
+ success: integer("success", { mode: 'boolean' }).default(true),
233
+ reason: text("reason"),
234
+ metadata: text("metadata"), // JSON string
235
+ createdAt: text("created_at").notNull(),
236
+ });
237
+
238
+
239
+
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from "drizzle-kit";
2
+
3
+ export default defineConfig({
4
+ schema: "./db/schema.ts",
5
+ out: "./db/migrations",
6
+ dialect: "sqlite",
7
+ dbCredentials: {
8
+ url: "./data/omnirad.db",
9
+ },
10
+ });