@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,380 @@
|
|
|
1
|
+
const { createHash, randomBytes } = require('crypto');
|
|
2
|
+
|
|
3
|
+
const { getSystems } = require('../config/fhirConfig');
|
|
4
|
+
const { codeableConcept, extension, reference, toInstant, patientReference } = require('../helpers/elementHelper');
|
|
5
|
+
const { baseResource, problemListCategory, provenance } = require('../helpers/resourceHelper');
|
|
6
|
+
const { extensionUrl } = require('../helpers/fhirHelper');
|
|
7
|
+
const { extMap, identifierValue } = require('../helpers/fhirReadHelper');
|
|
8
|
+
const { KIND_TO_RESOURCE_TYPE, VARIABLE_REGISTRY, NO_KNOWN_ALLERGY } = require('../constants/variableRegistry');
|
|
9
|
+
const { foldAccents } = require('../../utils/formatUtils');
|
|
10
|
+
const { CONTEXT_FACT_SLUG } = require('../constants/projectionSlugs');
|
|
11
|
+
const { CONTEXT_EXT } = require('../constants/extensionSlugs');
|
|
12
|
+
const { toIsoInstant } = require('../../utils/dateUtils');
|
|
13
|
+
const { logger } = require('../../utils/logger');
|
|
14
|
+
|
|
15
|
+
const CONDITION_STATUS = {
|
|
16
|
+
active: 'active', activo: 'active', ongoing: 'active', 'en curso': 'active',
|
|
17
|
+
recurrence: 'recurrence', recurrencia: 'recurrence', relapse: 'relapse', recaida: 'relapse',
|
|
18
|
+
remission: 'remission', remision: 'remission', 'en remision': 'remission',
|
|
19
|
+
resolved: 'resolved', resuelto: 'resolved', resuelta: 'resolved',
|
|
20
|
+
completed: 'resolved', completado: 'resolved', ended: 'resolved',
|
|
21
|
+
inactive: 'inactive', inactivo: 'inactive', inactiva: 'inactive',
|
|
22
|
+
cancelled: 'inactive', cancelado: 'inactive',
|
|
23
|
+
suspended: 'inactive', discontinued: 'inactive', paused: 'inactive', not_active: 'inactive',
|
|
24
|
+
past: 'inactive', pasado: 'inactive', previous: 'inactive', previo: 'inactive',
|
|
25
|
+
historical: 'inactive', historico: 'inactive',
|
|
26
|
+
finalizado: 'resolved', end: 'resolved', extirpado: 'resolved', replaced: 'resolved',
|
|
27
|
+
};
|
|
28
|
+
const PROCEDURE_STATUS = {
|
|
29
|
+
planned: 'preparation', planificado: 'preparation', planificada: 'preparation',
|
|
30
|
+
programada: 'preparation', programado: 'preparation',
|
|
31
|
+
ongoing: 'in-progress', 'in-progress': 'in-progress', 'en curso': 'in-progress',
|
|
32
|
+
completed: 'completed', completado: 'completed', completada: 'completed',
|
|
33
|
+
ended: 'completed', realizada: 'completed', realizado: 'completed',
|
|
34
|
+
stopped: 'stopped', suspendido: 'stopped', suspendida: 'stopped',
|
|
35
|
+
suspended: 'stopped', discontinued: 'stopped', not_active: 'stopped',
|
|
36
|
+
paused: 'on-hold', started: 'in-progress',
|
|
37
|
+
finalizado: 'completed', end: 'completed', past: 'completed', previous: 'completed',
|
|
38
|
+
historical: 'completed', historico: 'completed',
|
|
39
|
+
cancelled: 'not-done', cancelado: 'not-done', cancelada: 'not-done',
|
|
40
|
+
};
|
|
41
|
+
const ALLERGY_STATUS = {
|
|
42
|
+
active: 'active', activo: 'active', activa: 'active', ongoing: 'active', 'en curso': 'active',
|
|
43
|
+
inactive: 'inactive', inactivo: 'inactive', inactiva: 'inactive',
|
|
44
|
+
stopped: 'inactive', suspendido: 'inactive', suspendida: 'inactive',
|
|
45
|
+
cancelled: 'inactive', cancelado: 'inactive', cancelada: 'inactive',
|
|
46
|
+
completed: 'inactive', completado: 'inactive', completada: 'inactive', ended: 'inactive',
|
|
47
|
+
suspended: 'inactive', discontinued: 'inactive', paused: 'inactive', not_active: 'inactive',
|
|
48
|
+
finalizado: 'inactive', end: 'inactive', past: 'inactive', previous: 'inactive',
|
|
49
|
+
historical: 'inactive', historico: 'inactive',
|
|
50
|
+
resolved: 'resolved', resuelto: 'resolved', resuelta: 'resolved',
|
|
51
|
+
};
|
|
52
|
+
const SERVICE_STATUS = {
|
|
53
|
+
planned: 'draft', planificado: 'draft', programado: 'draft',
|
|
54
|
+
ongoing: 'active', active: 'active', activo: 'active', 'en curso': 'active',
|
|
55
|
+
completed: 'completed', completado: 'completed', ended: 'completed',
|
|
56
|
+
stopped: 'revoked', suspendido: 'revoked', suspendida: 'revoked',
|
|
57
|
+
suspended: 'revoked', discontinued: 'revoked', not_active: 'revoked',
|
|
58
|
+
paused: 'on-hold',
|
|
59
|
+
finalizado: 'completed', end: 'completed', past: 'completed', previous: 'completed',
|
|
60
|
+
historical: 'completed', historico: 'completed',
|
|
61
|
+
cancelled: 'revoked', cancelado: 'revoked', cancelada: 'revoked',
|
|
62
|
+
};
|
|
63
|
+
const ACTIVITY_TEXT = 'clinical context assertion';
|
|
64
|
+
|
|
65
|
+
const MEDICATION_ADHERENCE = {
|
|
66
|
+
active: 'taking', activo: 'taking', ongoing: 'taking', taking: 'taking', 'en curso': 'taking',
|
|
67
|
+
completed: 'stopped', completado: 'stopped', completada: 'stopped', ended: 'stopped',
|
|
68
|
+
stopped: 'stopped', suspendido: 'stopped', suspendida: 'stopped',
|
|
69
|
+
descontinuado: 'stopped', descontinuada: 'stopped',
|
|
70
|
+
cancelled: 'stopped', cancelado: 'stopped', cancelada: 'stopped',
|
|
71
|
+
suspended: 'stopped', discontinued: 'stopped', not_active: 'stopped',
|
|
72
|
+
finalizado: 'stopped', end: 'stopped', replaced: 'stopped',
|
|
73
|
+
past: 'stopped', previous: 'stopped', historical: 'stopped', historico: 'stopped',
|
|
74
|
+
'on-hold': 'on-hold', 'en pausa': 'on-hold', paused: 'on-hold',
|
|
75
|
+
planned: 'not-taking', planificado: 'not-taking', programado: 'not-taking',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const CONTEXT_RESOURCE_TYPES = [...new Set(Object.values(KIND_TO_RESOURCE_TYPE))];
|
|
79
|
+
|
|
80
|
+
const masculine = (raw) => (raw.endsWith('a') ? `${raw.slice(0, -1)}o` : null);
|
|
81
|
+
|
|
82
|
+
// Model free text, unbounded upstream and about to be logged, so it is cut before either.
|
|
83
|
+
const MAX_STATUS_CHARS = 64;
|
|
84
|
+
|
|
85
|
+
const statusToken = (status) => foldAccents(
|
|
86
|
+
String(status ?? '').trim().toLowerCase().replace(/\s+/g, ' ').slice(0, MAX_STATUS_CHARS),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Salted per process: an unkeyed digest of a guessable phrase is recoverable from the logs.
|
|
90
|
+
const STATUS_SHAPED = /^[a-z][a-z _/-]{0,39}$/;
|
|
91
|
+
const MAX_STATUS_WORDS = 4;
|
|
92
|
+
const REPORT_SALT = randomBytes(16);
|
|
93
|
+
const namesAStatus = (raw) => STATUS_SHAPED.test(raw) && raw.split(' ').length <= MAX_STATUS_WORDS;
|
|
94
|
+
const reportable = (raw) => (namesAStatus(raw)
|
|
95
|
+
? raw
|
|
96
|
+
: `opaque:${createHash('sha256').update(REPORT_SALT).update(raw).digest('hex').slice(0, 12)}`);
|
|
97
|
+
|
|
98
|
+
const unplaceableStatus = new Set();
|
|
99
|
+
const MAX_UNPLACEABLE_LOGGED = 50;
|
|
100
|
+
const REPORT_WINDOW_MS = 60 * 60 * 1000;
|
|
101
|
+
let filledAt = 0;
|
|
102
|
+
|
|
103
|
+
// Forgotten only when the cap suppressed something, or a recurring spelling repeats every window.
|
|
104
|
+
function noteUnplaceable(raw, unrecognised) {
|
|
105
|
+
const status = reportable(raw);
|
|
106
|
+
if (unplaceableStatus.has(status)) return;
|
|
107
|
+
if (unplaceableStatus.size >= MAX_UNPLACEABLE_LOGGED) {
|
|
108
|
+
if (Date.now() - filledAt < REPORT_WINDOW_MS) return;
|
|
109
|
+
logger.warn('[contextFact] Status report resumed after the previous window filled', {
|
|
110
|
+
reportedLastWindow: unplaceableStatus.size,
|
|
111
|
+
});
|
|
112
|
+
unplaceableStatus.clear();
|
|
113
|
+
}
|
|
114
|
+
unplaceableStatus.add(status);
|
|
115
|
+
if (unplaceableStatus.size >= MAX_UNPLACEABLE_LOGGED) filledAt = Date.now();
|
|
116
|
+
logger.warn('[contextFact] Status is outside the vocabulary; storing the default', {
|
|
117
|
+
status, storedAs: unrecognised,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function statusFrom(table, status, { absent, unrecognised = null }) {
|
|
122
|
+
const raw = statusToken(status);
|
|
123
|
+
if (!raw) return absent;
|
|
124
|
+
if (raw in table) return table[raw];
|
|
125
|
+
const key = masculine(raw);
|
|
126
|
+
if (key && key in table) return table[key];
|
|
127
|
+
noteUnplaceable(raw, unrecognised);
|
|
128
|
+
return unrecognised;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function variableEntry(variableId) {
|
|
132
|
+
return VARIABLE_REGISTRY[variableId] || null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function isSingleton(variableId) {
|
|
136
|
+
return Boolean(variableEntry(variableId)?.singleton);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resourceTypeFor(variableId) {
|
|
140
|
+
const entry = variableEntry(variableId);
|
|
141
|
+
return entry ? KIND_TO_RESOURCE_TYPE[entry.kind] : null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function conceptKeyOf({ patientId, variableId, concept }) {
|
|
145
|
+
const scope = String(patientId ?? '').trim();
|
|
146
|
+
if (!scope) throw new Error('patientId is required to key a context fact');
|
|
147
|
+
if (isSingleton(variableId)) return `${scope}|${variableId}`;
|
|
148
|
+
const discriminator = foldAccents(String(concept ?? '').trim().toLowerCase()).replace(/\s+/g, ' ');
|
|
149
|
+
if (!discriminator) throw new Error(`concept is required to key the list-like variable ${variableId}`);
|
|
150
|
+
return `${scope}|${variableId}:${discriminator}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// fhirId truncates at 64 chars, so a natural key would collide across long concepts.
|
|
154
|
+
function digestId(prefix, key) {
|
|
155
|
+
return `${prefix}-${createHash('sha256').update(key).digest('hex').slice(0, 24)}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// A stored row missing its timestamps must not throw out of the merge callback and fail the batch.
|
|
159
|
+
const instantOrNull = toIsoInstant;
|
|
160
|
+
|
|
161
|
+
function contextExtensions(claim, { alternates = [], openConflict = false } = {}) {
|
|
162
|
+
const out = [
|
|
163
|
+
extension(CONTEXT_EXT.VARIABLE_ID, { valueString: claim.variableId }),
|
|
164
|
+
extension(CONTEXT_EXT.SOURCE, { valueString: claim.source }),
|
|
165
|
+
extension(CONTEXT_EXT.TRUST, { valueDecimal: claim.trust }),
|
|
166
|
+
extension(CONTEXT_EXT.VALID_TIME, { valueDateTime: instantOrNull(claim.validTime) }),
|
|
167
|
+
extension(CONTEXT_EXT.RECORD_TIME, { valueDateTime: instantOrNull(claim.recordTime) }),
|
|
168
|
+
];
|
|
169
|
+
for (const alternate of alternates) {
|
|
170
|
+
out.push(extension(CONTEXT_EXT.ALTERNATE, {
|
|
171
|
+
extension: [
|
|
172
|
+
extension(CONTEXT_EXT.ALTERNATE_VALUE, { valueString: alternate.value }),
|
|
173
|
+
extension(CONTEXT_EXT.SOURCE, { valueString: alternate.source }),
|
|
174
|
+
extension(CONTEXT_EXT.TRUST, { valueDecimal: alternate.trust }),
|
|
175
|
+
extension(CONTEXT_EXT.VALID_TIME, { valueDateTime: instantOrNull(alternate.validTime) }),
|
|
176
|
+
extension(CONTEXT_EXT.RECORD_TIME, { valueDateTime: instantOrNull(alternate.recordTime) }),
|
|
177
|
+
],
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
if (openConflict) out.push(extension(CONTEXT_EXT.OPEN_CONFLICT, { valueBoolean: true }));
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// An unconfigured `snomed` costs the coding, not the finding: the rendered block reads `text`.
|
|
185
|
+
function allergyCoding(value, systems) {
|
|
186
|
+
if (value !== NO_KNOWN_ALLERGY.concept || !systems.snomed) return codeableConcept(value);
|
|
187
|
+
return codeableConcept(value, {
|
|
188
|
+
code: NO_KNOWN_ALLERGY.code, system: systems.snomed, display: NO_KNOWN_ALLERGY.display,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function factResource(assertion) {
|
|
193
|
+
const { variableId, value, status } = assertion;
|
|
194
|
+
const entry = variableEntry(variableId);
|
|
195
|
+
if (!entry) throw new Error(`unknown context variable ${variableId}`);
|
|
196
|
+
const systems = getSystems();
|
|
197
|
+
const conceptKey = conceptKeyOf(assertion);
|
|
198
|
+
const scope = scopeOf(conceptKey);
|
|
199
|
+
const payload = {
|
|
200
|
+
...baseResource(resourceTypeFor(variableId), conceptKey, CONTEXT_FACT_SLUG, scope),
|
|
201
|
+
id: digestId('ctx', conceptKey),
|
|
202
|
+
extension: contextExtensions(assertion),
|
|
203
|
+
};
|
|
204
|
+
const effective = toInstant(assertion.validTime);
|
|
205
|
+
|
|
206
|
+
if (entry.kind === 'condition') {
|
|
207
|
+
// R5 binds clinicalStatus to a value set with no "unknown" member and makes it mandatory.
|
|
208
|
+
const code = statusFrom(CONDITION_STATUS, status, { absent: 'active', unrecognised: 'active' });
|
|
209
|
+
payload.clinicalStatus = codeableConcept(code, { code, system: systems.conditionClinical });
|
|
210
|
+
payload.category = [problemListCategory()];
|
|
211
|
+
payload.code = codeableConcept(value);
|
|
212
|
+
payload.onsetDateTime = effective;
|
|
213
|
+
} else if (entry.kind === 'observation') {
|
|
214
|
+
payload.status = 'final';
|
|
215
|
+
payload.code = codeableConcept(variableId);
|
|
216
|
+
payload.valueString = value;
|
|
217
|
+
payload.effectiveDateTime = effective;
|
|
218
|
+
} else if (entry.kind === 'medication') {
|
|
219
|
+
const adherence = statusFrom(MEDICATION_ADHERENCE, status, { absent: null, unrecognised: 'unknown' });
|
|
220
|
+
payload.status = 'recorded';
|
|
221
|
+
payload.medication = { concept: codeableConcept(value) };
|
|
222
|
+
if (adherence) {
|
|
223
|
+
payload.adherence = {
|
|
224
|
+
code: codeableConcept(adherence, { code: adherence, system: systems.medicationStatementAdherence }),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
payload.effectiveDateTime = effective;
|
|
228
|
+
} else if (entry.kind === 'procedure') {
|
|
229
|
+
payload.status = statusFrom(PROCEDURE_STATUS, status, { absent: 'unknown', unrecognised: 'unknown' });
|
|
230
|
+
payload.code = codeableConcept(value);
|
|
231
|
+
payload.occurrenceDateTime = effective;
|
|
232
|
+
} else if (entry.kind === 'allergy') {
|
|
233
|
+
delete payload.subject;
|
|
234
|
+
payload.patient = patientReference(scope);
|
|
235
|
+
const allergyCode = statusFrom(ALLERGY_STATUS, status, { absent: 'active', unrecognised: 'active' });
|
|
236
|
+
payload.clinicalStatus = codeableConcept(allergyCode, { code: allergyCode, system: systems.allergyClinical });
|
|
237
|
+
payload.code = allergyCoding(value, systems);
|
|
238
|
+
payload.recordedDate = toInstant(assertion.recordTime);
|
|
239
|
+
} else {
|
|
240
|
+
payload.status = statusFrom(SERVICE_STATUS, status, { absent: 'active', unrecognised: 'unknown' });
|
|
241
|
+
payload.intent = 'plan';
|
|
242
|
+
payload.code = { concept: codeableConcept(value) };
|
|
243
|
+
payload.occurrenceDateTime = effective;
|
|
244
|
+
}
|
|
245
|
+
return payload;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function factProvenance(assertion, fact) {
|
|
249
|
+
return {
|
|
250
|
+
...provenance({
|
|
251
|
+
provenanceId: digestId('ctx-prov', `${conceptKeyOf(assertion)}|${toInstant(assertion.recordTime)}`),
|
|
252
|
+
targetRefs: [reference(fact.resourceType, fact.id)],
|
|
253
|
+
recordedAt: assertion.recordTime,
|
|
254
|
+
activity: codeableConcept(ACTIVITY_TEXT),
|
|
255
|
+
}),
|
|
256
|
+
extension: [
|
|
257
|
+
extension(CONTEXT_EXT.VARIABLE_ID, { valueString: assertion.variableId }),
|
|
258
|
+
extension(CONTEXT_EXT.SOURCE, { valueString: assertion.source }),
|
|
259
|
+
extension(CONTEXT_EXT.TRUST, { valueDecimal: assertion.trust }),
|
|
260
|
+
extension(CONTEXT_EXT.VALID_TIME, { valueDateTime: toInstant(assertion.validTime) }),
|
|
261
|
+
],
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function toFhir(assertion) {
|
|
266
|
+
const fact = factResource(assertion);
|
|
267
|
+
return [fact, factProvenance(assertion, fact)];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function valueOf(resource) {
|
|
271
|
+
switch (resource.resourceType) {
|
|
272
|
+
case 'Observation': return resource.valueString ?? null;
|
|
273
|
+
case 'MedicationStatement': return resource.medication?.concept?.text ?? null;
|
|
274
|
+
case 'ServiceRequest': return resource.code?.concept?.text ?? null;
|
|
275
|
+
default: return resource.code?.text ?? null;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function statusOf(resource) {
|
|
280
|
+
switch (resource.resourceType) {
|
|
281
|
+
case 'AllergyIntolerance':
|
|
282
|
+
case 'Condition': return resource.clinicalStatus?.coding?.[0]?.code ?? null;
|
|
283
|
+
case 'MedicationStatement': return resource.adherence?.code?.coding?.[0]?.code ?? null;
|
|
284
|
+
case 'Procedure':
|
|
285
|
+
case 'ServiceRequest': return resource.status ?? null;
|
|
286
|
+
default: return null;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function scopeOf(conceptKey) {
|
|
291
|
+
const end = String(conceptKey ?? '').indexOf('|');
|
|
292
|
+
return end === -1 ? null : String(conceptKey).slice(0, end);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function conceptOf(conceptKey) {
|
|
296
|
+
const scopeEnd = conceptKey.indexOf('|');
|
|
297
|
+
const separator = scopeEnd === -1 ? -1 : conceptKey.indexOf(':', scopeEnd);
|
|
298
|
+
return separator === -1 ? null : conceptKey.slice(separator + 1);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function claimOf(resource) {
|
|
302
|
+
const ext = extMap(resource);
|
|
303
|
+
return {
|
|
304
|
+
variableId: ext[CONTEXT_EXT.VARIABLE_ID],
|
|
305
|
+
value: valueOf(resource),
|
|
306
|
+
source: ext[CONTEXT_EXT.SOURCE],
|
|
307
|
+
trust: Number(ext[CONTEXT_EXT.TRUST] ?? 0),
|
|
308
|
+
validTime: ext[CONTEXT_EXT.VALID_TIME],
|
|
309
|
+
recordTime: ext[CONTEXT_EXT.RECORD_TIME],
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function alternatesOf(resource) {
|
|
314
|
+
const url = extensionUrl(CONTEXT_EXT.ALTERNATE);
|
|
315
|
+
const out = [];
|
|
316
|
+
for (const ext of resource.extension || []) {
|
|
317
|
+
if (ext.url !== url) continue;
|
|
318
|
+
const inner = extMap({ extension: ext.extension || [] });
|
|
319
|
+
out.push({
|
|
320
|
+
value: inner[CONTEXT_EXT.ALTERNATE_VALUE],
|
|
321
|
+
source: inner[CONTEXT_EXT.SOURCE],
|
|
322
|
+
trust: Number(inner[CONTEXT_EXT.TRUST] ?? 0),
|
|
323
|
+
validTime: inner[CONTEXT_EXT.VALID_TIME],
|
|
324
|
+
recordTime: inner[CONTEXT_EXT.RECORD_TIME],
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return out;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function withArbitration(resource, winner, arbitration) {
|
|
331
|
+
return { ...resource, extension: contextExtensions(winner, arbitration) };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const contextKeyOf = (resource) => identifierValue(resource, CONTEXT_FACT_SLUG);
|
|
335
|
+
|
|
336
|
+
function isContextFact(resource) {
|
|
337
|
+
return Boolean(contextKeyOf(resource));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function fromFhir(resources) {
|
|
341
|
+
const rows = [];
|
|
342
|
+
for (const resource of resources) {
|
|
343
|
+
const conceptKey = contextKeyOf(resource);
|
|
344
|
+
if (!conceptKey) continue;
|
|
345
|
+
const ext = extMap(resource);
|
|
346
|
+
const value = valueOf(resource);
|
|
347
|
+
if (!ext[CONTEXT_EXT.VARIABLE_ID] || !value) continue;
|
|
348
|
+
rows.push({
|
|
349
|
+
conceptKey,
|
|
350
|
+
variableId: ext[CONTEXT_EXT.VARIABLE_ID],
|
|
351
|
+
concept: conceptOf(conceptKey),
|
|
352
|
+
value,
|
|
353
|
+
status: statusOf(resource),
|
|
354
|
+
source: ext[CONTEXT_EXT.SOURCE],
|
|
355
|
+
trust: Number(ext[CONTEXT_EXT.TRUST] ?? 0),
|
|
356
|
+
validTime: ext[CONTEXT_EXT.VALID_TIME],
|
|
357
|
+
recordTime: ext[CONTEXT_EXT.RECORD_TIME],
|
|
358
|
+
openConflict: Boolean(ext[CONTEXT_EXT.OPEN_CONFLICT]),
|
|
359
|
+
alternates: alternatesOf(resource),
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return rows;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
module.exports = {
|
|
366
|
+
CONTEXT_RESOURCE_TYPES,
|
|
367
|
+
PROCEDURE_STATUS,
|
|
368
|
+
statusFrom,
|
|
369
|
+
toFhir,
|
|
370
|
+
fromFhir,
|
|
371
|
+
conceptKeyOf,
|
|
372
|
+
contextKeyOf,
|
|
373
|
+
scopeOf,
|
|
374
|
+
claimOf,
|
|
375
|
+
alternatesOf,
|
|
376
|
+
withArbitration,
|
|
377
|
+
isContextFact,
|
|
378
|
+
variableEntry,
|
|
379
|
+
isSingleton,
|
|
380
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
const { ZodError } = require('zod');
|
|
2
|
+
|
|
3
|
+
const { getOrganizationId } = require('../config/fhirConfig');
|
|
4
|
+
const { fhirId } = require('../helpers/fhirHelper');
|
|
5
|
+
const { patientReference, reference, codeableConcept, extension, toIso } = require('../helpers/elementHelper');
|
|
6
|
+
const { baseResource, provenance } = require('../helpers/resourceHelper');
|
|
7
|
+
const { extMap, identifierValue, referencedId } = require('../helpers/fhirReadHelper');
|
|
8
|
+
const { CONTINGENCY_PLAN_SLUG, CONTINGENCY_STEP_SLUG } = require('../constants/projectionSlugs');
|
|
9
|
+
const { ContingencySafetyNet, ACTIVE_CARE_PLAN_STATUSES, RESOLVES_ON, ARMED_BY } = require('../../shared/dtos/ContingencySafetyNet');
|
|
10
|
+
const { logger } = require('../../utils/logger');
|
|
11
|
+
|
|
12
|
+
const ACTIVITY_TEXT = 'contingency-safety-net';
|
|
13
|
+
const CATEGORY_PREFIX = 'contingency-';
|
|
14
|
+
|
|
15
|
+
const EXT = {
|
|
16
|
+
STATUS: 'contingency-status',
|
|
17
|
+
AWAITING_CHARACTERIZATION: 'contingency-awaiting-characterization',
|
|
18
|
+
RESOLVES_ON: 'contingency-resolves-on',
|
|
19
|
+
ARMED_BY: 'contingency-armed-by',
|
|
20
|
+
WHY_THIS_MATTERS: 'contingency-why-this-matters',
|
|
21
|
+
CREATION_REASONING: 'contingency-creation-reasoning',
|
|
22
|
+
RESOLVED_REASON: 'contingency-resolved-reason',
|
|
23
|
+
EXPIRES_AT: 'contingency-expires-at',
|
|
24
|
+
RELATED_CASE_ID: 'contingency-related-case-id',
|
|
25
|
+
RELATED_CLUSTER_ID: 'contingency-related-cluster-id',
|
|
26
|
+
STEP_PRIORITY: 'contingency-step-priority',
|
|
27
|
+
ACTION_REQUESTED: 'contingency-action-requested',
|
|
28
|
+
FIRES_AFTER_SILENCE_MINUTES: 'fires-after-silence-minutes',
|
|
29
|
+
WINDOW_REASONING: 'contingency-window-reasoning',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const STATUS_TO_FHIR = {
|
|
33
|
+
armed: 'active',
|
|
34
|
+
fired_reminder: 'active',
|
|
35
|
+
fired_team: 'active',
|
|
36
|
+
auto_resolved: 'completed',
|
|
37
|
+
cancelled: 'revoked',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const PRIORITY_CROSSWALK = {
|
|
41
|
+
critical: 'stat',
|
|
42
|
+
high: 'urgent',
|
|
43
|
+
medium: 'routine',
|
|
44
|
+
low: 'routine',
|
|
45
|
+
routine: 'routine',
|
|
46
|
+
urgent: 'urgent',
|
|
47
|
+
asap: 'asap',
|
|
48
|
+
stat: 'stat',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const RESOURCE_TYPES = ['CarePlan', 'CommunicationRequest'];
|
|
52
|
+
|
|
53
|
+
function toFhir(contingency) {
|
|
54
|
+
const { carePlan, teamEscalation, patientReminder } = contingency;
|
|
55
|
+
const steps = [teamEscalation, patientReminder].filter(Boolean);
|
|
56
|
+
|
|
57
|
+
const resources = [carePlanResource(carePlan)];
|
|
58
|
+
for (const step of steps) resources.push(stepResource(step, carePlan));
|
|
59
|
+
|
|
60
|
+
const targetRefs = [{ reference: `CarePlan/${fhirId(carePlan.planId)}` }];
|
|
61
|
+
for (const step of steps) {
|
|
62
|
+
targetRefs.push({ reference: `CommunicationRequest/${fhirId(`${carePlan.planId}-${step.recipient}`)}` });
|
|
63
|
+
}
|
|
64
|
+
resources.push(provenance({
|
|
65
|
+
provenanceId: `${carePlan.planId}-prov`,
|
|
66
|
+
targetRefs,
|
|
67
|
+
recordedAt: carePlan.createdAt,
|
|
68
|
+
activity: codeableConcept(ACTIVITY_TEXT),
|
|
69
|
+
}));
|
|
70
|
+
return resources;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function carePlanResource(carePlan) {
|
|
74
|
+
const payload = {
|
|
75
|
+
...baseResource('CarePlan', carePlan.planId, CONTINGENCY_PLAN_SLUG, carePlan.patientId),
|
|
76
|
+
status: STATUS_TO_FHIR[carePlan.status],
|
|
77
|
+
intent: 'plan',
|
|
78
|
+
created: toIso(carePlan.createdAt),
|
|
79
|
+
period: carePlanPeriod(carePlan),
|
|
80
|
+
};
|
|
81
|
+
if (carePlan.concern) payload.description = carePlan.concern;
|
|
82
|
+
if (carePlan.relatedCaseId) payload.addresses = [{ reference: reference('Condition', carePlan.relatedCaseId) }];
|
|
83
|
+
if (carePlan.relatedClusterId) payload.supportingInfo = [reference('ClinicalImpression', carePlan.relatedClusterId)];
|
|
84
|
+
const ext = carePlanExtensions(carePlan);
|
|
85
|
+
if (ext.length) payload.extension = ext;
|
|
86
|
+
return payload;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function carePlanPeriod(carePlan) {
|
|
90
|
+
const period = { start: toIso(carePlan.createdAt) };
|
|
91
|
+
if (carePlan.resolvedAt) period.end = toIso(carePlan.resolvedAt);
|
|
92
|
+
return period;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function carePlanExtensions(carePlan) {
|
|
96
|
+
const out = [
|
|
97
|
+
extension(EXT.STATUS, { valueString: carePlan.status }),
|
|
98
|
+
extension(EXT.RESOLVES_ON, { valueString: carePlan.resolvesOn }),
|
|
99
|
+
extension(EXT.ARMED_BY, { valueString: carePlan.armedBy }),
|
|
100
|
+
];
|
|
101
|
+
if (carePlan.relatedCaseId) out.push(extension(EXT.RELATED_CASE_ID, { valueString: carePlan.relatedCaseId }));
|
|
102
|
+
if (carePlan.relatedClusterId) out.push(extension(EXT.RELATED_CLUSTER_ID, { valueString: carePlan.relatedClusterId }));
|
|
103
|
+
if (carePlan.awaitingCharacterization) out.push(extension(EXT.AWAITING_CHARACTERIZATION, { valueString: carePlan.awaitingCharacterization }));
|
|
104
|
+
if (carePlan.whyThisMatters) out.push(extension(EXT.WHY_THIS_MATTERS, { valueString: carePlan.whyThisMatters }));
|
|
105
|
+
if (carePlan.creationReasoning) out.push(extension(EXT.CREATION_REASONING, { valueString: carePlan.creationReasoning }));
|
|
106
|
+
if (carePlan.resolvedReason) out.push(extension(EXT.RESOLVED_REASON, { valueString: carePlan.resolvedReason }));
|
|
107
|
+
if (carePlan.expiresAt) out.push(extension(EXT.EXPIRES_AT, { valueDateTime: toIso(carePlan.expiresAt) }));
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function stepResource(step, carePlan) {
|
|
112
|
+
const stepId = `${carePlan.planId}-${step.recipient}`;
|
|
113
|
+
const payload = {
|
|
114
|
+
...baseResource('CommunicationRequest', stepId, CONTINGENCY_STEP_SLUG, carePlan.patientId),
|
|
115
|
+
status: STATUS_TO_FHIR[carePlan.status],
|
|
116
|
+
intent: 'plan',
|
|
117
|
+
category: [codeableConcept(`${CATEGORY_PREFIX}${step.recipient}`)],
|
|
118
|
+
recipient: [step.recipient === 'patient'
|
|
119
|
+
? patientReference(carePlan.patientId)
|
|
120
|
+
: { reference: `Organization/${fhirId(getOrganizationId())}` }],
|
|
121
|
+
payload: [{ contentCodeableConcept: codeableConcept(step.message) }],
|
|
122
|
+
authoredOn: toIso(carePlan.createdAt),
|
|
123
|
+
basedOn: [{ reference: `CarePlan/${fhirId(carePlan.planId)}` }],
|
|
124
|
+
};
|
|
125
|
+
const priority = step.priority ? PRIORITY_CROSSWALK[step.priority] || 'routine' : null;
|
|
126
|
+
if (priority) payload.priority = priority;
|
|
127
|
+
const ext = stepExtensions(step);
|
|
128
|
+
if (ext.length) payload.extension = ext;
|
|
129
|
+
return payload;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function stepExtensions(step) {
|
|
133
|
+
const out = [];
|
|
134
|
+
if (step.priority) out.push(extension(EXT.STEP_PRIORITY, { valueString: step.priority }));
|
|
135
|
+
if (step.actionRequested) out.push(extension(EXT.ACTION_REQUESTED, { valueString: step.actionRequested }));
|
|
136
|
+
if (step.firesAfterSilenceMinutes !== null && step.firesAfterSilenceMinutes !== undefined) {
|
|
137
|
+
out.push(extension(EXT.FIRES_AFTER_SILENCE_MINUTES, { valueInteger: step.firesAfterSilenceMinutes }));
|
|
138
|
+
}
|
|
139
|
+
if (step.windowReasoning) out.push(extension(EXT.WINDOW_REASONING, { valueString: step.windowReasoning }));
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function fromFhir(resources, { patientId }) {
|
|
144
|
+
const requests = resources.filter((r) => r.resourceType === 'CommunicationRequest' && identifierValue(r, CONTINGENCY_STEP_SLUG));
|
|
145
|
+
return resources
|
|
146
|
+
.filter((r) => r.resourceType === 'CarePlan' && identifierValue(r, CONTINGENCY_PLAN_SLUG))
|
|
147
|
+
.map((plan) => reconstruct(plan, requests, patientId))
|
|
148
|
+
.filter(Boolean);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function knownProvenance(value, planId) {
|
|
152
|
+
if (!value) return ARMED_BY.AGENT;
|
|
153
|
+
if (Object.values(ARMED_BY).includes(value)) return value;
|
|
154
|
+
logger.warn('contingency net has an unknown armedBy; reading it as agent-armed', { planId, armedBy: value });
|
|
155
|
+
return ARMED_BY.AGENT;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function reconstruct(plan, requests, patientId) {
|
|
159
|
+
const planId = identifierValue(plan, CONTINGENCY_PLAN_SLUG);
|
|
160
|
+
const ext = extMap(plan);
|
|
161
|
+
const stepFor = (recipient) => {
|
|
162
|
+
const resource = requests.find((r) => identifierValue(r, CONTINGENCY_STEP_SLUG) === `${planId}-${recipient}`);
|
|
163
|
+
return resource ? reconstructStep(resource, recipient) : null;
|
|
164
|
+
};
|
|
165
|
+
const address = plan.addresses && plan.addresses[0] && plan.addresses[0].reference;
|
|
166
|
+
const reconstructed = {
|
|
167
|
+
schemaVersion: '1',
|
|
168
|
+
carePlan: {
|
|
169
|
+
planId,
|
|
170
|
+
patientId,
|
|
171
|
+
relatedCaseId: referencedId(plan, EXT.RELATED_CASE_ID, address?.reference),
|
|
172
|
+
relatedClusterId: referencedId(plan, EXT.RELATED_CLUSTER_ID, plan.supportingInfo?.[0]?.reference),
|
|
173
|
+
concern: plan.description || '',
|
|
174
|
+
awaitingCharacterization: ext[EXT.AWAITING_CHARACTERIZATION] || '',
|
|
175
|
+
resolvesOn: ext[EXT.RESOLVES_ON] || RESOLVES_ON.REPLY,
|
|
176
|
+
armedBy: knownProvenance(ext[EXT.ARMED_BY], planId),
|
|
177
|
+
whyThisMatters: ext[EXT.WHY_THIS_MATTERS] || '',
|
|
178
|
+
creationReasoning: ext[EXT.CREATION_REASONING] || '',
|
|
179
|
+
status: ext[EXT.STATUS] || 'armed',
|
|
180
|
+
createdAt: plan.created,
|
|
181
|
+
expiresAt: ext[EXT.EXPIRES_AT] || null,
|
|
182
|
+
resolvedAt: (plan.period && plan.period.end) || null,
|
|
183
|
+
resolvedReason: ext[EXT.RESOLVED_REASON] || null,
|
|
184
|
+
},
|
|
185
|
+
teamEscalation: stepFor('care_team'),
|
|
186
|
+
patientReminder: stepFor('patient'),
|
|
187
|
+
};
|
|
188
|
+
try {
|
|
189
|
+
return new ContingencySafetyNet(reconstructed);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
if (error instanceof ZodError) {
|
|
192
|
+
logger.warn('skipping malformed contingency CarePlan', { planId });
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function isRetiredPlanResource(resource) {
|
|
200
|
+
if (resource?.resourceType !== 'CarePlan') return false;
|
|
201
|
+
const status = extMap(resource)[EXT.STATUS];
|
|
202
|
+
return Boolean(resource.period?.end) || Boolean(status && !ACTIVE_CARE_PLAN_STATUSES.includes(status));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function reconstructStep(resource, recipient) {
|
|
206
|
+
const ext = extMap(resource);
|
|
207
|
+
const silence = ext[EXT.FIRES_AFTER_SILENCE_MINUTES];
|
|
208
|
+
const firstPayload = resource.payload && resource.payload[0];
|
|
209
|
+
return {
|
|
210
|
+
recipient,
|
|
211
|
+
message: (firstPayload && firstPayload.contentCodeableConcept && firstPayload.contentCodeableConcept.text) || null,
|
|
212
|
+
priority: ext[EXT.STEP_PRIORITY] || resource.priority || null,
|
|
213
|
+
actionRequested: ext[EXT.ACTION_REQUESTED] || null,
|
|
214
|
+
firesAfterSilenceMinutes: typeof silence === 'number' ? silence : null,
|
|
215
|
+
windowReasoning: ext[EXT.WINDOW_REASONING] || null,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
module.exports = {
|
|
220
|
+
toFhir,
|
|
221
|
+
fromFhir,
|
|
222
|
+
isRetiredPlanResource,
|
|
223
|
+
RESOURCE_TYPES,
|
|
224
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const { getDeviceId } = require('../config/fhirConfig');
|
|
2
|
+
const { identifierValue } = require('../helpers/fhirReadHelper');
|
|
3
|
+
const { ESCALATION_SLUG } = require('../constants/projectionSlugs');
|
|
4
|
+
|
|
5
|
+
const { CommunicationRequest } = require('../resources/CommunicationRequest');
|
|
6
|
+
const { Task } = require('../resources/Task');
|
|
7
|
+
const { Provenance } = require('../resources/Provenance');
|
|
8
|
+
|
|
9
|
+
const PROJECTOR_NAME = 'dispatchedEscalation';
|
|
10
|
+
const ACTIVITY_TEXT = 'dispatched-escalation';
|
|
11
|
+
const TICKET_KIND = 'open_ticket';
|
|
12
|
+
|
|
13
|
+
function projectDispatchedEscalation(escalation) {
|
|
14
|
+
const primary = escalation.kind === TICKET_KIND
|
|
15
|
+
? Task.fromTicketEscalation({ ticket: escalation, deviceId: getDeviceId() })
|
|
16
|
+
: CommunicationRequest.fromNotifyEscalation({ notify: escalation });
|
|
17
|
+
const provenance = Provenance.fromDispatchedEscalation({
|
|
18
|
+
target: primary,
|
|
19
|
+
recordedAt: escalation.createdAt,
|
|
20
|
+
activityText: ACTIVITY_TEXT,
|
|
21
|
+
});
|
|
22
|
+
return [primary, provenance];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isTicket = (resource) => resource?.resourceType === 'Task';
|
|
26
|
+
|
|
27
|
+
const kindOf = (resource) => (isTicket(resource)
|
|
28
|
+
? resource.code?.coding?.[0]?.code || resource.code?.text
|
|
29
|
+
: resource.category?.[0]?.coding?.[0]?.code || resource.category?.[0]?.text) || null;
|
|
30
|
+
|
|
31
|
+
const reasonOf = (resource) => (isTicket(resource)
|
|
32
|
+
? resource.note?.[0]?.text || resource.description
|
|
33
|
+
: resource.reason?.[0]?.concept?.text) || null;
|
|
34
|
+
|
|
35
|
+
function fromFhir(resources = []) {
|
|
36
|
+
const events = new Map();
|
|
37
|
+
for (const resource of resources) {
|
|
38
|
+
const authoredOn = resource?.authoredOn;
|
|
39
|
+
if (!authoredOn) continue;
|
|
40
|
+
const reason = reasonOf(resource);
|
|
41
|
+
const key = `${authoredOn}|${reason ?? ''}`;
|
|
42
|
+
const event = events.get(key) || {
|
|
43
|
+
escalationIds: [],
|
|
44
|
+
escalatedAt: authoredOn,
|
|
45
|
+
urgency: null,
|
|
46
|
+
reason,
|
|
47
|
+
channels: [],
|
|
48
|
+
};
|
|
49
|
+
const escalationId = identifierValue(resource, ESCALATION_SLUG);
|
|
50
|
+
if (escalationId && !event.escalationIds.includes(escalationId)) event.escalationIds.push(escalationId);
|
|
51
|
+
event.urgency = event.urgency || resource.priority || null;
|
|
52
|
+
const kind = kindOf(resource);
|
|
53
|
+
if (kind && !event.channels.includes(kind)) event.channels.push(kind);
|
|
54
|
+
events.set(key, event);
|
|
55
|
+
}
|
|
56
|
+
return [...events.values()].sort((a, b) => (a.escalatedAt < b.escalatedAt ? 1 : -1));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
projectDispatchedEscalation,
|
|
61
|
+
fromFhir,
|
|
62
|
+
PROJECTOR_NAME,
|
|
63
|
+
};
|