@peopl-health/nexus 6.0.0-dev.718 → 6.0.0
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.
- package/README.md +104 -0
- package/lib/adapters/BaileysProvider.js +8 -37
- package/lib/adapters/MessageAdapter.js +3 -1
- package/lib/adapters/MessageProvider.js +0 -11
- package/lib/adapters/TwilioProvider.js +44 -77
- package/lib/clinical/AssistantProcessor.js +414 -19
- package/lib/clinical/assistants/BaseAssistant.js +0 -15
- package/lib/clinical/config/checkInConfig.js +3 -0
- package/lib/clinical/config/cohortConfig.js +3 -3
- package/lib/clinical/config/composerConfig.js +42 -0
- package/lib/clinical/config/divergenceConfig.js +80 -50
- package/lib/clinical/config/llmConfig.js +11 -2
- package/lib/clinical/config/safetyNetConfig.js +108 -0
- package/lib/clinical/config/subAgentsConfig.js +61 -2
- package/lib/clinical/context/ToolRuntimeContext.js +121 -6
- package/lib/clinical/context/turnContext.js +50 -0
- package/lib/clinical/flags/bridgeConfig.js +31 -0
- package/lib/clinical/flags/clinicalContextFlags.js +46 -0
- package/lib/clinical/flags/composerFlags.js +14 -0
- package/lib/clinical/flags/contingencyFlags.js +19 -0
- package/lib/clinical/flags/escalationFlags.js +43 -0
- package/lib/clinical/flags/flagSnapshot.js +58 -0
- package/lib/clinical/flags/inboundRecoveryFlags.js +17 -0
- package/lib/clinical/flags/llmAuditConfig.js +7 -0
- package/lib/clinical/flags/llmMonitorConfig.js +18 -0
- package/lib/clinical/flags/patternConsultFlags.js +10 -0
- package/lib/clinical/flags/recommendationRecoveryFlags.js +9 -0
- package/lib/clinical/flags/supportLightFlags.js +7 -0
- package/lib/clinical/flags/triageRecommendationFlags.js +16 -0
- package/lib/clinical/flags/turnEfficiencyFlags.js +19 -0
- package/lib/clinical/helpers/auditReasoningHelper.js +30 -0
- package/lib/clinical/helpers/carePlanInterventionDerivation.js +76 -0
- package/lib/clinical/helpers/carePlanValidationHelper.js +62 -0
- package/lib/clinical/helpers/ceilingGapHelper.js +21 -0
- package/lib/clinical/helpers/chemoContextHelper.js +217 -0
- package/lib/clinical/helpers/clinicalContextHelper.js +162 -0
- package/lib/clinical/helpers/clinicalFactsHelper.js +45 -4
- package/lib/clinical/helpers/clinicalMentionHelper.js +16 -13
- package/lib/clinical/helpers/clinicalProfileHelper.js +60 -0
- package/lib/clinical/helpers/clinicalWorkflowGuard.js +175 -0
- package/lib/clinical/helpers/cohortHelper.js +3 -1
- package/lib/clinical/helpers/contextMirrorHelper.js +68 -0
- package/lib/clinical/helpers/dateAnchorHelper.js +18 -0
- package/lib/clinical/helpers/doctorReviewMessageHelper.js +152 -0
- package/lib/clinical/helpers/drugIdentityHelper.js +67 -0
- package/lib/clinical/helpers/encodedPairHelper.js +12 -0
- package/lib/clinical/helpers/evidenceAnchorHelper.js +70 -0
- package/lib/clinical/helpers/factAssertionHelper.js +300 -0
- package/lib/clinical/helpers/gradeEstimateHelper.js +148 -0
- package/lib/clinical/helpers/hospitalizationContextHelper.js +8 -0
- package/lib/clinical/helpers/legacyContextHelper.js +122 -0
- package/lib/clinical/helpers/legacyRecommendationFormatHelper.js +107 -0
- package/lib/clinical/helpers/llmsHelper.js +170 -87
- package/lib/clinical/helpers/managedSymptomProjectionHelper.js +23 -0
- package/lib/clinical/helpers/medicationNamingRule.js +5 -0
- package/lib/clinical/helpers/palliativeAssessmentHelper.js +62 -0
- package/lib/clinical/helpers/palliativeCarePlanHelper.js +68 -0
- package/lib/clinical/helpers/recommendationGateHelper.js +208 -0
- package/lib/clinical/helpers/recommendationPlanHelper.js +104 -0
- package/lib/clinical/helpers/resultsHelper.js +56 -0
- package/lib/clinical/helpers/reviewUpdateHelper.js +68 -0
- package/lib/clinical/helpers/shadowHelper.js +1 -13
- package/lib/clinical/helpers/skillActivationHelper.js +53 -0
- package/lib/clinical/helpers/structuredTextHelper.js +13 -0
- package/lib/clinical/helpers/toolResultHelper.js +35 -0
- package/lib/clinical/helpers/triageCaseBaseHelper.js +483 -0
- package/lib/clinical/helpers/triageResultMessageHelper.js +30 -0
- package/lib/clinical/helpers/triageRetriggerHelper.js +85 -0
- package/lib/clinical/helpers/triageSymptomsHelper.js +33 -0
- package/lib/clinical/index.js +4 -0
- package/lib/clinical/memory/DefaultMemoryManager.js +211 -39
- package/lib/clinical/memory/EnhancedMemoryManager.js +14 -8
- package/lib/clinical/models/llmCallModel.js +19 -0
- package/lib/clinical/models/llmMonitorCheckpointModel.js +20 -0
- package/lib/clinical/models/llmMonitorEvaluationModel.js +56 -0
- package/lib/clinical/models/patternConsultModel.js +37 -0
- package/lib/clinical/models/riskWarmupEventModel.js +23 -0
- package/lib/clinical/models/supportCandidateModel.js +90 -0
- package/lib/clinical/models/supportLightModel.js +95 -0
- package/lib/clinical/models/triageRecommendationEventModel.js +110 -0
- package/lib/clinical/models/turnTraceModel.js +24 -7
- package/lib/clinical/monitoring/AirtableMonitorSink.js +488 -0
- package/lib/clinical/monitoring/LlmMonitorService.js +558 -0
- package/lib/clinical/monitoring/contingencyMonitorSpec.js +601 -0
- package/lib/clinical/promptPlacement.js +5 -0
- package/lib/clinical/protocols/treatmentFormulary.js +387 -0
- package/lib/clinical/providers/AnthropicProvider.js +459 -31
- package/lib/clinical/providers/BaseLLMProvider.js +689 -52
- package/lib/clinical/providers/GatewayProvider.js +14 -4
- package/lib/clinical/providers/OpenAIResponsesProvider.js +73 -11
- package/lib/clinical/providers/OpenAIResponsesProviderTools.js +24 -9
- package/lib/clinical/providers/OpenRouterProvider.js +9 -2
- package/lib/clinical/services/assistantService.js +51 -7
- package/lib/clinical/services/bridgeService.js +93 -0
- package/lib/clinical/services/checkInDueService.js +134 -0
- package/lib/clinical/services/clinicalAirtableService.js +752 -0
- package/lib/clinical/services/clinicalContextReadService.js +47 -0
- package/lib/clinical/services/clinicalExtractionService.js +156 -23
- package/lib/clinical/services/composerService.js +78 -0
- package/lib/clinical/services/conceptVerifierService.js +127 -0
- package/lib/clinical/services/conditionCloseService.js +138 -0
- package/lib/clinical/services/contextCleanupService.js +85 -0
- package/lib/clinical/services/contextMirrorService.js +72 -0
- package/lib/clinical/services/contextSyncRunner.js +20 -0
- package/lib/clinical/services/contextSyncService.js +258 -0
- package/lib/clinical/services/contingencyDispatchService.js +496 -0
- package/lib/clinical/services/ctcaeLadderService.js +70 -0
- package/lib/clinical/services/ctcaeTermService.js +44 -0
- package/lib/clinical/services/currentRegimenService.js +60 -0
- package/lib/clinical/services/deliverySettlementService.js +39 -0
- package/lib/clinical/services/deniedSymptomBoundaryService.js +218 -0
- package/lib/clinical/services/dispatcherService.js +142 -0
- package/lib/clinical/services/escalationDraftService.js +229 -0
- package/lib/clinical/services/escalationNoteFactsService.js +131 -0
- package/lib/clinical/services/escalationQuestionsService.js +131 -0
- package/lib/clinical/services/gradeAnchorService.js +85 -0
- package/lib/clinical/services/gradeClaimService.js +73 -0
- package/lib/clinical/services/gradeSourceService.js +138 -0
- package/lib/clinical/services/impressionValidationService.js +19 -0
- package/lib/clinical/services/legacyContextSyncService.js +255 -0
- package/lib/clinical/services/llmAuditService.js +23 -0
- package/lib/clinical/services/nutritionPlanService.js +97 -0
- package/lib/clinical/services/outreachCarrierService.js +88 -0
- package/lib/clinical/services/outreachSweepRunner.js +8 -0
- package/lib/clinical/services/outreachSweepService.js +644 -0
- package/lib/clinical/services/patientHistoryService.js +203 -0
- package/lib/clinical/services/patientIdentityService.js +43 -0
- package/lib/clinical/services/patientProfileService.js +145 -0
- package/lib/clinical/services/patternConsultService.js +127 -0
- package/lib/clinical/services/pausedSafetyNetService.js +387 -0
- package/lib/clinical/services/promptComposerService.js +74 -21
- package/lib/clinical/services/radiotherapyContextService.js +40 -0
- package/lib/clinical/services/radiotherapyPhaseService.js +272 -0
- package/lib/clinical/services/recommendationRankService.js +180 -0
- package/lib/clinical/services/recommendationRecoveryService.js +241 -0
- package/lib/clinical/services/recommendationValidationService.js +206 -0
- package/lib/clinical/services/regimenCloserService.js +205 -0
- package/lib/clinical/services/reminderDispatchService.js +36 -0
- package/lib/clinical/services/riskAssessmentService.js +469 -0
- package/lib/clinical/services/riskHeadlineService.js +56 -0
- package/lib/clinical/services/safetyNetPledgeService.js +231 -0
- package/lib/clinical/services/shadowMessageService.js +30 -12
- package/lib/clinical/services/shadowService.js +8 -4
- package/lib/clinical/services/skillService.js +117 -0
- package/lib/clinical/services/supportActionService.js +122 -0
- package/lib/clinical/services/supportCandidateService.js +607 -0
- package/lib/clinical/services/supportInvitability.js +86 -0
- package/lib/clinical/services/supportLightEvaluationService.js +231 -0
- package/lib/clinical/services/supportLightService.js +277 -0
- package/lib/clinical/services/supportRoutingAgentService.js +118 -0
- package/lib/clinical/services/symptomLandscapeService.js +153 -0
- package/lib/clinical/services/treatmentProposalService.js +136 -0
- package/lib/clinical/services/triageRecommendationService.js +1226 -0
- package/lib/clinical/services/turnRiskBriefService.js +217 -0
- package/lib/clinical/services/writeClaimStore.js +126 -0
- package/lib/clinical/stores/CtcaeCatalog.js +21 -0
- package/lib/clinical/tools/analyzeSymptomPatternsTool.js +276 -0
- package/lib/clinical/tools/deliverPatientMessageTool.js +294 -0
- package/lib/clinical/tools/extractClinicalInfoTool.js +252 -37
- package/lib/clinical/tools/getActiveRecommendationsTool.js +44 -0
- package/lib/clinical/tools/getActiveSymptomLandscapeTool.js +37 -0
- package/lib/clinical/tools/getPatientHistoryTool.js +45 -0
- package/lib/clinical/tools/getPatientRiskAssessmentTool.js +66 -0
- package/lib/clinical/tools/getRouterContextBundleTool.js +136 -0
- package/lib/clinical/tools/lookupCtcaeEntryTool.js +36 -0
- package/lib/clinical/tools/openClusterHypothesisTool.js +175 -0
- package/lib/clinical/tools/openConditionTool.js +198 -0
- package/lib/clinical/tools/recordClinicalImpressionTool.js +394 -0
- package/lib/clinical/tools/recordInterventionTool.js +138 -0
- package/lib/clinical/tools/recordRecommendationOutcomeTool.js +72 -0
- package/lib/clinical/tools/registerClinicalTools.js +51 -6
- package/lib/clinical/tools/reportCrisisTool.js +193 -0
- package/lib/clinical/tools/reportMedicalEscalationTool.js +471 -0
- package/lib/clinical/tools/reportResultsReceivedTool.js +176 -0
- package/lib/clinical/tools/reportUnresolvedRequestv2Tool.js +164 -0
- package/lib/clinical/tools/requestPatternConsultTool.js +70 -0
- package/lib/clinical/tools/schedulePatientReminderTool.js +292 -0
- package/lib/clinical/tools/sendBridgeMessageTool.js +33 -0
- package/lib/clinical/tools/setContingencyPlanTool.js +332 -0
- package/lib/clinical/tools/skillTool.js +81 -0
- package/lib/clinical/tools/submitNutritionSafetyDecisionTool.js +200 -0
- package/lib/clinical/tools/submitOutreachDecisionTool.js +139 -0
- package/lib/clinical/tools/submitPalliativeAssessmentTool.js +75 -0
- package/lib/clinical/tools/submitPalliativeCarePlanTool.js +101 -0
- package/lib/clinical/tools/submitRecommendationPlanTool.js +145 -0
- package/lib/clinical/tools/submitRoutingDecisionTool.js +466 -0
- package/lib/clinical/tools/submitSafetyGateTool.js +130 -0
- package/lib/clinical/tools/submitSupportRoutingRecommendationTool.js +149 -0
- package/lib/clinical/tools/updateClusterHypothesisTool.js +178 -0
- package/lib/clinical/tools/updateConditionStatusTool.js +192 -0
- package/lib/clinical/tools/updatePalliativeAssessmentTool.js +78 -0
- package/lib/config/airtableArchiveConfig.js +177 -0
- package/lib/config/airtableConfig.js +24 -1
- package/lib/config/instructionConfig.js +5 -0
- package/lib/config/lifecycle.js +36 -1
- package/lib/config/programConfig.js +20 -0
- package/lib/controllers/assistantController.js +67 -11
- package/lib/controllers/contextSyncController.js +30 -0
- package/lib/controllers/contingencyController.js +28 -0
- package/lib/controllers/conversationController.js +7 -7
- package/lib/controllers/dashboardController.js +7 -4
- package/lib/controllers/escalationReviewController.js +299 -0
- package/lib/controllers/healthController.js +16 -0
- package/lib/controllers/interactionController.js +1 -1
- package/lib/controllers/messageController.js +67 -19
- package/lib/controllers/officeAssistantController.js +57 -0
- package/lib/controllers/patientController.js +216 -48
- package/lib/controllers/prescriptionController.js +10 -3
- package/lib/controllers/templateController.js +8 -17
- package/lib/controllers/traceController.js +26 -0
- package/lib/controllers/triageRecommendationController.js +41 -0
- package/lib/controllers/uploadController.js +2 -2
- package/lib/core/BatchingManager.js +146 -11
- package/lib/core/DeferredWorkRunner.js +257 -0
- package/lib/core/MessageParser.js +2 -2
- package/lib/core/NexusMessaging.js +948 -146
- package/lib/core/PhiProcessor.js +198 -17
- package/lib/core/ProcessingPipeline.js +49 -4
- package/lib/core/interactiveRouteService.js +64 -0
- package/lib/core/runtimeToolPolicy.js +3 -0
- package/lib/eval/EvalProvider.js +72 -25
- package/lib/fhir/config/catalogConfig.js +9 -14
- package/lib/fhir/config/fhirConfig.js +16 -12
- package/lib/fhir/constants/escalationCaseStatus.js +31 -0
- package/lib/fhir/constants/extensionSlugs.js +195 -0
- package/lib/fhir/constants/gradeMethods.js +12 -0
- package/lib/fhir/constants/projectionSlugs.js +69 -1
- package/lib/fhir/constants/severityPriority.js +8 -0
- package/lib/fhir/constants/variableRegistry.js +60 -0
- package/lib/fhir/helpers/compositeHelper.js +65 -12
- package/lib/fhir/helpers/contextArbitrationHelper.js +41 -0
- package/lib/fhir/helpers/elementHelper.js +39 -0
- package/lib/fhir/helpers/fhirHelper.js +4 -1
- package/lib/fhir/helpers/fhirReadHelper.js +62 -0
- package/lib/fhir/helpers/recommendationIds.js +44 -0
- package/lib/fhir/helpers/resourceDisplayHelper.js +9 -0
- package/lib/fhir/helpers/resourceHelper.js +46 -0
- package/lib/fhir/helpers/symptomAliasHelper.js +56 -0
- package/lib/fhir/helpers/termMatchHelper.js +42 -0
- package/lib/fhir/helpers/terminologyHelper.js +92 -5
- package/lib/fhir/helpers/triagePayloadHelper.js +133 -0
- package/lib/fhir/helpers/variableRegistryHelper.js +21 -0
- package/lib/fhir/index.js +75 -0
- package/lib/fhir/models/envelopeModel.js +22 -0
- package/lib/fhir/projections/clinicalMentionProjection.js +208 -46
- package/lib/fhir/projections/clusterProjection.js +124 -0
- package/lib/fhir/projections/contextFactProjection.js +380 -0
- package/lib/fhir/projections/contingencyProjection.js +224 -0
- package/lib/fhir/projections/dispatchedEscalationProjection.js +63 -0
- package/lib/fhir/projections/interventionProjection.js +245 -0
- package/lib/fhir/projections/palliativeCarePlanProjection.js +183 -0
- package/lib/fhir/projections/palliativeProjection.js +175 -0
- package/lib/fhir/projections/proctcaeProjection.js +62 -15
- package/lib/fhir/projections/recommendationPlanProjection.js +557 -0
- package/lib/fhir/projections/registerProjectors.js +10 -2
- package/lib/fhir/projections/reminderProjection.js +20 -0
- package/lib/fhir/projections/riskProjection.js +16 -0
- package/lib/fhir/projections/routingProjection.js +285 -0
- package/lib/fhir/projections/safetyGateProjection.js +42 -0
- package/lib/fhir/projections/symptomCaseProjection.js +324 -0
- package/lib/fhir/resources/CommunicationRequest.js +91 -0
- package/lib/fhir/resources/Condition.js +2 -24
- package/lib/fhir/resources/Encounter.js +30 -0
- package/lib/fhir/resources/Observation.js +22 -69
- package/lib/fhir/resources/Patient.js +57 -6
- package/lib/fhir/resources/Provenance.js +48 -12
- package/lib/fhir/resources/RiskAssessment.js +184 -0
- package/lib/fhir/resources/Task.js +102 -0
- package/lib/fhir/services/clinicalContextService.js +161 -0
- package/lib/fhir/services/clinicalMentionService.js +3 -5
- package/lib/fhir/services/clusterService.js +30 -0
- package/lib/fhir/services/contingencyService.js +47 -0
- package/lib/fhir/services/encounterService.js +16 -0
- package/lib/fhir/services/escalationService.js +85 -0
- package/lib/fhir/services/fhirService.js +20 -0
- package/lib/fhir/services/interventionService.js +50 -0
- package/lib/fhir/services/palliativeService.js +74 -0
- package/lib/fhir/services/patientService.js +41 -0
- package/lib/fhir/services/recommendationService.js +336 -0
- package/lib/fhir/services/resultObservationService.js +53 -0
- package/lib/fhir/services/riskService.js +202 -0
- package/lib/fhir/services/routingService.js +86 -0
- package/lib/fhir/services/snapshotService.js +18 -3
- package/lib/fhir/services/symptomCaseService.js +33 -0
- package/lib/fhir/services/terminologyService.js +16 -21
- package/lib/fhir/services/triageService.js +8 -4
- package/lib/fhir/stores/fhirStore.js +42 -19
- package/lib/fhir/utils/normalizeUtils.js +12 -0
- package/lib/helpers/airtableArchiveHelper.js +51 -0
- package/lib/helpers/airtableFormulaHelper.js +25 -0
- package/lib/helpers/caregiverHelper.js +136 -0
- package/lib/helpers/channelErrorHelper.js +31 -0
- package/lib/helpers/channelRetryHelper.js +156 -0
- package/lib/helpers/conversationWindowHelper.js +2 -2
- package/lib/helpers/deliveryAttemptHelper.js +14 -2
- package/lib/helpers/filesHelper.js +3 -3
- package/lib/helpers/healthHelper.js +40 -0
- package/lib/helpers/messageHelper.js +16 -6
- package/lib/helpers/messageStatusHelper.js +16 -22
- package/lib/helpers/metaSignatureHelper.js +6 -6
- package/lib/helpers/nerHelper.js +24 -0
- package/lib/helpers/outboundAllowlistHelper.js +51 -0
- package/lib/helpers/patientInformationHelper.js +20 -16
- package/lib/helpers/patientMessageHelper.js +79 -0
- package/lib/helpers/patientTaskRulesHelper.js +57 -0
- package/lib/helpers/pausedThreadHelper.js +37 -0
- package/lib/helpers/processHelper.js +47 -16
- package/lib/helpers/sendClaimHelper.js +126 -0
- package/lib/helpers/staffSendHelper.js +4 -0
- package/lib/helpers/templateFlowControllerHelper.js +1 -1
- package/lib/helpers/templateRecoveryHelper.js +66 -8
- package/lib/helpers/triageRecordHelper.js +124 -0
- package/lib/helpers/twilioHelper.js +7 -79
- package/lib/helpers/twilioMediaHelper.js +1 -1
- package/lib/helpers/whatsappHelper.js +3 -1
- package/lib/index.d.ts +844 -34
- package/lib/index.js +169 -11
- package/lib/jobs/ScheduledMessageJob.js +44 -0
- package/lib/jobs/TemplateApprovalJob.js +200 -33
- package/lib/models/agendaMessageModel.js +5 -0
- package/lib/models/airtableArchiveModel.js +225 -0
- package/lib/models/contactGateDecisionModel.js +27 -0
- package/lib/models/contextSyncStateModel.js +26 -0
- package/lib/models/deferredWorkModel.js +24 -0
- package/lib/models/deliveryAttemptModel.js +5 -1
- package/lib/models/escalationReviewModel.js +341 -0
- package/lib/models/flowRoutingModel.js +1 -1
- package/lib/models/messageModel.js +21 -1
- package/lib/models/patientProfileModel.js +24 -0
- package/lib/models/safetyNetPledgeModel.js +31 -0
- package/lib/models/sendClaimModel.js +18 -0
- package/lib/models/templateModel.js +1 -2
- package/lib/models/threadModel.js +7 -0
- package/lib/models/tokenMapModel.js +2 -1
- package/lib/models/writeClaimModel.js +14 -0
- package/lib/observability/telemetry.js +7 -7
- package/lib/providers/NerClient.js +2 -2
- package/lib/queue/QueueAdapter.js +1 -0
- package/lib/queue/RedisQueueAdapter.js +104 -7
- package/lib/routes/index.js +132 -2
- package/lib/services/airtableArchivePlanService.js +197 -0
- package/lib/services/airtableArchiveReadService.js +48 -0
- package/lib/services/airtableArchiveService.js +561 -0
- package/lib/services/airtableMirrorService.js +223 -0
- package/lib/services/airtableService.js +198 -18
- package/lib/services/assistantMessageService.js +140 -0
- package/lib/services/carePlanHistoryService.js +610 -0
- package/lib/services/characterizationOutcomeService.js +294 -0
- package/lib/services/contactGateService.js +178 -0
- package/lib/services/conversationService.js +66 -20
- package/lib/services/dashboard-provider-registry.js +38 -0
- package/lib/services/dashboardService.js +31 -4
- package/lib/services/escalationCaseTaskService.js +134 -0
- package/lib/services/escalationContextService.js +92 -0
- package/lib/services/escalationReviewService.js +2214 -0
- package/lib/services/flowDataExchangeService.js +1 -1
- package/lib/services/globalEntityService.js +1 -1
- package/lib/services/gravePendingService.js +41 -0
- package/lib/services/healthService.js +252 -0
- package/lib/services/heldMessageService.js +141 -0
- package/lib/services/inboundRecoveryService.js +354 -0
- package/lib/services/instructionInFlightService.js +17 -0
- package/lib/services/officeAssistantService.js +217 -0
- package/lib/services/orbisService.js +44 -0
- package/lib/services/patientClinicalStatusService.js +189 -0
- package/lib/services/patientResourceService.js +24 -0
- package/lib/services/patientService.js +28 -16
- package/lib/services/patientTaskService.js +221 -0
- package/lib/services/patientTaskSummaryService.js +93 -0
- package/lib/services/physicianService.js +31 -0
- package/lib/services/preprocessingService.js +18 -6
- package/lib/services/queueReconciliationService.js +161 -0
- package/lib/services/recommendationCarouselService.js +398 -0
- package/lib/services/reviewAlertSweepService.js +99 -0
- package/lib/services/reviewBoardService.js +75 -0
- package/lib/services/reviewDeadlineService.js +116 -0
- package/lib/services/reviewDraftSweepService.js +85 -0
- package/lib/services/teamAlertService.js +140 -0
- package/lib/services/templateService.js +1 -2
- package/lib/{helpers/threadHelper.js → services/threadService.js} +38 -6
- package/lib/services/tokenMapService.js +119 -22
- package/lib/services/toolRegistryService.js +43 -2
- package/lib/services/triageHistoryService.js +128 -0
- package/lib/services/twilioMediaService.js +79 -0
- package/lib/services/undeliverableService.js +36 -0
- package/lib/services/untakenAlertService.js +210 -0
- package/lib/shared/dtos/ClinicalAssertion.js +21 -0
- package/lib/shared/dtos/ClinicalMention.js +4 -0
- package/lib/shared/dtos/ClusterImpression.js +16 -5
- package/lib/shared/dtos/ContingencySafetyNet.js +69 -7
- package/lib/shared/dtos/DispatchedEscalation.js +4 -8
- package/lib/shared/dtos/GradedSymptom.js +2 -0
- package/lib/shared/dtos/Intervention.js +10 -3
- package/lib/shared/dtos/ManagedSymptom.js +40 -11
- package/lib/shared/dtos/NutritionSafetyDecision.js +128 -0
- package/lib/shared/dtos/PalliativeAssessment.js +62 -0
- package/lib/shared/dtos/PalliativeCarePlan.js +47 -0
- package/lib/shared/dtos/PatientRiskAssessment.js +25 -1
- package/lib/shared/dtos/RecommendationPlan.js +102 -0
- package/lib/shared/dtos/RecommendationSafetyGate.js +64 -0
- package/lib/shared/dtos/Reminder.js +2 -2
- package/lib/shared/dtos/RoutingDecision.js +2 -1
- package/lib/shared/dtos/SupportAction.js +28 -0
- package/lib/shared/dtos/SupportRoutingRecommendation.js +124 -0
- package/lib/shared/dtos/TriageCompletion.js +50 -0
- package/lib/shared/dtos/TriageResponse.js +7 -1
- package/lib/storage/MongoStorage.js +10 -1
- package/lib/templates/predefinedTemplates.js +1 -1
- package/lib/templates/templateStructure.js +15 -2
- package/lib/utils/MapCache.js +1 -1
- package/lib/utils/coercionUtils.js +11 -0
- package/lib/utils/concurrencyUtils.js +13 -0
- package/lib/utils/dateUtils.js +114 -6
- package/lib/utils/errorUtils.js +26 -1
- package/lib/utils/formatUtils.js +43 -37
- package/lib/utils/httpErrorUtils.js +9 -0
- package/lib/utils/intervalSweeper.js +75 -0
- package/lib/utils/jsonUtils.js +51 -0
- package/lib/utils/logger.js +8 -6
- package/lib/utils/paginationUtils.js +30 -0
- package/lib/utils/retryUtils.js +9 -1
- package/lib/utils/sanitizerUtils.js +87 -1
- package/lib/utils/scheduleUtils.js +70 -1
- package/lib/utils/shadowScope.js +13 -0
- package/lib/utils/statsUtils.js +21 -0
- package/lib/utils/textMatchUtils.js +76 -0
- package/lib/utils/timeoutUtils.js +16 -0
- package/lib/utils/tokenMapUtils.js +3 -3
- package/package.json +11 -11
- package/lib/clinical/helpers/divergenceHelper.js +0 -100
- package/lib/clinical/models/divergenceModel.js +0 -41
- package/lib/clinical/services/clinicalAgentService.js +0 -18
- package/lib/clinical/services/divergenceService.js +0 -90
- package/lib/core/workflowRunner.js +0 -35
- package/lib/fhir/resources/Appointment.js +0 -28
- package/lib/fhir/resources/MedicationStatement.js +0 -42
- package/lib/fhir/resources/Procedure.js +0 -30
- package/lib/services/twilioService.js +0 -13
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const FINDING_CODES = [
|
|
6
|
+
'cannot_eat',
|
|
7
|
+
'cannot_keep_fluids',
|
|
8
|
+
'bleeding',
|
|
9
|
+
'severe_abdominal_pain',
|
|
10
|
+
];
|
|
11
|
+
const FINDING_VALUES = ['yes', 'no', 'unknown'];
|
|
12
|
+
const FINDING_TO_QUESTION = Object.freeze({
|
|
13
|
+
cannot_eat: 'can_eat',
|
|
14
|
+
cannot_keep_fluids: 'can_keep_fluids',
|
|
15
|
+
bleeding: 'bleeding',
|
|
16
|
+
severe_abdominal_pain: 'severe_abdominal_pain',
|
|
17
|
+
});
|
|
18
|
+
const QUESTION_CODES = Object.freeze(FINDING_CODES.map(code => FINDING_TO_QUESTION[code]));
|
|
19
|
+
const EVIDENCE_SOURCE_TYPES = ['chat', 'flow', 'historical', 'forecast'];
|
|
20
|
+
const CURRENT_EVIDENCE_SOURCE_TYPES = new Set(['chat', 'flow']);
|
|
21
|
+
const DISPOSITIONS = ['clear', 'clarify', 'escalate', 'review_required'];
|
|
22
|
+
|
|
23
|
+
const findingsSchema = z.strictObject(Object.fromEntries(
|
|
24
|
+
FINDING_CODES.map(code => [code, z.enum(FINDING_VALUES)]),
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
const evidenceRefSchema = z.strictObject({
|
|
28
|
+
finding: z.enum(FINDING_CODES),
|
|
29
|
+
source_type: z.enum(EVIDENCE_SOURCE_TYPES),
|
|
30
|
+
source_id: z.string().min(1),
|
|
31
|
+
observed_at: z.string().datetime({ offset: true }),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const schema = z.strictObject({
|
|
35
|
+
submission_revision: z.number().int().positive(),
|
|
36
|
+
screen_revision: z.number().int().nonnegative(),
|
|
37
|
+
findings: findingsSchema,
|
|
38
|
+
evidence_refs: z.array(evidenceRefSchema).min(FINDING_CODES.length),
|
|
39
|
+
questions_needed: z.array(z.enum(QUESTION_CODES)).max(QUESTION_CODES.length)
|
|
40
|
+
.refine(values => new Set(values).size === values.length, 'question codes must be unique'),
|
|
41
|
+
disposition: z.enum(DISPOSITIONS),
|
|
42
|
+
}).superRefine((value, ctx) => {
|
|
43
|
+
const unknown = FINDING_CODES.filter(code => value.findings[code] === 'unknown');
|
|
44
|
+
const yes = FINDING_CODES.filter(code => value.findings[code] === 'yes');
|
|
45
|
+
const questions = new Set(value.questions_needed);
|
|
46
|
+
for (const finding of FINDING_CODES) {
|
|
47
|
+
const references = value.evidence_refs.filter(reference => reference.finding === finding);
|
|
48
|
+
if (references.length === 0) {
|
|
49
|
+
ctx.addIssue({
|
|
50
|
+
code: 'custom',
|
|
51
|
+
path: ['evidence_refs'],
|
|
52
|
+
message: `evidence is required for ${finding}`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (value.findings[finding] !== 'unknown'
|
|
56
|
+
&& !references.some(reference => CURRENT_EVIDENCE_SOURCE_TYPES.has(reference.source_type))) {
|
|
57
|
+
ctx.addIssue({
|
|
58
|
+
code: 'custom',
|
|
59
|
+
path: ['evidence_refs'],
|
|
60
|
+
message: `${finding} requires current Flow or active chat evidence`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (value.findings[finding] !== 'unknown'
|
|
64
|
+
&& references.some(reference => !CURRENT_EVIDENCE_SOURCE_TYPES.has(reference.source_type))) {
|
|
65
|
+
ctx.addIssue({
|
|
66
|
+
code: 'custom',
|
|
67
|
+
path: ['evidence_refs'],
|
|
68
|
+
message: 'historical and forecast evidence may only support unknown findings',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (value.disposition === 'clear') {
|
|
73
|
+
if (FINDING_CODES.some(code => value.findings[code] !== 'no')) {
|
|
74
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'clear requires every finding to be no' });
|
|
75
|
+
}
|
|
76
|
+
if (value.questions_needed.length > 0) {
|
|
77
|
+
ctx.addIssue({ code: 'custom', path: ['questions_needed'], message: 'clear cannot request questions' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (value.disposition === 'clarify') {
|
|
81
|
+
const expectedQuestions = unknown.map(code => FINDING_TO_QUESTION[code]);
|
|
82
|
+
if (unknown.length === 0
|
|
83
|
+
|| expectedQuestions.some(code => !questions.has(code))
|
|
84
|
+
|| questions.size !== expectedQuestions.length) {
|
|
85
|
+
ctx.addIssue({ code: 'custom', path: ['questions_needed'], message: 'clarify must request every and only unknown finding' });
|
|
86
|
+
}
|
|
87
|
+
if (yes.length > 0) {
|
|
88
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'a confirmed warning requires escalation' });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (value.disposition === 'review_required' && yes.length > 0) {
|
|
92
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'a confirmed warning requires escalation' });
|
|
93
|
+
}
|
|
94
|
+
if (value.disposition === 'escalate') {
|
|
95
|
+
if (yes.length === 0) {
|
|
96
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'escalate requires a confirmed warning finding' });
|
|
97
|
+
}
|
|
98
|
+
if (value.questions_needed.length > 0) {
|
|
99
|
+
ctx.addIssue({ code: 'custom', path: ['questions_needed'], message: 'escalate cannot request questions' });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}).transform(value => ({
|
|
103
|
+
submissionRevision: value.submission_revision,
|
|
104
|
+
screenRevision: value.screen_revision,
|
|
105
|
+
findings: value.findings,
|
|
106
|
+
evidenceRefs: value.evidence_refs.map(reference => ({
|
|
107
|
+
finding: reference.finding,
|
|
108
|
+
sourceType: reference.source_type,
|
|
109
|
+
sourceId: reference.source_id,
|
|
110
|
+
observedAt: reference.observed_at,
|
|
111
|
+
})),
|
|
112
|
+
questionsNeeded: value.questions_needed,
|
|
113
|
+
disposition: value.disposition,
|
|
114
|
+
}));
|
|
115
|
+
|
|
116
|
+
class NutritionSafetyDecision extends BaseDto {}
|
|
117
|
+
|
|
118
|
+
NutritionSafetyDecision.schema = schema;
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
NutritionSafetyDecision,
|
|
122
|
+
FINDING_CODES,
|
|
123
|
+
FINDING_VALUES,
|
|
124
|
+
FINDING_TO_QUESTION,
|
|
125
|
+
QUESTION_CODES,
|
|
126
|
+
EVIDENCE_SOURCE_TYPES,
|
|
127
|
+
DISPOSITIONS,
|
|
128
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const dateTime = z.iso.datetime({ offset: true });
|
|
6
|
+
|
|
7
|
+
const escalationSchema = z.strictObject({
|
|
8
|
+
patientId: z.string(),
|
|
9
|
+
maxActionTimeHours: z.number().int().min(1).max(24),
|
|
10
|
+
escalationRoutes: z.array(z.string()).default([]),
|
|
11
|
+
escalationReason: z.string(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const findingSchema = z.strictObject({
|
|
15
|
+
rank: z.number().int().min(1),
|
|
16
|
+
elementType: z.enum(['cluster', 'individual']),
|
|
17
|
+
nameShort: z.string().min(1),
|
|
18
|
+
timeWindow: z.string().default(''),
|
|
19
|
+
symptomTerms: z.array(z.string()).default([]),
|
|
20
|
+
clinicalDescription: z.string().default(''),
|
|
21
|
+
whyRelevant: z.string().default(''),
|
|
22
|
+
qolImpact: z.enum(['Low', 'Medium', 'High']).nullable().default(null),
|
|
23
|
+
qolCriteria: z.string().default(''),
|
|
24
|
+
improvementCapacity: z.enum(['Low', 'Medium', 'High']).nullable().default(null),
|
|
25
|
+
improvementCriteria: z.string().default(''),
|
|
26
|
+
areMedsNeeded: z.boolean().nullable().default(null),
|
|
27
|
+
needsCharacterization: z.boolean().nullable().default(null),
|
|
28
|
+
characterizationCriteria: z.string().default(''),
|
|
29
|
+
probeQuestions: z.array(z.string()).default([]),
|
|
30
|
+
auditNotes: z.string().default(''),
|
|
31
|
+
clusterNote: z.string().nullable().default(null),
|
|
32
|
+
escalation: escalationSchema.nullable().default(null),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const schema = z.strictObject({
|
|
36
|
+
schemaVersion: z.string().default('1'),
|
|
37
|
+
assessmentId: z.string(),
|
|
38
|
+
patientId: z.string(),
|
|
39
|
+
turnId: z.string(),
|
|
40
|
+
committedAt: dateTime,
|
|
41
|
+
evaluationSummary: z.string().default(''),
|
|
42
|
+
rankingRationale: z.string().default(''),
|
|
43
|
+
escalationReason: z.string().nullable().default(null),
|
|
44
|
+
findings: z.array(findingSchema).default([]).refine(hasContiguousRanks, {
|
|
45
|
+
message: 'findings ranks must be unique and contiguous 1..N',
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function hasContiguousRanks(findings) {
|
|
50
|
+
const ranks = new Set(findings.map((finding) => finding.rank));
|
|
51
|
+
if (ranks.size !== findings.length) return false;
|
|
52
|
+
for (let expected = 1; expected <= findings.length; expected += 1) {
|
|
53
|
+
if (!ranks.has(expected)) return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class PalliativeAssessment extends BaseDto {}
|
|
59
|
+
|
|
60
|
+
PalliativeAssessment.schema = schema;
|
|
61
|
+
|
|
62
|
+
module.exports = { PalliativeAssessment };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const dateTime = z.iso.datetime({ offset: true });
|
|
6
|
+
|
|
7
|
+
const followupSchema = z.strictObject({
|
|
8
|
+
type: z.string().nullable().default(null),
|
|
9
|
+
urgency: z.string().nullable().default(null),
|
|
10
|
+
}).nullable().default(null);
|
|
11
|
+
|
|
12
|
+
const otcOfferSchema = z.strictObject({
|
|
13
|
+
label: z.string(),
|
|
14
|
+
dose: z.string().nullable().default(null),
|
|
15
|
+
frequency: z.string().nullable().default(null),
|
|
16
|
+
duration: z.string().nullable().default(null),
|
|
17
|
+
warnings: z.array(z.string()).default([]),
|
|
18
|
+
}).nullable().default(null);
|
|
19
|
+
|
|
20
|
+
const recommendationSchema = z.strictObject({
|
|
21
|
+
rank: z.number().int().min(1),
|
|
22
|
+
elementNameShort: z.string().min(1),
|
|
23
|
+
isPharmacologicalMedNeeded: z.boolean().nullable().default(null),
|
|
24
|
+
ctcaeTerms: z.array(z.string()).default([]),
|
|
25
|
+
mainRecommendation: z.string().nullable().default(null),
|
|
26
|
+
otcOffer: otcOfferSchema,
|
|
27
|
+
followup: followupSchema,
|
|
28
|
+
whenToEscalate: z.string().nullable().default(null),
|
|
29
|
+
expectedEffectiveness: z.string().nullable().default(null),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const schema = z.strictObject({
|
|
33
|
+
schemaVersion: z.string().default('1'),
|
|
34
|
+
careplanId: z.string(),
|
|
35
|
+
patientId: z.string(),
|
|
36
|
+
turnId: z.string(),
|
|
37
|
+
assessmentId: z.string(),
|
|
38
|
+
committedAt: dateTime,
|
|
39
|
+
summary: z.string().nullable().default(null),
|
|
40
|
+
recommendations: z.array(recommendationSchema).default([]),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
class PalliativeCarePlan extends BaseDto {}
|
|
44
|
+
|
|
45
|
+
PalliativeCarePlan.schema = schema;
|
|
46
|
+
|
|
47
|
+
module.exports = { PalliativeCarePlan };
|
|
@@ -7,6 +7,7 @@ const dateTime = z.iso.datetime({ offset: true });
|
|
|
7
7
|
const predictedAeSchema = z.strictObject({
|
|
8
8
|
aeName: z.string(),
|
|
9
9
|
severityIfConfirmed: z.enum(['emergency', 'safety_relevant', 'moderate']),
|
|
10
|
+
relatedSymptomTerms: z.array(z.string()).default([]),
|
|
10
11
|
minimumSymptomSet: z.array(z.string()).default([]),
|
|
11
12
|
why: z.string().nullable().default(null),
|
|
12
13
|
});
|
|
@@ -15,6 +16,7 @@ const predictedDiseaseRiskSchema = z.strictObject({
|
|
|
15
16
|
bodySite: z.string(),
|
|
16
17
|
complications: z.array(z.string()).default([]),
|
|
17
18
|
warningSymptoms: z.array(z.string()).default([]),
|
|
19
|
+
relatedSymptomTerms: z.array(z.string()).default([]),
|
|
18
20
|
amplifierComorbidities: z.array(z.string()).default([]),
|
|
19
21
|
});
|
|
20
22
|
|
|
@@ -24,8 +26,23 @@ const predictedComorbidityAmplifierSchema = z.strictObject({
|
|
|
24
26
|
clinicalNote: z.string().nullable().default(null),
|
|
25
27
|
});
|
|
26
28
|
|
|
29
|
+
const changeFromPreviousSchema = z.strictObject({
|
|
30
|
+
changeType: z.enum([
|
|
31
|
+
'created',
|
|
32
|
+
'unchanged',
|
|
33
|
+
'increased',
|
|
34
|
+
'decreased',
|
|
35
|
+
'materially-reframed',
|
|
36
|
+
]),
|
|
37
|
+
direction: z.enum(['up', 'down', 'none']).default('none'),
|
|
38
|
+
materialChange: z.boolean().default(false),
|
|
39
|
+
reasonsForChange: z.array(z.string()).default([]),
|
|
40
|
+
newInformation: z.array(z.string()).default([]),
|
|
41
|
+
resolvedInformation: z.array(z.string()).default([]),
|
|
42
|
+
});
|
|
43
|
+
|
|
27
44
|
const schema = z.strictObject({
|
|
28
|
-
schemaVersion: z.string().default('
|
|
45
|
+
schemaVersion: z.string().default('2'),
|
|
29
46
|
assessmentId: z.string(),
|
|
30
47
|
patientId: z.string(),
|
|
31
48
|
status: z.literal('final').default('final'),
|
|
@@ -37,6 +54,13 @@ const schema = z.strictObject({
|
|
|
37
54
|
comorbidityAmplifiers: z.array(predictedComorbidityAmplifierSchema).default([]),
|
|
38
55
|
assessedAt: dateTime,
|
|
39
56
|
assessedByModel: z.string().nullable().default(null),
|
|
57
|
+
derivedFrom: z.string().nullable().default(null),
|
|
58
|
+
validUntil: dateTime.nullable().default(null),
|
|
59
|
+
sourceDataCutoff: dateTime.nullable().default(null),
|
|
60
|
+
assessmentTrigger: z.string().nullable().default(null),
|
|
61
|
+
methodVersion: z.string().nullable().default(null),
|
|
62
|
+
missingInformation: z.array(z.string()).default([]),
|
|
63
|
+
changeFromPrevious: changeFromPreviousSchema.nullable().default(null),
|
|
40
64
|
});
|
|
41
65
|
|
|
42
66
|
class PatientRiskAssessment extends BaseDto {}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const dateTime = z.iso.datetime({ offset: true });
|
|
6
|
+
|
|
7
|
+
const ELEMENT_TYPES = ['cluster', 'individual'];
|
|
8
|
+
const SYMPTOM_STATUSES = ['confirmed', 'suspected', 'denied'];
|
|
9
|
+
const PALLIATIVE_ROUTES = ['equipo_medico_tratante', 'abordaje_onco_nutricion', 'abordaje_psico_onco'];
|
|
10
|
+
const QOL_CATEGORIES = ['low', 'moderate', 'high'];
|
|
11
|
+
const EFFECTIVENESS = ['low', 'medium', 'high'];
|
|
12
|
+
const FOLLOWUP_TYPES = ['checkin_48h', 'team_referral', 'none'];
|
|
13
|
+
|
|
14
|
+
const symptomSchema = z.strictObject({
|
|
15
|
+
ctcaeTerm: z.string(),
|
|
16
|
+
grade: z.number().int().min(1).max(5).nullable().default(null),
|
|
17
|
+
verificationStatus: z.enum(SYMPTOM_STATUSES),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const escalationSchema = z.strictObject({
|
|
21
|
+
urgentUnder24h: z.boolean().default(false),
|
|
22
|
+
maxActionTimeHours: z.number().int().min(1).max(24).nullable().default(null),
|
|
23
|
+
routes: z.array(z.enum(PALLIATIVE_ROUTES)).default([]),
|
|
24
|
+
clinicalCriteria: z.string().nullable().default(null),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const otcOfferSchema = z.strictObject({
|
|
28
|
+
label: z.string(),
|
|
29
|
+
dose: z.string().nullable().default(null),
|
|
30
|
+
frequency: z.string().nullable().default(null),
|
|
31
|
+
duration: z.string().nullable().default(null),
|
|
32
|
+
warnings: z.string().nullable().default(null),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const patientSchema = z.strictObject({
|
|
36
|
+
mainRecommendation: z.string(),
|
|
37
|
+
whenToEscalate: z.string().nullable().default(null),
|
|
38
|
+
contraindications: z.string().nullable().default(null),
|
|
39
|
+
expectedEffectiveness: z.enum(EFFECTIVENESS).nullable().default(null),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const recommendationSchema = z.strictObject({
|
|
43
|
+
symptomsPatientFacing: z.array(z.string()).min(1).max(6),
|
|
44
|
+
isPharmacologicalMedNeeded: z.boolean(),
|
|
45
|
+
patient: patientSchema,
|
|
46
|
+
otcOffer: otcOfferSchema.nullable().default(null),
|
|
47
|
+
followup: z.enum(FOLLOWUP_TYPES).nullable().default(null),
|
|
48
|
+
followupUrgency: z.string().nullable().default(null),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const elementSchema = z.strictObject({
|
|
52
|
+
rank: z.number().int().min(1),
|
|
53
|
+
type: z.enum(ELEMENT_TYPES),
|
|
54
|
+
nameShort: z.string(),
|
|
55
|
+
timeWindow: z.string().nullable().default(null),
|
|
56
|
+
symptoms: z.array(symptomSchema).default([]),
|
|
57
|
+
targetedCtcaeTerms: z.array(z.string()).min(1),
|
|
58
|
+
whyRelevant: z.string(),
|
|
59
|
+
qolImpact: z.enum(QOL_CATEGORIES).nullable().default(null),
|
|
60
|
+
improvementCapacity: z.enum(QOL_CATEGORIES).nullable().default(null),
|
|
61
|
+
characterizationNeeded: z.boolean().nullable().default(null),
|
|
62
|
+
minCharacterizationVariables: z.array(z.string()).default([]),
|
|
63
|
+
escalation: escalationSchema,
|
|
64
|
+
recommendation: recommendationSchema,
|
|
65
|
+
groundedIn: z.array(z.string()).default([]),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const takeawaysSchema = z.strictObject({
|
|
69
|
+
safetyConfirmationNeeded: z.boolean().default(false),
|
|
70
|
+
safetyConfirmationQuestion: z.string().nullable().default(null),
|
|
71
|
+
vitalRiskPossibleNow: z.boolean().default(false),
|
|
72
|
+
summaryPatientFacing: z.string(),
|
|
73
|
+
summaryInternal: z.string(),
|
|
74
|
+
})
|
|
75
|
+
.refine(
|
|
76
|
+
(t) => !t.safetyConfirmationNeeded || Boolean(t.safetyConfirmationQuestion && t.safetyConfirmationQuestion.trim()),
|
|
77
|
+
{ path: ['safetyConfirmationQuestion'], message: 'safetyConfirmationNeeded=true ⇒ exactamente 1 pregunta cerrada' },
|
|
78
|
+
)
|
|
79
|
+
.refine(
|
|
80
|
+
(t) => t.safetyConfirmationNeeded || !t.safetyConfirmationQuestion,
|
|
81
|
+
{ path: ['safetyConfirmationQuestion'], message: 'safetyConfirmationNeeded=false ⇒ null' },
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
const schema = z.strictObject({
|
|
85
|
+
schemaVersion: z.string().default('1'),
|
|
86
|
+
runId: z.string(),
|
|
87
|
+
patientId: z.string(),
|
|
88
|
+
origin: z.enum(['chat', 'triage']).default('chat'),
|
|
89
|
+
turnId: z.string(),
|
|
90
|
+
takeaways: takeawaysSchema,
|
|
91
|
+
elements: z.array(elementSchema).min(1),
|
|
92
|
+
createdAt: dateTime,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
class RecommendationPlan extends BaseDto {}
|
|
96
|
+
|
|
97
|
+
RecommendationPlan.schema = schema;
|
|
98
|
+
|
|
99
|
+
module.exports = {
|
|
100
|
+
RecommendationPlan,
|
|
101
|
+
PALLIATIVE_ROUTES,
|
|
102
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const dateTime = z.iso.datetime({ offset: true });
|
|
6
|
+
|
|
7
|
+
const ESCALATION_ROUTES = ['emergencia', 'urgencias', 'equipo_tratante_hoy'];
|
|
8
|
+
const RED_FLAG_STATUSES = ['confirmed', 'partially_confirmed', 'inconclusive', 'denied'];
|
|
9
|
+
const RISK_PROBABILITIES = ['high', 'medium', 'low'];
|
|
10
|
+
|
|
11
|
+
const relatedAeSchema = z.strictObject({
|
|
12
|
+
ctcaeTerm: z.string(),
|
|
13
|
+
probabilityGivenPatient: z.enum(RISK_PROBABILITIES),
|
|
14
|
+
whyIsRelevant: z.string(),
|
|
15
|
+
groundedIn: z.array(z.string()).default([]),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const redFlagEventSchema = z.strictObject({
|
|
19
|
+
clinicalEvent: z.string(),
|
|
20
|
+
ctcaeGradesReference: z.array(z.number().int()).default([]),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const redFlagSchema = z.strictObject({
|
|
24
|
+
name: z.string(),
|
|
25
|
+
verificationStatus: z.enum(RED_FLAG_STATUSES),
|
|
26
|
+
escalationRoute: z.enum(ESCALATION_ROUTES).nullable().default(null),
|
|
27
|
+
eventsConfirmed: z.array(z.string()).default([]),
|
|
28
|
+
eventsDenied: z.array(z.string()).default([]),
|
|
29
|
+
relatedAes: z.array(relatedAeSchema).default([]),
|
|
30
|
+
definition: z.array(redFlagEventSchema).default([]),
|
|
31
|
+
groundedIn: z.array(z.string()).default([]),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const schema = z.strictObject({
|
|
35
|
+
schemaVersion: z.string().default('1'),
|
|
36
|
+
runId: z.string(),
|
|
37
|
+
patientId: z.string(),
|
|
38
|
+
origin: z.enum(['chat', 'triage']).default('chat'),
|
|
39
|
+
turnId: z.string(),
|
|
40
|
+
urgentUnder24h: z.boolean(),
|
|
41
|
+
maxActionTimeHours: z.number().int().min(1).max(24).nullable().default(null),
|
|
42
|
+
escalationRoute: z.enum(ESCALATION_ROUTES).nullable().default(null),
|
|
43
|
+
reasonForEscalation: z.string().nullable().default(null),
|
|
44
|
+
summary: z.string(),
|
|
45
|
+
redFlags: z.array(redFlagSchema).default([]),
|
|
46
|
+
createdAt: dateTime,
|
|
47
|
+
})
|
|
48
|
+
.refine((g) => !g.urgentUnder24h || g.maxActionTimeHours !== null, {
|
|
49
|
+
message: 'urgent gate requires maxActionTimeHours',
|
|
50
|
+
})
|
|
51
|
+
.refine((g) => !g.urgentUnder24h || g.escalationRoute !== null, {
|
|
52
|
+
message: 'urgent gate requires escalationRoute',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
class RecommendationSafetyGate extends BaseDto {}
|
|
56
|
+
|
|
57
|
+
RecommendationSafetyGate.schema = schema;
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
RecommendationSafetyGate,
|
|
61
|
+
ESCALATION_ROUTES,
|
|
62
|
+
RED_FLAG_STATUSES,
|
|
63
|
+
RISK_PROBABILITIES,
|
|
64
|
+
};
|
|
@@ -21,8 +21,8 @@ const schema = z.strictObject({
|
|
|
21
21
|
.refine((d) => (d.status === 'cancelled') === (d.cancelReason !== null), {
|
|
22
22
|
message: 'cancelReason is set iff status is cancelled',
|
|
23
23
|
})
|
|
24
|
-
.refine((d) => d.recipientKind !== 'related_person' || d.recipientRefId
|
|
25
|
-
message: 'a related_person recipient requires recipientRefId',
|
|
24
|
+
.refine((d) => d.recipientKind !== 'related_person' || (typeof d.recipientRefId === 'string' && d.recipientRefId.length > 0), {
|
|
25
|
+
message: 'a related_person recipient requires a non-empty recipientRefId',
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
class Reminder extends BaseDto {}
|
|
@@ -5,7 +5,8 @@ const { BaseDto } = require('./BaseDto');
|
|
|
5
5
|
const dateTime = z.iso.datetime({ offset: true });
|
|
6
6
|
|
|
7
7
|
const mentionFindingSchema = z.strictObject({
|
|
8
|
-
|
|
8
|
+
// null when the mention opened/updated no case (medication, appointment, allergy, emotion); absence is stored as absence, not a sentinel.
|
|
9
|
+
caseId: z.string().nullable().default(null),
|
|
9
10
|
clinicalReasoning: z.string(),
|
|
10
11
|
decisionAction: z.string(),
|
|
11
12
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const actionSchema = z.strictObject({
|
|
6
|
+
candidateId: z.string().min(1),
|
|
7
|
+
service: z.enum(['nutrition', 'psychology']),
|
|
8
|
+
type: z.enum(['group_registration', 'urgent_nutrition_intake']),
|
|
9
|
+
invitationClass: z.enum(['first', 'followup']).nullable().default(null),
|
|
10
|
+
idempotencyKey: z.string().min(1).nullable().optional(),
|
|
11
|
+
targetKey: z.string().min(1),
|
|
12
|
+
priority: z.enum(['routine', 'soon', 'urgent']),
|
|
13
|
+
}).refine((action) => action.type !== 'group_registration' || Boolean(action.idempotencyKey), {
|
|
14
|
+
path: ['idempotencyKey'], message: 'group registration requires idempotencyKey',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const supportActionSchema = z.strictObject({
|
|
18
|
+
schemaVersion: z.literal('1'),
|
|
19
|
+
patientId: z.string().min(1),
|
|
20
|
+
sourceId: z.string().min(1),
|
|
21
|
+
actions: z.array(actionSchema).min(1).max(3),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
class SupportAction extends BaseDto {}
|
|
25
|
+
|
|
26
|
+
SupportAction.schema = supportActionSchema;
|
|
27
|
+
|
|
28
|
+
module.exports = { SupportAction };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { z } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { BaseDto } = require('./BaseDto');
|
|
4
|
+
|
|
5
|
+
const dateTime = z.iso.datetime({ offset: true });
|
|
6
|
+
const PRIORITIES = ['routine', 'soon', 'urgent'];
|
|
7
|
+
const DISPOSITIONS = ['group', 'individual', 'escalated', 'reviewRequired', 'none'];
|
|
8
|
+
|
|
9
|
+
const evidenceSchema = z.strictObject({
|
|
10
|
+
source: z.enum(['triage', 'chat', 'fhir', 'airtable']),
|
|
11
|
+
sourceId: z.string().min(1),
|
|
12
|
+
code: z.string().min(1),
|
|
13
|
+
summary: z.string().max(300).nullable().default(null),
|
|
14
|
+
confidence: z.number().min(0).max(1).nullable().default(null),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const safetySchema = z.strictObject({
|
|
18
|
+
suicidalIdeation: z.boolean().default(false),
|
|
19
|
+
immediateRisk: z.boolean().default(false),
|
|
20
|
+
urgentMedicalRisk: z.boolean().default(false),
|
|
21
|
+
needsHumanConfirmation: z.boolean().default(false),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const decisionBase = {
|
|
25
|
+
disposition: z.enum(DISPOSITIONS),
|
|
26
|
+
groupEligible: z.boolean(),
|
|
27
|
+
priority: z.enum(PRIORITIES).default('routine'),
|
|
28
|
+
confidence: z.number().min(0).max(1),
|
|
29
|
+
reasonCodes: z.array(z.string().min(1)).max(20).default([]),
|
|
30
|
+
evidence: z.array(evidenceSchema).min(1).max(20),
|
|
31
|
+
safety: safetySchema,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const nutritionDecisionSchema = z.strictObject({
|
|
35
|
+
service: z.literal('nutrition'),
|
|
36
|
+
nutritionRisk: z.enum(['green', 'yellow', 'red', 'unknown']),
|
|
37
|
+
urgentIntakeEligible: z.boolean(),
|
|
38
|
+
...decisionBase,
|
|
39
|
+
}).superRefine((decision, ctx) => {
|
|
40
|
+
const expected = {
|
|
41
|
+
green: { eligible: true, urgentIntakeEligible: false, dispositions: ['group'] },
|
|
42
|
+
yellow: { eligible: null, urgentIntakeEligible: true, dispositions: ['individual'] },
|
|
43
|
+
red: { eligible: false, urgentIntakeEligible: false, dispositions: ['escalated'] },
|
|
44
|
+
unknown: { eligible: false, urgentIntakeEligible: false, dispositions: ['reviewRequired'] },
|
|
45
|
+
}[decision.nutritionRisk];
|
|
46
|
+
if (expected.eligible !== null && decision.groupEligible !== expected.eligible) {
|
|
47
|
+
ctx.addIssue({ code: 'custom', path: ['groupEligible'], message: `nutrition ${decision.nutritionRisk} has invalid group eligibility` });
|
|
48
|
+
}
|
|
49
|
+
if (decision.urgentIntakeEligible !== expected.urgentIntakeEligible) {
|
|
50
|
+
ctx.addIssue({ code: 'custom', path: ['urgentIntakeEligible'], message: `nutrition ${decision.nutritionRisk} has invalid urgent intake eligibility` });
|
|
51
|
+
}
|
|
52
|
+
if (!expected.dispositions.includes(decision.disposition)) {
|
|
53
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: `nutrition ${decision.nutritionRisk} has invalid disposition` });
|
|
54
|
+
}
|
|
55
|
+
if (!decision.safety.urgentMedicalRisk) {
|
|
56
|
+
if (decision.disposition === 'escalated') {
|
|
57
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'nutrition escalation requires urgent medical risk' });
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (decision.disposition !== 'escalated') {
|
|
62
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'urgent medical risk permits escalation only' });
|
|
63
|
+
}
|
|
64
|
+
if (decision.groupEligible) {
|
|
65
|
+
ctx.addIssue({ code: 'custom', path: ['groupEligible'], message: 'urgent medical risk cannot be group eligible' });
|
|
66
|
+
}
|
|
67
|
+
if (decision.urgentIntakeEligible) {
|
|
68
|
+
ctx.addIssue({ code: 'custom', path: ['urgentIntakeEligible'], message: 'urgent medical risk cannot be urgent intake eligible' });
|
|
69
|
+
}
|
|
70
|
+
if (decision.priority !== 'urgent') {
|
|
71
|
+
ctx.addIssue({ code: 'custom', path: ['priority'], message: 'urgent medical risk requires urgent priority' });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const psychologyDecisionSchema = z.strictObject({
|
|
76
|
+
service: z.literal('psychology'),
|
|
77
|
+
psychologyRisk: z.enum(['green', 'orange', 'red', 'unknown']),
|
|
78
|
+
...decisionBase,
|
|
79
|
+
}).superRefine((decision, ctx) => {
|
|
80
|
+
const expected = {
|
|
81
|
+
green: { eligible: true, dispositions: ['group'] },
|
|
82
|
+
orange: { eligible: false, dispositions: ['individual'] },
|
|
83
|
+
red: { eligible: false, dispositions: ['escalated'] },
|
|
84
|
+
unknown: { eligible: false, dispositions: ['reviewRequired'] },
|
|
85
|
+
}[decision.psychologyRisk];
|
|
86
|
+
if (decision.groupEligible !== expected.eligible) {
|
|
87
|
+
ctx.addIssue({ code: 'custom', path: ['groupEligible'], message: `psychology ${decision.psychologyRisk} has invalid group eligibility` });
|
|
88
|
+
}
|
|
89
|
+
if (!expected.dispositions.includes(decision.disposition)) {
|
|
90
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: `psychology ${decision.psychologyRisk} has invalid disposition` });
|
|
91
|
+
}
|
|
92
|
+
if ((decision.safety.suicidalIdeation || decision.safety.immediateRisk) && decision.psychologyRisk !== 'red') {
|
|
93
|
+
ctx.addIssue({ code: 'custom', path: ['psychologyRisk'], message: 'immediate or suicidal risk must be red' });
|
|
94
|
+
}
|
|
95
|
+
if ((decision.safety.suicidalIdeation || decision.safety.immediateRisk) && decision.priority !== 'urgent') {
|
|
96
|
+
ctx.addIssue({ code: 'custom', path: ['priority'], message: 'immediate or suicidal risk requires urgent priority' });
|
|
97
|
+
}
|
|
98
|
+
if ((decision.safety.suicidalIdeation || decision.safety.immediateRisk) && decision.disposition !== 'escalated') {
|
|
99
|
+
ctx.addIssue({ code: 'custom', path: ['disposition'], message: 'immediate or suicidal risk requires escalation' });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const schema = z.strictObject({
|
|
104
|
+
schemaVersion: z.string().default('1'),
|
|
105
|
+
decisionVersion: z.string().default('support-routing-v1'),
|
|
106
|
+
patientId: z.string().trim().min(1),
|
|
107
|
+
origin: z.enum(['triage', 'chat', 'fhir']),
|
|
108
|
+
sourceId: z.string().min(1),
|
|
109
|
+
createdAt: dateTime,
|
|
110
|
+
decisions: z.array(z.union([nutritionDecisionSchema, psychologyDecisionSchema])).max(2),
|
|
111
|
+
}).superRefine((recommendation, ctx) => {
|
|
112
|
+
const services = recommendation.decisions.map((decision) => decision.service);
|
|
113
|
+
if (new Set(services).size !== services.length) {
|
|
114
|
+
ctx.addIssue({ code: 'custom', path: ['decisions'], message: 'only one decision per service is allowed' });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
class SupportRoutingRecommendation extends BaseDto {}
|
|
119
|
+
|
|
120
|
+
SupportRoutingRecommendation.schema = schema;
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
SupportRoutingRecommendation,
|
|
124
|
+
};
|