/**
 * NIH Genomic Data Sharing Policy -- Pack
 *
 * Split notice: All four NIH policy instruments were previously bundled in
 * `src/packs/nih-data-sharing.ts`. Split per Thomas's 2026-04-24 principle:
 * one country, one regulation, one pack. Reference the original Vera brief at
 * `docs/compliance-research/2026-04-24-pack-brief-nih-data-sharing.md`
 * which documented all four instruments.
 *
 * Cross-pack interactions (all 4 NIH packs typically activate together):
 *   - us-nih-dms requires sharing of scientific data broadly; GDS governs
 *     the controlled-access repository workflow for genomic data specifically.
 *     Both run simultaneously for genomic NIH research.
 *   - us-nih-coc may restrict sharing of CoC-protected identifiable genomic
 *     data. CoC governs the disclosure side; GDS governs the deposit side.
 *     CoC-protected genomic data routes to controlled-access repositories only.
 *   - us-nih-it-security provides the FISMA Moderate baseline required for
 *     systems processing controlled-access genomic data.
 *   - When all 4 packs are active, strictest-wins resolves conflicts.
 *
 * NIH Genomic Data Sharing (GDS) Policy (NOT-OD-14-124):
 * Effective January 25, 2015. Applies to NIH-funded research generating
 * large-scale genomic data. Requires deposit of genomic data in NIH-
 * designated repositories (dbGaP for controlled-access; public repositories
 * for unrestricted data). AI systems processing controlled-access genomic
 * data require an active Data Use Certificate (DUC) from the relevant
 * Data Access Committee (DAC).
 *
 * @connexum/ai-governance
 */
/**
 * NIH GDS category classifiers.
 */
export const NIH_GDS_CATEGORY_CLASSIFIERS = {
    GENOMIC_DATA_HUMAN: {
        references: ['NOT-OD-14-124 -- NIH Genomic Data Sharing Policy; GDS Policy scope'],
        classifier: (input) => {
            if (/\b(?:GWAS|WGS|WES|SNP.array|RNA.seq|transcriptomic|methylation.array|variant.call.format|vcf.file|dbGaP|GENOMIC_DATA_HUMAN)\b/i.test(input))
                return true;
            // Genomic coordinate patterns (chr:pos format)
            if (/\bchr(?:[1-9]|1\d|2[012]|[XY]):(?:\d{5,9})\b/i.test(input))
                return true;
            // Human genomic data with NIH context
            if (/\b(?:genomic|genome|genetic.variant|allele.frequency)\b.*\b(?:human|participant|subject|nih)\b/i.test(input))
                return true;
            return false;
        },
    },
    GENOMIC_IDENTIFIABLE_LINK: {
        references: ['NOT-OD-14-124 -- re-identification risk; GDS Policy controlled-access threshold'],
        classifier: (input) => {
            if (/\b(?:genomic.identifiable|re.identifiable.genomic|linked.genomic.record|genomic.pii.link|GENOMIC_IDENTIFIABLE_LINK)\b/i.test(input))
                return true;
            if (/\b(?:genomic|genome|genetic)\b.*\b(?:patient.name|subject.name|linked.to.identity|identifiable)\b/i.test(input))
                return true;
            return false;
        },
    },
    CONTROLLED_ACCESS_REPOSITORY_DATA: {
        references: ['NOT-OD-14-124 (GDS Policy) -- controlled-access repository; dbGaP Data Access Committee'],
        classifier: (input) => {
            if (/\b(?:dbGaP|controlled.access.dataset|DAC.approved|data.access.committee|NDA.repository|controlled.access.repository|CONTROLLED_ACCESS_REPOSITORY_DATA)\b/i.test(input))
                return true;
            // dbGaP accession number pattern (phs followed by digits)
            if (/\bphs\d{6}\b/i.test(input))
                return true;
            return false;
        },
    },
    DAC_APPROVED_DATA_USE: {
        references: ['GDS Policy -- Data Use Certificate; dbGaP DAC standard DUC terms'],
        classifier: (input) => {
            if (/\b(?:DUC|data.use.certificate|DAC.approval|dac.approved|data.access.request|DAC_APPROVED_DATA_USE)\b/i.test(input))
                return true;
            return false;
        },
    },
    /**
     * GAP-6: DAC_APPROVAL_EXPIRED -- detects expired DAC/DUC approvals.
     * Action: BLOCK.
     * Reference: GDS Policy (NOT-OD-14-124) -- active DUC required at all times.
     */
    DAC_APPROVAL_EXPIRED: {
        references: ['NOT-OD-14-124 (GDS Policy) -- active Data Use Certificate required; expired approval is non-compliance; GAP-6'],
        classifier: (input, _ctx) => {
            if (/\bDAC_APPROVAL_EXPIRED\b/i.test(input))
                return true;
            if (/\b(?:DAC|DUC|data.use.certificate|data.access.committee)\b.*\bexpir(?:ed|es|ation|y)\b/i.test(input))
                return true;
            if (/\bexpir(?:ed|es|ation|y)\b.*\b(?:DAC|DUC|data.use.certificate|data.access.committee)\b/i.test(input))
                return true;
            const hasDACContext = /\b(?:DAC|DUC|data.use.certificate|data.access.committee|dbGaP)\b/i.test(input);
            if (!hasDACContext)
                return false;
            const pastYearMatch = /\b(\d{4})\b/.exec(input);
            if (pastYearMatch)
                return true;
            return false;
        },
    },
    /**
     * F-NEW-VERA-PACK-C6-02: STUDY_CONCLUDED_DUC_ACTIVE
     * Detects scenarios where a study has ended but a DUC remains in-date and
     * has not been formally terminated. A lapsed DUC is covered by
     * DAC_APPROVAL_EXPIRED; this category covers the complementary gap where
     * the DUC is technically active but the study is over and the GDS Policy
     * expects the DUC termination workflow to be initiated.
     *
     * Risk if undetected: DAC audit finding; potential ORI referral for failure
     * to close out controlled-access data access when research purpose concluded.
     *
     * Action: REQUIRE_APPROVAL (not BLOCK) -- the runtime prompts a human
     * reviewer to confirm whether the DUC termination workflow has been initiated,
     * without hard-blocking access (which could disrupt legitimate close-out work).
     *
     * Reference: GDS Policy (NOT-OD-14-124); dbGaP DUC standard terms (study
     * closeout obligations); NIH GPS Section 8 (closeout requirements).
     */
    STUDY_CONCLUDED_DUC_ACTIVE: {
        references: [
            'NOT-OD-14-124 (GDS Policy) -- DUC termination required when research purpose concludes; F-NEW-VERA-PACK-C6-02',
            'dbGaP DUC standard terms -- study closeout obligations',
            'NIH GPS -- closeout requirements for terminated NIH awards',
        ],
        classifier: (input) => {
            if (/\bSTUDY_CONCLUDED_DUC_ACTIVE\b/i.test(input))
                return true;
            // Study conclusion / termination signals
            const studyConcluded = /\bstudy\s+(?:ended|concluded|completed|terminated)\b/i.test(input) ||
                /\b(?:final\s+report\s+submitted|closeout\s+(?:report|period|package)|project\s+closeout|award\s+closeout|grant\s+closeout)\b/i.test(input) ||
                /\b(?:no.?cost\s+extension\s+ended|ncoe\s+expired|project\s+period\s+ended)\b/i.test(input);
            if (!studyConcluded)
                return false;
            // Must also have DUC/DAC/dbGaP context to avoid false positives on generic study completion text
            const hasDACContext = /\b(?:DAC|DUC|data.use.certificate|data.access.committee|dbGaP|genomic|controlled.access)\b/i.test(input);
            return hasDACContext;
        },
    },
};
export const NIH_GDS_PACK = {
    categoryClassifiers: NIH_GDS_CATEGORY_CLASSIFIERS,
    /**
     * P3.5: Human genomic data with re-identification risk, genomic data
     * with identifiable links, and controlled-access repository data are
     * inherently subject-keyed to satisfy GDS Policy access logging
     * obligations to the relevant Data Access Committee.
     */
    subjectKeyedCategories: [
        'GENOMIC_DATA_HUMAN',
        'GENOMIC_IDENTIFIABLE_LINK',
        'CONTROLLED_ACCESS_REPOSITORY_DATA',
        // STUDY_CONCLUDED_DUC_ACTIVE is subject-keyed: the study + DAC context
        // identifies the specific DUC subject record requiring termination review.
        'STUDY_CONCLUDED_DUC_ACTIVE',
    ],
    id: 'us-nih-gds',
    name: 'NIH Genomic Data Sharing Policy',
    version: '1.0.0',
    contentHash: '7c185b1443c4d8e3260f8bbbb6fe4a2b8f3464d314b47325e881d91501b16b55',
    description: 'NIH Genomic Data Sharing Policy (NOT-OD-14-124, effective January 25, 2015). Applies to NIH-funded research generating large-scale genomic data. Requires controlled-access repository deposit (dbGaP), active DAC approval listing the AI system, and no re-identifiable genomic data in public repositories. Activate alongside us-nih-dms, us-nih-coc, and us-nih-it-security for complete NIH research compliance.',
    authority: 'National Institutes of Health (NIH), HHS; enforced through NIH Program Officers, Grants Policy, and dbGaP Data Access Committees',
    industries: ['clinical-research', 'academic-research', 'genomics', 'biotech', 'federal-grantee'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'DAC approval verification gate; genomic re-identification block; controlled-access enforcement',
            reference: 'GDS Policy (NOT-OD-14-124) -- DAC gate; dbGaP DUC terms',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Per-access tamper-evident log with NIH award number, DAC approval reference, and timestamp',
            reference: 'GDS Policy; dbGaP DAC standard DUC terms; NIH GPS (citation to verify)',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Classify genomic data, controlled-access datasets, identifiable genomic links, DAC approval status, and expired approvals',
            reference: 'NOT-OD-14-124 (genomic data); GDS Policy controlled-access threshold',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Active DAC approval tracking per session; NIH award number context persistence',
            reference: 'GDS Policy DUC terms',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'DUA incorporating DAC DUC terms; no-training-on-research-data attestation; US data residency commitment',
            reference: 'GDS Policy DUC terms; NOT-OD-14-124',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Human confirmation of DAC approval scope before AI processes controlled-access genomic data',
            reference: 'GDS Policy (DAC approval required)',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'DUC records; FISMA security evidence for controlled-access systems',
            reference: '45 CFR 74.53; NIH GPS (citation to verify); NOT-OD-14-124',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Unauthorized genomic data access alerts; DAC approval expiry events; NIH Program Officer notification stream',
            reference: 'GDS Policy DUC terms; NOT-OD-14-124',
        },
        {
            name: 'encryption-layer',
            required: true,
            reason: 'FISMA Moderate equivalent encryption for controlled-access genomic data; FIPS 140 validation for systems in scope',
            reference: 'NIH IT Security Policy (NIH Manual Chapter 2800 series); FISMA (44 USC 3554)',
        },
    ],
    moduleConfig: {
        'governance-runtime': {
            dacApprovalRequired: true,
            genomicIdentifiableBlockEnabled: true,
        },
        'data-classifier': {
            enabledCategories: [
                'GENOMIC_DATA_HUMAN',
                'CONTROLLED_ACCESS_REPOSITORY_DATA',
                'GENOMIC_IDENTIFIABLE_LINK',
                'DAC_APPROVED_DATA_USE',
                'DAC_APPROVAL_EXPIRED',
                'STUDY_CONCLUDED_DUC_ACTIVE',
            ],
        },
        'supply-chain': {
            duaIncorporatingDucRequired: true,
            providerTrainingProhibitionAttested: true,
            fismaModerateRequiredForControlledAccess: true,
            dataResidencyUSRequired: true,
        },
        'approval-queue': {
            dacApprovalScopeConfirmationRequired: true,
        },
        'attestation-manager': {
            nihAuditRightsAcknowledged: true,
        },
        'event-bus': {
            researchDataAuditEnabled: true,
            nihAwardNumberRequiredInEvents: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: [
            'DATA-RESIDENCY-US',
            'ZERO-TRAINING-ON-NIH-RESEARCH-DATA',
            'DUA-DUC-TERMS-ACCEPTED',
            'FISMA-MODERATE-OR-FEDRAMP-MODERATE',
        ],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: [
            'GENOMIC_DATA_HUMAN',
            'CONTROLLED_ACCESS_REPOSITORY_DATA',
            'GENOMIC_IDENTIFIABLE_LINK',
            'DAC_APPROVED_DATA_USE',
            'DAC_APPROVAL_EXPIRED',
            'STUDY_CONCLUDED_DUC_ACTIVE',
        ],
        categoryActions: {
            GENOMIC_DATA_HUMAN: 'REQUIRE_APPROVAL',
            CONTROLLED_ACCESS_REPOSITORY_DATA: 'BLOCK',
            GENOMIC_IDENTIFIABLE_LINK: 'BLOCK',
            DAC_APPROVED_DATA_USE: 'LOG',
            DAC_APPROVAL_EXPIRED: 'BLOCK',
            // REQUIRE_APPROVAL not BLOCK: the study concluding while the DUC is still
            // in-date requires human confirmation that the DUC termination workflow
            // has been initiated. Hard-blocking would disrupt legitimate close-out work.
            STUDY_CONCLUDED_DUC_ACTIVE: 'REQUIRE_APPROVAL',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256',
        minimumClassification: 'CONFIDENTIAL',
    },
    retentionPolicy: {
        sovereignty: ['US'],
        auditLogRetentionDays: 2555, // 7 years (NIH clinical research standard)
        sessionRetentionDays: 2555,
        incidentRetentionDays: 2555,
        reference: 'NOT-OD-14-124 (GDS Policy); dbGaP DAC standard DUC terms; NIH GPS Section 8.4.1 (citation to verify)',
    },
    incidentPolicy: {
        notificationDeadlineHours: 72,
        reference: 'GDS Policy DUC terms; NIH Program Officer notification required promptly for unauthorized genomic data access',
        requiredRecipients: ['nih-program-officer', 'dbgap-dac', 'institution-research-compliance'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'nih-gds-controlled-access-dac-gate',
            description: 'Active Data Use Certificate required before processing controlled-access repository data',
            reference: 'GDS Policy (NOT-OD-14-124); dbGaP DUC terms',
            check: 'nih_dms_controlled_access_dac_gate',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nih-gds-genomic-identifiable-block',
            description: 'Re-identifiable genomic data treated as controlled-access',
            reference: 'GDS Policy; NIH Genomic Data Sharing guidance',
            check: 'nih_dms_genomic_identifiable_block',
            failSeverity: 'HIGH',
        },
        {
            id: 'nih-gds-behavioral-controlled-access-block',
            description: 'Runtime blocks CONTROLLED_ACCESS_REPOSITORY_DATA category without active DAC approval',
            reference: 'GDS Policy; dbGaP DUC terms',
            check: 'behavioralValidator_nih_data_sharing',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nih-gds-dac-expiry-block',
            description: 'Runtime blocks DAC_APPROVAL_EXPIRED category (GAP-6): expired DUC data must be blocked',
            reference: 'GDS Policy (NOT-OD-14-124) -- active Data Use Certificate required at all times',
            check: 'behavioralValidator_nih_dms_dac_expiry',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nih-gds-no-training-on-genomic-data',
            description: 'Provider attestation: no model training on NIH genomic data',
            reference: 'NOT-OD-14-124; GDS Policy; FTC guidance on research data training prohibition',
            check: 'nih_dms_no_training_on_research_data',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'nih-gds-audit-log-per-access',
            description: 'Every access to controlled-access genomic data logged with DAC reference and timestamp',
            reference: 'GDS Policy; NIH GPS (citation to verify section)',
            check: 'audit_trail_exists',
            failSeverity: 'HIGH',
        },
        {
            // F-NEW-VERA-PACK-C6-02: study-concluded-but-DUC-still-active gap.
            // DAC_APPROVAL_EXPIRED covers lapsed DUCs; this validator covers the
            // complementary scenario where the DUC is in-date but the study has
            // concluded and the DUC termination workflow should have been triggered.
            // Action is REQUIRE_APPROVAL not BLOCK: close-out work is legitimate
            // but must be reviewed by a human before continuing.
            id: 'nih-gds-study-concluded-duc-termination',
            description: 'Study concluded but DUC remains active: require human confirmation that DUC termination workflow has been initiated per GDS Policy closeout obligations',
            reference: 'GDS Policy (NOT-OD-14-124) -- DUC termination on research conclusion; dbGaP DUC standard terms (study closeout); NIH GPS closeout requirements; F-NEW-VERA-PACK-C6-02',
            check: 'nih_gds_study_concluded_duc_termination_active',
            failSeverity: 'HIGH',
        },
    ],
};
//# sourceMappingURL=us-nih-gds.js.map