@htilabs/platform-common-models 0.12.4 → 0.13.1
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/dist/constants/index.cjs +73 -0
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +1 -1
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/index.js +69 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/{cvcEntry-DaDrEuTa.d.cts → cvcEntry-0BIB9sen.d.cts} +44 -44
- package/dist/{cvcEntry-DaDrEuTa.d.ts → cvcEntry-0BIB9sen.d.ts} +44 -44
- package/dist/cvcs/index.cjs +1065 -236
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +1337 -484
- package/dist/cvcs/index.d.ts +1337 -484
- package/dist/cvcs/index.js +1065 -236
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +32 -17
- package/dist/enums/index.cjs.map +1 -1
- package/dist/enums/index.d.cts +38 -23
- package/dist/enums/index.d.ts +38 -23
- package/dist/enums/index.js +32 -17
- package/dist/enums/index.js.map +1 -1
- package/dist/{index-C0J3f169.d.ts → index-CDoqrfc1.d.ts} +1 -1
- package/dist/{index-EPjPjR0z.d.cts → index-Zu_mOJRn.d.cts} +1 -1
- package/dist/index.cjs +1170 -253
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1166 -253
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/{platform-auth-Dv5fu0Fh.d.cts → platform-auth-64U8jjuw.d.cts} +71 -2
- package/dist/{platform-auth-Dv5fu0Fh.d.ts → platform-auth-64U8jjuw.d.ts} +71 -2
- package/dist/schemas/index.cjs +62 -0
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +35 -35
- package/dist/schemas/index.d.ts +35 -35
- package/dist/schemas/index.js +62 -0
- package/dist/schemas/index.js.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/package.json +26 -27
- package/src/__tests__/__snapshots__/cvc-sot.snap +12 -12
- package/src/__tests__/core-information-scope-invariant.test.ts +28 -0
- package/src/__tests__/cvc-drift-gate.test.ts +16 -5
- package/src/__tests__/cvc-sot-snapshot.test.ts +24 -14
- package/src/__tests__/cvc-structural.test.ts +8 -8
- package/src/__tests__/incident-participation-roles-canon.test.ts +424 -0
- package/src/__tests__/referral-entity-category-canon.test.ts +383 -0
- package/src/__tests__/victim-abuse-types-canon.test.ts +301 -0
- package/src/constants/ic.ts +158 -0
- package/src/cvcs/coreInformationScope.v1.0.0.json +3 -3
- package/src/cvcs/{highestEducationLevelCompleted.v1.0.0.json → highestEducationLevelCompleted.v1.1.0.json} +1 -1
- package/src/cvcs/incidentParticipationRoles.v1.1.0.json +433 -0
- package/src/cvcs/{incomeBenefitsSources.v1.0.0.json → incomeBenefitsSources.v1.1.0.json} +1 -1
- package/src/cvcs/index.ts +8 -8
- package/src/cvcs/{referralEntityCategory.v1.0.0.json → referralEntityCategory.v1.1.0.json} +192 -54
- package/src/cvcs/{serviceStates.v1.0.0.json → serviceStates.v1.1.0.json} +1 -1
- package/src/cvcs/{sourceSubtype.v1.1.0.json → sourceSubtype.v1.2.0.json} +1 -1
- package/src/cvcs/{verificationMethod.v1.0.0.json → verificationMethod.v1.1.0.json} +1 -1
- package/src/cvcs/victimAbuseTypes.v1.1.0.json +744 -0
- package/src/generated/cvc-enums.ts +38 -23
- package/src/cvcs/incidentParticipationRoles.v1.0.0.json +0 -212
- package/src/cvcs/victimAbuseTypes.v1.0.0.json +0 -276
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REFERRAL ENTITY CATEGORY (CVC-48 / IC-58) — the canon v1.3 row pin
|
|
3
|
+
* ==================================================================
|
|
4
|
+
*
|
|
5
|
+
* platform-common's CVC-48 mirror shipped STALE through 0.13.0:
|
|
6
|
+
* referralEntityCategory v1.0.0 predated canon's 2026-08-20 full audit, so it
|
|
7
|
+
* lacked three leaves (Adult Protective Services, School / academic
|
|
8
|
+
* institution, Legal services provider), had Education selectable and Law
|
|
9
|
+
* enforcement / Police not, and carried the pre-audit MDT / Coalition wording.
|
|
10
|
+
* Nothing failed, because every gate here checks a SOT file against ITSELF.
|
|
11
|
+
*
|
|
12
|
+
* The CANON table below is TRANSCRIBED from canon — htilabstech/prototype
|
|
13
|
+
* `data/cvcs/core_referral_entity_category.yaml` v1.3 @ 9a10f480 (`entries:`,
|
|
14
|
+
* 46 rows) and the live Notion codebook
|
|
15
|
+
* `collection://3181ef14-abcd-8081-95b5-000bc30a73bd` (46 rows, compared
|
|
16
|
+
* 2026-10-05) — NOT derived from the JSON.
|
|
17
|
+
*
|
|
18
|
+
* It also pins the compatibility contract (consumers persist these KEYS):
|
|
19
|
+
* every v1.0.0 key is still an entry at its v1.0.0 positional code, and the
|
|
20
|
+
* three new leaves exist.
|
|
21
|
+
*
|
|
22
|
+
* And it pins the ONE canon row deliberately not carried: `02-02-01-00`
|
|
23
|
+
* Hotline (see `HELD` in scripts/gen-referral-entity-category.py). If that row
|
|
24
|
+
* is ever carried, this test must be changed on purpose.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { readFileSync } from "node:fs";
|
|
28
|
+
import path from "node:path";
|
|
29
|
+
import { fileURLToPath } from "node:url";
|
|
30
|
+
|
|
31
|
+
import { describe, it, expect } from "vitest";
|
|
32
|
+
|
|
33
|
+
import { ReferralEntityCategoryKeys } from "../generated/cvc-enums.js";
|
|
34
|
+
|
|
35
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
36
|
+
const FILE = path.join(here, "..", "cvcs", "referralEntityCategory.v1.1.0.json");
|
|
37
|
+
|
|
38
|
+
interface Entry {
|
|
39
|
+
code: string;
|
|
40
|
+
key: string;
|
|
41
|
+
title: string;
|
|
42
|
+
selectable: boolean;
|
|
43
|
+
parentCode: string | null;
|
|
44
|
+
childCodes: string[];
|
|
45
|
+
definition: string | null;
|
|
46
|
+
canonicalCode?: string;
|
|
47
|
+
}
|
|
48
|
+
interface Envelope {
|
|
49
|
+
domain: string;
|
|
50
|
+
version: string;
|
|
51
|
+
_status: string;
|
|
52
|
+
_source: string;
|
|
53
|
+
_supersedes: { version: string; keyMap: Record<string, string | null>; retiredCodes: unknown[] };
|
|
54
|
+
_notCarried: { canonicalCode: string; name: string; reason: string }[];
|
|
55
|
+
entries: Entry[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const env = JSON.parse(readFileSync(FILE, "utf-8")) as Envelope;
|
|
59
|
+
const byKey = new Map(env.entries.map((e) => [e.key, e]));
|
|
60
|
+
const byCode = new Map(env.entries.map((e) => [e.code, e]));
|
|
61
|
+
const get = (key: string): Entry => {
|
|
62
|
+
const e = byKey.get(key);
|
|
63
|
+
if (!e) throw new Error(`no entry with key ${key}`);
|
|
64
|
+
return e;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Canon's rows that this package carries (45 of 46), in canon code order:
|
|
69
|
+
* [canon code, package key, canon name, canon Selectable]. For the three
|
|
70
|
+
* Level-0 rows canon's name is a bare slug and the package keeps its house
|
|
71
|
+
* missingness title, so the title is not compared there (`null`).
|
|
72
|
+
*/
|
|
73
|
+
const CANON: readonly (readonly [string, string, string | null, boolean])[] = [
|
|
74
|
+
["00-00-01-00", "unknown", null, true],
|
|
75
|
+
["00-00-02-00", "anonymous", null, true],
|
|
76
|
+
["00-00-03-00", "data_not_collected", null, true],
|
|
77
|
+
["01-00-01-00", "self_referred", "Self-referred", true],
|
|
78
|
+
["01-00-02-00", "family_guardian_friend", "Family/guardian/friend/foster parent", true],
|
|
79
|
+
["01-00-03-00", "peer", "Peer / another client", true],
|
|
80
|
+
["01-00-04-00", "other_individual", "Other individual", true],
|
|
81
|
+
["02-01-00-00", "housing_shelter_continuum", "Housing / Shelter continuum", false],
|
|
82
|
+
["02-01-01-00", "outreach_project", "Outreach Project", true],
|
|
83
|
+
["02-01-02-00", "temporary_shelter", "Temporary Shelter", true],
|
|
84
|
+
["02-01-03-00", "residential_project", "Residential Project", true],
|
|
85
|
+
["02-02-00-00", "hotlines", "Hotlines", false],
|
|
86
|
+
["02-02-01-01", "national_hotline", "National hotline", true],
|
|
87
|
+
["02-02-01-02", "local_other_hotline", "Local/other hotline", true],
|
|
88
|
+
["02-03-00-00", "justice_protective_systems", "Justice & Protective Systems", false],
|
|
89
|
+
["02-03-01-00", "child_welfare_cps", "Child Welfare / CPS", true],
|
|
90
|
+
["02-03-02-00", "juvenile_justice", "Juvenile Justice", true],
|
|
91
|
+
["02-03-03-00", "law_enforcement", "Law enforcement / Police", true],
|
|
92
|
+
["02-03-03-01", "local_law_enforcement", "Local law enforcement", true],
|
|
93
|
+
["02-03-03-02", "state_law_enforcement", "State law enforcement", true],
|
|
94
|
+
["02-03-03-03", "federal_law_enforcement", "Federal law enforcement", true],
|
|
95
|
+
["02-03-03-04", "tribal_law_enforcement", "Tribal law enforcement", true],
|
|
96
|
+
["02-03-03-05", "other_law_enforcement", "Other/ unknown LE", true],
|
|
97
|
+
["02-03-04-00", "courts_prosecution", "Courts or prosecution", true],
|
|
98
|
+
["02-03-05-00", "correction_probation", "Correction / probation", true],
|
|
99
|
+
// Notion label; the yaml port omits "(APS)".
|
|
100
|
+
["02-03-06-00", "adult_protective_services", "Adult Protective Services (APS)", true],
|
|
101
|
+
["02-04-00-00", "health_behavioral_health", "Health / behavioral health", false],
|
|
102
|
+
["02-04-01-00", "inpatient_psychiatric_facility", "Inpatient psychiatric facility", true],
|
|
103
|
+
[
|
|
104
|
+
"02-04-02-00",
|
|
105
|
+
"healthcare_provider",
|
|
106
|
+
"Healthcare provider (non-inpatient psychiatric)",
|
|
107
|
+
true,
|
|
108
|
+
],
|
|
109
|
+
["02-05-00-00", "education", "Education", false],
|
|
110
|
+
["02-05-01-00", "school_academic_institution", "School / academic institution", true],
|
|
111
|
+
[
|
|
112
|
+
"02-06-00-00",
|
|
113
|
+
"victim_community_service_providers",
|
|
114
|
+
"Victim + Community service providers",
|
|
115
|
+
false,
|
|
116
|
+
],
|
|
117
|
+
["02-06-01-00", "child_advocacy_center", "Child Advocacy Center (CAC)", true],
|
|
118
|
+
[
|
|
119
|
+
"02-06-02-00",
|
|
120
|
+
"victim_service_provider",
|
|
121
|
+
"Victim service provider / advocacy program",
|
|
122
|
+
true,
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
"02-06-03-00",
|
|
126
|
+
"community_based_service_provider",
|
|
127
|
+
"Community-based service provider (general social services)",
|
|
128
|
+
true,
|
|
129
|
+
],
|
|
130
|
+
["02-06-04-00", "legal_services_provider", "Legal services provider", true],
|
|
131
|
+
["02-07-00-00", "coordination_governance", "Coordination & Governance", false],
|
|
132
|
+
["02-07-01-00", "mdt", "Multidisciplinary team (MDT)", true],
|
|
133
|
+
["02-07-02-00", "coalition", "Coalition (state/regional coalition)", true],
|
|
134
|
+
["02-08-00-00", "internal", "Internal", false],
|
|
135
|
+
["02-08-01-00", "own_agency_internal", "Own agency / internal referral", true],
|
|
136
|
+
["02-09-00-00", "other_entity", "Other", false],
|
|
137
|
+
["02-09-01-00", "employer", "Employer", true],
|
|
138
|
+
["02-09-02-00", "benefits_public_assistance_office", "Benefits/public assistance office", true],
|
|
139
|
+
["02-09-03-00", "other_organization", "Other Organization", true],
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Canon's definition for each carried row, VERBATIM: the yaml port
|
|
144
|
+
* (`data/cvcs/core_referral_entity_category.yaml` @ 9a10f480) except the
|
|
145
|
+
* definition cells where the live Notion codebook wording is used instead
|
|
146
|
+
* (generator `NOTION_WORDING`). `null` where canon has no definition (headings
|
|
147
|
+
* and the Level-0 rows). Transcribed, not derived from the JSON.
|
|
148
|
+
*/
|
|
149
|
+
const CANON_DEFINITIONS: Readonly<Record<string, string | null>> = {
|
|
150
|
+
"00-00-01-00": "Referral entity category unknown.",
|
|
151
|
+
"00-00-02-00": "Referral entity category withheld or redacted.",
|
|
152
|
+
"00-00-03-00": "Referral entity category not collected or no signal captured.",
|
|
153
|
+
"01-00-01-00": "Client initiated contact or presented for services without a third-party referrer.",
|
|
154
|
+
"01-00-02-00": "A caregiver, family member, or close personal support person initiated the referral.",
|
|
155
|
+
"01-00-03-00": "Another current or former client initiated or encouraged the referral.",
|
|
156
|
+
"01-00-04-00": "A non-family individual initiated the referral (e.g., neighbor, community member, clergy).",
|
|
157
|
+
"02-01-00-00": "Primary function is outreach engagement, emergency shelter, or residential shelter/housing programs.",
|
|
158
|
+
"02-01-01-00": "Street/community outreach program that engaged the client prior to enrollment.",
|
|
159
|
+
"02-01-02-00": "Emergency/crisis shelter or short-term temporary housing program.",
|
|
160
|
+
"02-01-03-00": "Longer-term residential or transitional living program.",
|
|
161
|
+
"02-02-00-00": "Crisis lines or call centers that connect a person to services.",
|
|
162
|
+
"02-02-01-01": "National-level hotline network.",
|
|
163
|
+
"02-02-01-02": "Local/regional hotline or non-national hotline.",
|
|
164
|
+
"02-03-00-00": null,
|
|
165
|
+
"02-03-01-00": "Government child protection agency responsible for investigating child abuse/neglect and ensuring child safety.",
|
|
166
|
+
"02-03-02-00": "Juvenile probation/detention/court-related juvenile justice system initiated the referral.",
|
|
167
|
+
"02-03-03-00": "Law enforcement agency initiated the referral (local/state/federal).",
|
|
168
|
+
"02-03-03-01": "City/county police or sheriff.",
|
|
169
|
+
"02-03-03-02": "State-level law enforcement agency (e.g., state police/highway patrol/state bureau of investigation) acting in an official capacity.",
|
|
170
|
+
"02-03-03-03": "Federal law enforcement agency (e.g., FBI, DHS/ICE).",
|
|
171
|
+
"02-03-03-04": "Tribal police.",
|
|
172
|
+
"02-03-03-05": "Other law enforcement entity, or law enforcement type is unknown.",
|
|
173
|
+
"02-03-04-00": "Court or prosecution entity (not law enforcement).",
|
|
174
|
+
"02-03-05-00": "Corrections, probation, parole, or community supervision entity (not law enforcement).",
|
|
175
|
+
"02-03-06-00": "Government adult protection agency responsible for investigating abuse, neglect, self-neglect, or exploitation of vulnerable or older adults and ensuring their safety. Adult analog of Child Welfare / CPS.",
|
|
176
|
+
"02-04-00-00": "Hospitals and healthcare providers (including mental health inpatient facilities).",
|
|
177
|
+
"02-04-01-00": "Inpatient psychiatric hospital or psychiatric facility.",
|
|
178
|
+
"02-04-02-00": "Any non-inpatient healthcare provider (clinic, hospital, outpatient provider, behavioral health clinic, SANE program, substance abuse clinic, etc.).",
|
|
179
|
+
"02-05-00-00": "Parent category for education-related institutions.",
|
|
180
|
+
"02-05-01-00": "School system or educational institution.",
|
|
181
|
+
"02-06-00-00": "Parent category for victim service providers and community-based service providers.",
|
|
182
|
+
"02-06-01-00": "A child-centered multidisciplinary center coordinating investigation and services (forensic interview, coordination, referrals, sometimes medical or therapy) for child victims.",
|
|
183
|
+
"02-06-02-00": "Organization whose primary mission is to provide services to victims/survivors of crime (VOCA-aligned breadth: rape crisis centers, DV/dating-violence/stalking programs, anti-trafficking programs, child victim centers, homicide-survivor organizations, and similar). Whether the organization is specifically a DV/SA victim service provider — the fact HMIS 2.01 needs (Comparable Database) — is a separate per-organization attribute, self-attested by the organization at onboarding (Platform survey / Agency Hub “My agency info”), not part of this category.",
|
|
184
|
+
"02-06-03-00": "The residual community-based provider (“other community-based service provider”): a non-VSP offering practical support services, navigation, or stabilization resources that is not primarily a VSP, a legal services provider, a housing/shelter project, a government justice agency, a healthcare provider, a school, a hotline, or a public benefits office. (Ex: youth drop-in center; food pantry; reentry program.)",
|
|
185
|
+
"02-06-04-00": "Civil legal aid organization, immigration attorneys, victim-rights law clinic, or similar provider of legal help to the client. Distinct from Courts or prosecution (the justice-system entity itself): this is getting a lawyer's help, not being referred into proceedings.",
|
|
186
|
+
"02-07-00-00": "Parent category for coordination and governance bodies (e.g., MDTs, coalitions).",
|
|
187
|
+
"02-07-01-00": "A case-level team: professionals from multiple agencies (law enforcement, child welfare, medical, advocacy) who review and coordinate individual cases together; referrals arise out of case review. (E.g., a county trafficking MDT or a CAC-based team.)",
|
|
188
|
+
"02-07-02-00": "A state or regional membership body of organizations coordinating at the system level — training, standards, policy, funding — not individual cases; referrals from a coalition are typically warm handoffs to a member organization.",
|
|
189
|
+
"02-08-00-00": "Parent category for internal referrals within the same umbrella agency.",
|
|
190
|
+
"02-08-01-00": "Client was referred from another program or unit within the same umbrella agency.",
|
|
191
|
+
"02-09-00-00": "Parent category for other organizations not captured by the primary sectors.",
|
|
192
|
+
"02-09-01-00": "Employer, HR, or employee assistance program initiated the referral.",
|
|
193
|
+
"02-09-02-00": "Government office administering public benefits or eligibility and enrollment (e.g., SNAP, TANF, Medicaid, SSA).",
|
|
194
|
+
"02-09-03-00": "Other organization not otherwise captured by the listed categories.",
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/** The canon row deliberately NOT carried (generator `HELD`). */
|
|
198
|
+
const HELD_CANON_CODE = "02-02-01-00";
|
|
199
|
+
|
|
200
|
+
const code = (...segs: number[]): string =>
|
|
201
|
+
[48, ...segs, ...Array(6 - segs.length).fill(0)]
|
|
202
|
+
.map((n) => String(n).padStart(3, "0"))
|
|
203
|
+
.join("-");
|
|
204
|
+
|
|
205
|
+
/** Every key v1.0.0 published (platform-common <= 0.13.0), with its code. */
|
|
206
|
+
const V1_0_0: Readonly<Record<string, string>> = {
|
|
207
|
+
missingness_root: "048-000-000-000-000-000-000",
|
|
208
|
+
unknown: "048-000-000-000-000-000-001",
|
|
209
|
+
anonymous: "048-000-000-000-000-000-002",
|
|
210
|
+
data_not_collected: "048-000-000-000-000-000-003",
|
|
211
|
+
self_referred: code(1),
|
|
212
|
+
family_guardian_friend: code(2),
|
|
213
|
+
peer: code(3),
|
|
214
|
+
other_individual: code(4),
|
|
215
|
+
housing_shelter_continuum: code(5),
|
|
216
|
+
outreach_project: code(5, 1),
|
|
217
|
+
temporary_shelter: code(5, 2),
|
|
218
|
+
residential_project: code(5, 3),
|
|
219
|
+
hotlines: code(6),
|
|
220
|
+
national_hotline: code(6, 1),
|
|
221
|
+
local_other_hotline: code(6, 2),
|
|
222
|
+
justice_protective_systems: code(7),
|
|
223
|
+
child_welfare_cps: code(7, 1),
|
|
224
|
+
juvenile_justice: code(7, 2),
|
|
225
|
+
law_enforcement: code(7, 3),
|
|
226
|
+
local_law_enforcement: code(7, 3, 1),
|
|
227
|
+
state_law_enforcement: code(7, 3, 2),
|
|
228
|
+
federal_law_enforcement: code(7, 3, 3),
|
|
229
|
+
tribal_law_enforcement: code(7, 3, 4),
|
|
230
|
+
other_law_enforcement: code(7, 3, 5),
|
|
231
|
+
courts_prosecution: code(7, 4),
|
|
232
|
+
correction_probation: code(7, 5),
|
|
233
|
+
health_behavioral_health: code(8),
|
|
234
|
+
inpatient_psychiatric_facility: code(8, 1),
|
|
235
|
+
healthcare_provider: code(8, 2),
|
|
236
|
+
education: code(9),
|
|
237
|
+
victim_community_service_providers: code(10),
|
|
238
|
+
child_advocacy_center: code(10, 1),
|
|
239
|
+
victim_service_provider: code(10, 2),
|
|
240
|
+
community_based_service_provider: code(10, 3),
|
|
241
|
+
coordination_governance: code(11),
|
|
242
|
+
mdt: code(11, 1),
|
|
243
|
+
coalition: code(11, 2),
|
|
244
|
+
internal: code(12),
|
|
245
|
+
own_agency_internal: code(12, 1),
|
|
246
|
+
other_entity: code(13),
|
|
247
|
+
employer: code(13, 1),
|
|
248
|
+
benefits_public_assistance_office: code(13, 2),
|
|
249
|
+
other_organization: code(13, 3),
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/** Leaves added in v1.1.0: [key, minted positional code, parent key]. */
|
|
253
|
+
const ADDED: readonly (readonly [string, string, string])[] = [
|
|
254
|
+
["adult_protective_services", code(7, 6), "justice_protective_systems"],
|
|
255
|
+
["school_academic_institution", code(9, 1), "education"],
|
|
256
|
+
["legal_services_provider", code(10, 4), "victim_community_service_providers"],
|
|
257
|
+
];
|
|
258
|
+
|
|
259
|
+
/** Canon's parent of a canon code, read off the code itself. */
|
|
260
|
+
function canonParent(c: string): string | null {
|
|
261
|
+
const [a, b, y, z] = c.split("-");
|
|
262
|
+
if (a !== "02") return null;
|
|
263
|
+
if (z !== "00") return `${a}-${b}-${y}-00`;
|
|
264
|
+
if (y !== "00") return `${a}-${b}-00-00`;
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
describe("CVC-48 referral_entity_category — canon v1.3 mirror", () => {
|
|
269
|
+
it("is v1.1.0 of the referral_entity_category domain, pinned to its canon source", () => {
|
|
270
|
+
expect(env.domain).toBe("referral_entity_category");
|
|
271
|
+
expect(env.version).toBe("1.1.0");
|
|
272
|
+
expect(env._source).toMatch(/core_referral_entity_category\.yaml @ [0-9a-f]{8} /);
|
|
273
|
+
expect(env._source).toContain("yaml v1.3");
|
|
274
|
+
expect(env._status.startsWith("CANONICAL")).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("carries exactly the 45 canon codes in the table, each once (+ missingness_root)", () => {
|
|
278
|
+
const carried = env.entries
|
|
279
|
+
.filter((e) => e.canonicalCode !== undefined)
|
|
280
|
+
.map((e) => e.canonicalCode);
|
|
281
|
+
expect([...carried].sort()).toEqual(CANON.map((r) => r[0]).sort());
|
|
282
|
+
expect(new Set(carried).size).toBe(45);
|
|
283
|
+
expect(env.entries.filter((e) => e.canonicalCode === undefined).map((e) => e.key)).toEqual([
|
|
284
|
+
"missingness_root",
|
|
285
|
+
]);
|
|
286
|
+
expect(env.entries.length).toBe(46);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
for (const [canonCode, key, name, selectable] of CANON) {
|
|
290
|
+
it(`${canonCode} ${key}: name, Selectable, definition and parent match canon`, () => {
|
|
291
|
+
const e = get(key);
|
|
292
|
+
expect(e.canonicalCode).toBe(canonCode);
|
|
293
|
+
if (name !== null) expect(e.title).toBe(name);
|
|
294
|
+
expect(e.selectable).toBe(selectable);
|
|
295
|
+
expect(e.definition, "canon definition").toBe(CANON_DEFINITIONS[canonCode]);
|
|
296
|
+
const parent = e.parentCode === null ? null : byCode.get(e.parentCode) ?? null;
|
|
297
|
+
const want = canonParent(canonCode);
|
|
298
|
+
if (canonCode.startsWith("00-")) {
|
|
299
|
+
expect(parent?.key).toBe("missingness_root");
|
|
300
|
+
} else if (want === HELD_CANON_CODE) {
|
|
301
|
+
// Canon parent is the held Hotline row: sits under ITS parent instead.
|
|
302
|
+
expect(parent?.canonicalCode).toBe(canonParent(HELD_CANON_CODE));
|
|
303
|
+
} else {
|
|
304
|
+
expect(parent?.canonicalCode ?? null).toBe(want);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
it("a non-selectable heading always has at least one leaf to record instead", () => {
|
|
310
|
+
for (const e of env.entries) {
|
|
311
|
+
if (!e.selectable) expect(e.childCodes.length, e.key).toBeGreaterThan(0);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("Education is a heading; School / academic institution is its only leaf", () => {
|
|
316
|
+
expect(get("education").selectable).toBe(false);
|
|
317
|
+
expect(get("education").childCodes).toEqual([get("school_academic_institution").code]);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("Law enforcement / Police is selectable and keeps its five optional children", () => {
|
|
321
|
+
expect(get("law_enforcement").selectable).toBe(true);
|
|
322
|
+
expect(get("law_enforcement").childCodes.length).toBe(5);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("canon Hotline (02-02-01-00) is HELD: not carried, and recorded as such", () => {
|
|
326
|
+
expect(env.entries.some((e) => e.canonicalCode === HELD_CANON_CODE)).toBe(false);
|
|
327
|
+
expect(byKey.has("hotline")).toBe(false);
|
|
328
|
+
expect(env._notCarried.map((r) => r.canonicalCode)).toEqual([HELD_CANON_CODE]);
|
|
329
|
+
expect(env._notCarried[0]?.name).toBe("Hotline");
|
|
330
|
+
// Its two canon children stay where v1.0.0 published them.
|
|
331
|
+
expect(get("national_hotline").parentCode).toBe(get("hotlines").code);
|
|
332
|
+
expect(get("local_other_hotline").parentCode).toBe(get("hotlines").code);
|
|
333
|
+
expect(get("hotlines").childCodes).toEqual([
|
|
334
|
+
get("national_hotline").code,
|
|
335
|
+
get("local_other_hotline").code,
|
|
336
|
+
]);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("CVC-48 v1.1.0 is ADDITIVE — stored v1.0.0 keys stay readable", () => {
|
|
341
|
+
it("v1.0.0 published 43 keys", () => {
|
|
342
|
+
expect(Object.keys(V1_0_0).length).toBe(43);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("every v1.0.0 key is still an entry, at its v1.0.0 positional code", () => {
|
|
346
|
+
for (const [key, c] of Object.entries(V1_0_0)) {
|
|
347
|
+
expect(byKey.has(key), `v1.0.0 key removed: ${key}`).toBe(true);
|
|
348
|
+
expect(get(key).code, key).toBe(c);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("every v1.0.0 key is still in the generated ReferralEntityCategoryKeys map", () => {
|
|
353
|
+
const generated = ReferralEntityCategoryKeys as Record<string, string>;
|
|
354
|
+
for (const [key, c] of Object.entries(V1_0_0)) expect(generated[key], key).toBe(c);
|
|
355
|
+
expect(Object.keys(generated).length).toBe(46);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
for (const [key, c, parentKey] of ADDED) {
|
|
359
|
+
it(`${key} is added at ${c}, a selectable leaf under ${parentKey}`, () => {
|
|
360
|
+
const e = get(key);
|
|
361
|
+
expect(e.code).toBe(c);
|
|
362
|
+
expect(e.selectable).toBe(true);
|
|
363
|
+
expect(e.childCodes).toEqual([]);
|
|
364
|
+
expect(e.parentCode).toBe(get(parentKey).code);
|
|
365
|
+
expect(e.definition).toBeTruthy();
|
|
366
|
+
expect(Object.values(V1_0_0), `${key} reuses a v1.0.0 code`).not.toContain(c);
|
|
367
|
+
expect((ReferralEntityCategoryKeys as Record<string, string>)[key]).toBe(c);
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
it("the entry set is exactly v1.0.0's 43 keys plus the 3 added leaves", () => {
|
|
372
|
+
expect([...byKey.keys()].sort()).toEqual(
|
|
373
|
+
[...Object.keys(V1_0_0), ...ADDED.map((r) => r[0])].sort(),
|
|
374
|
+
);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("_supersedes maps every v1.0.0 key to itself — nothing was renamed or retired", () => {
|
|
378
|
+
expect(env._supersedes.version).toBe("1.0.0");
|
|
379
|
+
expect(Object.keys(env._supersedes.keyMap).sort()).toEqual(Object.keys(V1_0_0).sort());
|
|
380
|
+
for (const [k, v] of Object.entries(env._supersedes.keyMap)) expect(v, k).toBe(k);
|
|
381
|
+
expect(env._supersedes.retiredCodes).toEqual([]);
|
|
382
|
+
});
|
|
383
|
+
});
|