@htilabs/platform-common-models 0.17.0 → 0.19.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.
Files changed (82) hide show
  1. package/dist/agency-BHv54o79.d.ts +484 -0
  2. package/dist/agency-Ca4pCOOf.d.ts +342 -0
  3. package/dist/agency-DYCv839V.d.cts +342 -0
  4. package/dist/agency-Djp57S71.d.cts +484 -0
  5. package/dist/constants/index.cjs +952 -0
  6. package/dist/constants/index.cjs.map +1 -1
  7. package/dist/constants/index.d.cts +3 -1
  8. package/dist/constants/index.d.ts +3 -1
  9. package/dist/constants/index.js +920 -0
  10. package/dist/constants/index.js.map +1 -1
  11. package/dist/{cvcEntry-ctHTp2df.d.cts → cvcEntry-BCj1OWqL.d.cts} +44 -44
  12. package/dist/{cvcEntry-ctHTp2df.d.ts → cvcEntry-BCj1OWqL.d.ts} +44 -44
  13. package/dist/cvcs/index.cjs +1078 -1026
  14. package/dist/cvcs/index.cjs.map +1 -1
  15. package/dist/cvcs/index.d.cts +1057 -1004
  16. package/dist/cvcs/index.d.ts +1057 -1004
  17. package/dist/cvcs/index.js +1069 -1017
  18. package/dist/cvcs/index.js.map +1 -1
  19. package/dist/enums/index.cjs +143 -142
  20. package/dist/enums/index.cjs.map +1 -1
  21. package/dist/enums/index.d.cts +145 -144
  22. package/dist/enums/index.d.ts +145 -144
  23. package/dist/enums/index.js +143 -142
  24. package/dist/enums/index.js.map +1 -1
  25. package/dist/{index-qreOzXYS.d.cts → index-CoVr1jIV.d.cts} +1 -1
  26. package/dist/{index-4DiJrn7y.d.ts → index-I-DiX9eQ.d.ts} +1 -1
  27. package/dist/index.cjs +2762 -2185
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +6 -4
  30. package/dist/index.d.ts +6 -4
  31. package/dist/index.js +2708 -2184
  32. package/dist/index.js.map +1 -1
  33. package/dist/models/index.cjs +1 -1
  34. package/dist/models/index.cjs.map +1 -1
  35. package/dist/models/index.d.cts +2 -2
  36. package/dist/models/index.d.ts +2 -2
  37. package/dist/models/index.js +1 -1
  38. package/dist/models/index.js.map +1 -1
  39. package/dist/org-type-BYQb9Qzq.d.ts +366 -0
  40. package/dist/org-type-D_FG4KdN.d.cts +366 -0
  41. package/dist/{platform-auth-CrF5U_JH.d.cts → platform-auth-CvAYFVhK.d.cts} +39 -0
  42. package/dist/{platform-auth-CrF5U_JH.d.ts → platform-auth-CvAYFVhK.d.ts} +39 -0
  43. package/dist/schemas/index.cjs +978 -3
  44. package/dist/schemas/index.cjs.map +1 -1
  45. package/dist/schemas/index.d.cts +38 -35
  46. package/dist/schemas/index.d.ts +38 -35
  47. package/dist/schemas/index.js +963 -2
  48. package/dist/schemas/index.js.map +1 -1
  49. package/dist/services/index.cjs +1 -1
  50. package/dist/services/index.cjs.map +1 -1
  51. package/dist/services/index.js +1 -1
  52. package/dist/services/index.js.map +1 -1
  53. package/dist/types/index.d.cts +2 -2
  54. package/dist/types/index.d.ts +2 -2
  55. package/dist/validation/index.cjs +894 -2
  56. package/dist/validation/index.cjs.map +1 -1
  57. package/dist/validation/index.d.cts +5 -1
  58. package/dist/validation/index.d.ts +5 -1
  59. package/dist/validation/index.js +884 -1
  60. package/dist/validation/index.js.map +1 -1
  61. package/package.json +26 -27
  62. package/src/__tests__/__snapshots__/cvc-sot.snap +3 -3
  63. package/src/__tests__/cvc-sot-snapshot.test.ts +6 -6
  64. package/src/__tests__/cvc-structural.test.ts +3 -3
  65. package/src/__tests__/org-type-contract.test.ts +1353 -0
  66. package/src/__tests__/referral-entity-category-canon.test.ts +255 -81
  67. package/src/constants/ic.ts +45 -0
  68. package/src/constants/index.ts +1 -0
  69. package/src/constants/org-type.ts +703 -0
  70. package/src/cvcs/index.ts +2 -2
  71. package/src/cvcs/{referralEntityCategory.v1.1.0.json → referralEntityCategory.v1.2.0.json} +111 -59
  72. package/src/cvcs/{serviceCategories.v1.0.0.json → serviceCategories.v1.2.0.json} +955 -955
  73. package/src/generated/cvc-enums.ts +145 -144
  74. package/src/index.ts +23 -0
  75. package/src/schemas/agency.ts +481 -0
  76. package/src/schemas/cvcRegistry.ts +1 -1
  77. package/src/schemas/index.ts +24 -0
  78. package/src/services/__tests__/cvcRegistryService.test.ts +11 -11
  79. package/src/validation/agency.ts +119 -0
  80. package/src/validation/index.ts +1 -0
  81. package/dist/team-C4LJ5Tex.d.cts +0 -333
  82. package/dist/team-C4LJ5Tex.d.ts +0 -333
@@ -20,9 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/schemas/index.ts
21
21
  var schemas_exports = {};
22
22
  __export(schemas_exports, {
23
+ AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS: () => AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS,
24
+ ORG_TYPE_FIELD_NAMES: () => ORG_TYPE_FIELD_NAMES,
23
25
  TEAM_MODEL_NAME: () => TEAM_MODEL_NAME,
26
+ VSP_TWO_STEP_ISSUE: () => VSP_TWO_STEP_ISSUE,
27
+ addAgencyOrgTypeFields: () => addAgencyOrgTypeFields,
28
+ addOrgTypeFields: () => addOrgTypeFields,
24
29
  addTeamDirectoryFields: () => addTeamDirectoryFields,
25
30
  addressSchema: () => addressSchema,
31
+ agencyOrgTypeSchemaDefinition: () => agencyOrgTypeSchemaDefinition,
32
+ applyRunValidatorsIfUnset: () => applyRunValidatorsIfUnset,
26
33
  buildCvcEntrySchema: () => buildCvcEntrySchema,
27
34
  buildCvcRegistrySchema: () => buildCvcRegistrySchema,
28
35
  buildFormSchema: () => buildFormSchema,
@@ -43,6 +50,9 @@ __export(schemas_exports, {
43
50
  formSectionRefSchema: () => formSectionRefSchema,
44
51
  guidanceSchema: () => guidanceSchema,
45
52
  layoutSchema: () => layoutSchema,
53
+ mirrorOrgTypeFields: () => mirrorOrgTypeFields,
54
+ orgTypeFieldsDiffer: () => orgTypeFieldsDiffer,
55
+ orgTypeSchemaDefinition: () => orgTypeSchemaDefinition,
46
56
  personNameSchema: () => personNameSchema,
47
57
  phoneSchema: () => phoneSchema,
48
58
  platformFunctionSchemaDefinition: () => platformFunctionSchemaDefinition,
@@ -51,6 +61,8 @@ __export(schemas_exports, {
51
61
  platformRoleSchemaOptions: () => platformRoleSchemaOptions,
52
62
  questionSchemaDefinition: () => questionSchemaDefinition,
53
63
  questionSchemaOptions: () => questionSchemaOptions,
64
+ resolveEffectiveOrgType: () => resolveEffectiveOrgType,
65
+ resolveEffectiveOrgTypeFields: () => resolveEffectiveOrgTypeFields,
54
66
  scoringConditionSchema: () => scoringConditionSchema,
55
67
  scoringRecommendationSchema: () => scoringRecommendationSchema,
56
68
  scoringRuleSchemaDefinition: () => scoringRuleSchemaDefinition,
@@ -60,7 +72,9 @@ __export(schemas_exports, {
60
72
  sectionSchemaDefinition: () => sectionSchemaDefinition,
61
73
  sectionSchemaOptions: () => sectionSchemaOptions,
62
74
  teamDirectorySchemaDefinition: () => teamDirectorySchemaDefinition,
63
- visibilityRuleSchema: () => visibilityRuleSchema
75
+ visibilityRuleSchema: () => visibilityRuleSchema,
76
+ vspTwoStepHolds: () => vspTwoStepHolds,
77
+ vspTwoStepHoldsOnUpdate: () => vspTwoStepHoldsOnUpdate
64
78
  });
65
79
  module.exports = __toCommonJS(schemas_exports);
66
80
 
@@ -4756,7 +4770,7 @@ var cvcRegistrySchemaDefinition = {
4756
4770
  dateDeactivated: {
4757
4771
  type: Date
4758
4772
  },
4759
- // Pinned domain versions: { service_categories: "1.0.0", ... }
4773
+ // Pinned domain versions: { service_categories: "1.2.0", ... }
4760
4774
  // Stored as a Map<string, string> so individual domains can be added or
4761
4775
  // bumped without re-validating the whole document shape.
4762
4776
  cvcVersions: {
@@ -4901,11 +4915,965 @@ function buildCvcEntrySchema() {
4901
4915
  return schema;
4902
4916
  }
4903
4917
  var _cvcEntrySchema = buildCvcEntrySchema();
4918
+
4919
+ // src/schemas/agency.ts
4920
+ var import_mongoose11 = require("mongoose");
4921
+
4922
+ // src/cvcs/referralEntityCategory.v1.2.0.json
4923
+ var referralEntityCategory_v1_2_0_default = {
4924
+ domain: "referral_entity_category",
4925
+ name: "Core Referral Entity Category",
4926
+ version: "1.2.0",
4927
+ _status: "CANONICAL \u2014 Notion CVC-48 `core-referral_entity_category` (IC-58), status Active (full audit 2026-08-20, CVC48_IC58_REFERRAL_ENTITY_CATEGORY_AUDIT; `Date of last audit` 2026-09-01). Re-mirrored from prototype canon yaml v1.3 @ f1321e47 and the live Notion codebook (46 rows, compared row by row 2026-10-05). SUPERSEDES referralEntityCategory v1.0.0 (platform-common <= 0.13.0), which predated the audit. ADDITIVE: no v1.0.0 key is removed and no v1.0.0 positional code changes. ADDED (4): `adult_protective_services` (02-03-06-00), `school_academic_institution` (02-05-01-00), `legal_services_provider` (02-06-04-00), and since 0.18.0 `hotline` (02-02-01-00, canon's selectable Level-2 parent of the two hotline children) at the next free ordinal 048-006-003 with `national_hotline` / `local_other_hotline` RE-PARENTED under it \u2014 their codes are unchanged (a positional code is identity, `parentCode` is hierarchy). SELECTABLE follows canon on two rows: `education` is now a non-selectable heading (its leaf is `school_academic_institution`, which carries the HMIS R1 School rollup \u2014 ruled 2026-08-20) and `law_enforcement` is now selectable (canon Level 2 Required; its five children are optional depth). A stored `education` is still a valid key. `title` and `definition` are canon's, verbatim (yaml `name` / `definition`; the live Notion wording where the two differ: the Adult Protective Services label, the quotation marks in the Victim service provider definition, and the wording of the residual Community-based provider definition); the Level-0 rows keep the package's house missingness titles. `justice_protective_systems` no longer carries the package-authored definition v1.0.0 gave it: canon's heading (02-03-00-00) has none. Every canon-backed row carries canon's 4-segment code as `canonicalCode`; the package's own positional codes are unchanged and are NOT canon's. NOT carried: canon `hmis_r1_code` / `hmis_r1_mapping`, `required`, `voca_ovc_pmt_bucket`, `pave_2025_mapping`, `logic_notes`, `mappings_notes` (v1.0.0 carried none of them). CARRIED since 0.18.0: canon `enum_constant` as `enumConstant` on every canon-backed row (the Sean-spec constant the org registry / `agencies.typeId` spell the type with). Generated by scripts/gen-referral-entity-category.py \u2014 do not hand-edit.",
4928
+ _source: "htilabstech/prototype/data/cvcs/core_referral_entity_category.yaml @ f1321e47 (Notion CVC-48, yaml v1.3; read from origin/main) + Notion codebook collection://3181ef14-abcd-8081-95b5-000bc30a73bd (wording of 3 cells, compared 2026-10-05)",
4929
+ _supersedes: {
4930
+ version: "1.0.0",
4931
+ keyMap: {
4932
+ missingness_root: "missingness_root",
4933
+ unknown: "unknown",
4934
+ anonymous: "anonymous",
4935
+ data_not_collected: "data_not_collected",
4936
+ self_referred: "self_referred",
4937
+ family_guardian_friend: "family_guardian_friend",
4938
+ peer: "peer",
4939
+ other_individual: "other_individual",
4940
+ housing_shelter_continuum: "housing_shelter_continuum",
4941
+ outreach_project: "outreach_project",
4942
+ temporary_shelter: "temporary_shelter",
4943
+ residential_project: "residential_project",
4944
+ hotlines: "hotlines",
4945
+ national_hotline: "national_hotline",
4946
+ local_other_hotline: "local_other_hotline",
4947
+ justice_protective_systems: "justice_protective_systems",
4948
+ child_welfare_cps: "child_welfare_cps",
4949
+ juvenile_justice: "juvenile_justice",
4950
+ law_enforcement: "law_enforcement",
4951
+ local_law_enforcement: "local_law_enforcement",
4952
+ state_law_enforcement: "state_law_enforcement",
4953
+ federal_law_enforcement: "federal_law_enforcement",
4954
+ tribal_law_enforcement: "tribal_law_enforcement",
4955
+ other_law_enforcement: "other_law_enforcement",
4956
+ courts_prosecution: "courts_prosecution",
4957
+ correction_probation: "correction_probation",
4958
+ health_behavioral_health: "health_behavioral_health",
4959
+ inpatient_psychiatric_facility: "inpatient_psychiatric_facility",
4960
+ healthcare_provider: "healthcare_provider",
4961
+ education: "education",
4962
+ victim_community_service_providers: "victim_community_service_providers",
4963
+ child_advocacy_center: "child_advocacy_center",
4964
+ victim_service_provider: "victim_service_provider",
4965
+ community_based_service_provider: "community_based_service_provider",
4966
+ coordination_governance: "coordination_governance",
4967
+ mdt: "mdt",
4968
+ coalition: "coalition",
4969
+ internal: "internal",
4970
+ own_agency_internal: "own_agency_internal",
4971
+ other_entity: "other_entity",
4972
+ employer: "employer",
4973
+ benefits_public_assistance_office: "benefits_public_assistance_office",
4974
+ other_organization: "other_organization"
4975
+ },
4976
+ retiredCodes: [],
4977
+ notes: {
4978
+ education: "v1.0.0 `education` was a selectable leaf. Canon makes Education a heading whose only leaf is School / academic institution. `education` stays a valid stored key (now `selectable: false`); the specific successor for a school is `school_academic_institution`. Not mapped automatically.",
4979
+ law_enforcement: "v1.0.0 `law_enforcement` was a non-selectable heading. Canon makes Law enforcement / Police a selectable leaf with five optional children."
4980
+ }
4981
+ },
4982
+ _notCarried: [],
4983
+ levels: {
4984
+ "0": "Unknown or Missing",
4985
+ "1": "Category",
4986
+ "2": "Entity",
4987
+ "3": "Variant"
4988
+ },
4989
+ entries: [
4990
+ {
4991
+ code: "048-000-000-000-000-000-000",
4992
+ key: "missingness_root",
4993
+ title: "Unknown, Redacted, or Missing",
4994
+ selectable: false,
4995
+ parentCode: null,
4996
+ childCodes: [
4997
+ "048-000-000-000-000-000-001",
4998
+ "048-000-000-000-000-000-002",
4999
+ "048-000-000-000-000-000-003"
5000
+ ],
5001
+ definition: "Root group for values indicating absent, withheld, or uncollected data."
5002
+ },
5003
+ {
5004
+ code: "048-000-000-000-000-000-001",
5005
+ key: "unknown",
5006
+ title: "Unknown",
5007
+ selectable: true,
5008
+ parentCode: "048-000-000-000-000-000-000",
5009
+ childCodes: [],
5010
+ definition: "Referral entity category unknown.",
5011
+ canonicalCode: "00-00-01-00",
5012
+ enumConstant: "EMPTY_RESPONSE_UNKNOWN"
5013
+ },
5014
+ {
5015
+ code: "048-000-000-000-000-000-002",
5016
+ key: "anonymous",
5017
+ title: "Anonymous",
5018
+ selectable: true,
5019
+ parentCode: "048-000-000-000-000-000-000",
5020
+ childCodes: [],
5021
+ definition: "Referral entity category withheld or redacted.",
5022
+ canonicalCode: "00-00-02-00",
5023
+ enumConstant: "EMPTY_RESPONSE_ANONYMOUS"
5024
+ },
5025
+ {
5026
+ code: "048-000-000-000-000-000-003",
5027
+ key: "data_not_collected",
5028
+ title: "Data not collected",
5029
+ selectable: true,
5030
+ parentCode: "048-000-000-000-000-000-000",
5031
+ childCodes: [],
5032
+ definition: "Referral entity category not collected or no signal captured.",
5033
+ canonicalCode: "00-00-03-00",
5034
+ enumConstant: "EMPTY_RESPONSE_NOTCOLLECTED"
5035
+ },
5036
+ {
5037
+ code: "048-001-000-000-000-000-000",
5038
+ key: "self_referred",
5039
+ title: "Self-referred",
5040
+ selectable: true,
5041
+ parentCode: null,
5042
+ childCodes: [],
5043
+ definition: "Client initiated contact or presented for services without a third-party referrer.",
5044
+ canonicalCode: "01-00-01-00",
5045
+ enumConstant: "INDIVIDUAL_PERSON_SELFREFERRED"
5046
+ },
5047
+ {
5048
+ code: "048-002-000-000-000-000-000",
5049
+ key: "family_guardian_friend",
5050
+ title: "Family/guardian/friend/foster parent",
5051
+ selectable: true,
5052
+ parentCode: null,
5053
+ childCodes: [],
5054
+ definition: "A caregiver, family member, or close personal support person initiated the referral.",
5055
+ canonicalCode: "01-00-02-00",
5056
+ enumConstant: "INDIVIDUAL_PERSON_FAMILYGUARDIANFRIEND"
5057
+ },
5058
+ {
5059
+ code: "048-003-000-000-000-000-000",
5060
+ key: "peer",
5061
+ title: "Peer / another client",
5062
+ selectable: true,
5063
+ parentCode: null,
5064
+ childCodes: [],
5065
+ definition: "Another current or former client initiated or encouraged the referral.",
5066
+ canonicalCode: "01-00-03-00",
5067
+ enumConstant: "INDIVIDUAL_PERSON_PEER"
5068
+ },
5069
+ {
5070
+ code: "048-004-000-000-000-000-000",
5071
+ key: "other_individual",
5072
+ title: "Other individual",
5073
+ selectable: true,
5074
+ parentCode: null,
5075
+ childCodes: [],
5076
+ definition: "A non-family individual initiated the referral (e.g., neighbor, community member, clergy).",
5077
+ canonicalCode: "01-00-04-00",
5078
+ enumConstant: "INDIVIDUAL_PERSON_OTHER"
5079
+ },
5080
+ {
5081
+ code: "048-005-000-000-000-000-000",
5082
+ key: "housing_shelter_continuum",
5083
+ title: "Housing / Shelter continuum",
5084
+ selectable: false,
5085
+ parentCode: null,
5086
+ childCodes: [
5087
+ "048-005-001-000-000-000-000",
5088
+ "048-005-002-000-000-000-000",
5089
+ "048-005-003-000-000-000-000"
5090
+ ],
5091
+ definition: "Primary function is outreach engagement, emergency shelter, or residential shelter/housing programs.",
5092
+ canonicalCode: "02-01-00-00",
5093
+ enumConstant: "ORGANIZATION_HOUSING"
5094
+ },
5095
+ {
5096
+ code: "048-005-001-000-000-000-000",
5097
+ key: "outreach_project",
5098
+ title: "Outreach Project",
5099
+ selectable: true,
5100
+ parentCode: "048-005-000-000-000-000-000",
5101
+ childCodes: [],
5102
+ definition: "Street/community outreach program that engaged the client prior to enrollment.",
5103
+ canonicalCode: "02-01-01-00",
5104
+ enumConstant: "ORGANIZATION_HOUSING_OUTREACHPROJECT"
5105
+ },
5106
+ {
5107
+ code: "048-005-002-000-000-000-000",
5108
+ key: "temporary_shelter",
5109
+ title: "Temporary Shelter",
5110
+ selectable: true,
5111
+ parentCode: "048-005-000-000-000-000-000",
5112
+ childCodes: [],
5113
+ definition: "Emergency/crisis shelter or short-term temporary housing program.",
5114
+ canonicalCode: "02-01-02-00",
5115
+ enumConstant: "ORGANIZATION_HOUSING_TEMPORARYSHELTER"
5116
+ },
5117
+ {
5118
+ code: "048-005-003-000-000-000-000",
5119
+ key: "residential_project",
5120
+ title: "Residential Project",
5121
+ selectable: true,
5122
+ parentCode: "048-005-000-000-000-000-000",
5123
+ childCodes: [],
5124
+ definition: "Longer-term residential or transitional living program.",
5125
+ canonicalCode: "02-01-03-00",
5126
+ enumConstant: "ORGANIZATION_HOUSING_RESIDENTIALPROJECT"
5127
+ },
5128
+ {
5129
+ code: "048-006-000-000-000-000-000",
5130
+ key: "hotlines",
5131
+ title: "Hotlines",
5132
+ selectable: false,
5133
+ parentCode: null,
5134
+ childCodes: [
5135
+ "048-006-003-000-000-000-000"
5136
+ ],
5137
+ definition: "Crisis lines or call centers that connect a person to services.",
5138
+ canonicalCode: "02-02-00-00",
5139
+ enumConstant: "ORGANIZATION_CALLCENTERS"
5140
+ },
5141
+ {
5142
+ code: "048-006-001-000-000-000-000",
5143
+ key: "national_hotline",
5144
+ title: "National hotline",
5145
+ selectable: true,
5146
+ parentCode: "048-006-003-000-000-000-000",
5147
+ childCodes: [],
5148
+ definition: "National-level hotline network.",
5149
+ canonicalCode: "02-02-01-01",
5150
+ enumConstant: "ORGANIZATION_CALLCENTERS_HOTLINE_NATIONAL"
5151
+ },
5152
+ {
5153
+ code: "048-006-002-000-000-000-000",
5154
+ key: "local_other_hotline",
5155
+ title: "Local/other hotline",
5156
+ selectable: true,
5157
+ parentCode: "048-006-003-000-000-000-000",
5158
+ childCodes: [],
5159
+ definition: "Local/regional hotline or non-national hotline.",
5160
+ canonicalCode: "02-02-01-02",
5161
+ enumConstant: "ORGANIZATION_CALLCENTERS_HOTLINE_LOCAL"
5162
+ },
5163
+ {
5164
+ code: "048-006-003-000-000-000-000",
5165
+ key: "hotline",
5166
+ title: "Hotline",
5167
+ selectable: true,
5168
+ parentCode: "048-006-000-000-000-000-000",
5169
+ childCodes: [
5170
+ "048-006-001-000-000-000-000",
5171
+ "048-006-002-000-000-000-000"
5172
+ ],
5173
+ definition: "Crisis hotline or call center that connected the client to services.",
5174
+ canonicalCode: "02-02-01-00",
5175
+ enumConstant: "ORGANIZATION_CALLCENTERS_HOTLINE"
5176
+ },
5177
+ {
5178
+ code: "048-007-000-000-000-000-000",
5179
+ key: "justice_protective_systems",
5180
+ title: "Justice & Protective Systems",
5181
+ selectable: false,
5182
+ parentCode: null,
5183
+ childCodes: [
5184
+ "048-007-001-000-000-000-000",
5185
+ "048-007-002-000-000-000-000",
5186
+ "048-007-003-000-000-000-000",
5187
+ "048-007-004-000-000-000-000",
5188
+ "048-007-005-000-000-000-000",
5189
+ "048-007-006-000-000-000-000"
5190
+ ],
5191
+ definition: null,
5192
+ canonicalCode: "02-03-00-00",
5193
+ enumConstant: "ORGANIZATION_JUSTICE"
5194
+ },
5195
+ {
5196
+ code: "048-007-001-000-000-000-000",
5197
+ key: "child_welfare_cps",
5198
+ title: "Child Welfare / CPS",
5199
+ selectable: true,
5200
+ parentCode: "048-007-000-000-000-000-000",
5201
+ childCodes: [],
5202
+ definition: "Government child protection agency responsible for investigating child abuse/neglect and ensuring child safety.",
5203
+ canonicalCode: "02-03-01-00",
5204
+ enumConstant: "ORGANIZATION_JUSTICE_CHILDWELFARE"
5205
+ },
5206
+ {
5207
+ code: "048-007-002-000-000-000-000",
5208
+ key: "juvenile_justice",
5209
+ title: "Juvenile Justice",
5210
+ selectable: true,
5211
+ parentCode: "048-007-000-000-000-000-000",
5212
+ childCodes: [],
5213
+ definition: "Juvenile probation/detention/court-related juvenile justice system initiated the referral.",
5214
+ canonicalCode: "02-03-02-00",
5215
+ enumConstant: "ORGANIZATION_JUSTICE_JUVENILE"
5216
+ },
5217
+ {
5218
+ code: "048-007-003-000-000-000-000",
5219
+ key: "law_enforcement",
5220
+ title: "Law enforcement / Police",
5221
+ selectable: true,
5222
+ parentCode: "048-007-000-000-000-000-000",
5223
+ childCodes: [
5224
+ "048-007-003-001-000-000-000",
5225
+ "048-007-003-002-000-000-000",
5226
+ "048-007-003-003-000-000-000",
5227
+ "048-007-003-004-000-000-000",
5228
+ "048-007-003-005-000-000-000"
5229
+ ],
5230
+ definition: "Law enforcement agency initiated the referral (local/state/federal).",
5231
+ canonicalCode: "02-03-03-00",
5232
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT"
5233
+ },
5234
+ {
5235
+ code: "048-007-003-001-000-000-000",
5236
+ key: "local_law_enforcement",
5237
+ title: "Local law enforcement",
5238
+ selectable: true,
5239
+ parentCode: "048-007-003-000-000-000-000",
5240
+ childCodes: [],
5241
+ definition: "City/county police or sheriff.",
5242
+ canonicalCode: "02-03-03-01",
5243
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT_LOCAL"
5244
+ },
5245
+ {
5246
+ code: "048-007-003-002-000-000-000",
5247
+ key: "state_law_enforcement",
5248
+ title: "State law enforcement",
5249
+ selectable: true,
5250
+ parentCode: "048-007-003-000-000-000-000",
5251
+ childCodes: [],
5252
+ definition: "State-level law enforcement agency (e.g., state police/highway patrol/state bureau of investigation) acting in an official capacity.",
5253
+ canonicalCode: "02-03-03-02",
5254
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT_STATE"
5255
+ },
5256
+ {
5257
+ code: "048-007-003-003-000-000-000",
5258
+ key: "federal_law_enforcement",
5259
+ title: "Federal law enforcement",
5260
+ selectable: true,
5261
+ parentCode: "048-007-003-000-000-000-000",
5262
+ childCodes: [],
5263
+ definition: "Federal law enforcement agency (e.g., FBI, DHS/ICE).",
5264
+ canonicalCode: "02-03-03-03",
5265
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT_FEDERAL"
5266
+ },
5267
+ {
5268
+ code: "048-007-003-004-000-000-000",
5269
+ key: "tribal_law_enforcement",
5270
+ title: "Tribal law enforcement",
5271
+ selectable: true,
5272
+ parentCode: "048-007-003-000-000-000-000",
5273
+ childCodes: [],
5274
+ definition: "Tribal police.",
5275
+ canonicalCode: "02-03-03-04",
5276
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT_TRIBAL"
5277
+ },
5278
+ {
5279
+ code: "048-007-003-005-000-000-000",
5280
+ key: "other_law_enforcement",
5281
+ title: "Other/ unknown LE",
5282
+ selectable: true,
5283
+ parentCode: "048-007-003-000-000-000-000",
5284
+ childCodes: [],
5285
+ definition: "Other law enforcement entity, or law enforcement type is unknown.",
5286
+ canonicalCode: "02-03-03-05",
5287
+ enumConstant: "ORGANIZATION_JUSTICE_LAWENFORCEMENT_OTHER"
5288
+ },
5289
+ {
5290
+ code: "048-007-004-000-000-000-000",
5291
+ key: "courts_prosecution",
5292
+ title: "Courts or prosecution",
5293
+ selectable: true,
5294
+ parentCode: "048-007-000-000-000-000-000",
5295
+ childCodes: [],
5296
+ definition: "Court or prosecution entity (not law enforcement).",
5297
+ canonicalCode: "02-03-04-00",
5298
+ enumConstant: "ORGANIZATION_JUSTICE_COURTS"
5299
+ },
5300
+ {
5301
+ code: "048-007-005-000-000-000-000",
5302
+ key: "correction_probation",
5303
+ title: "Correction / probation",
5304
+ selectable: true,
5305
+ parentCode: "048-007-000-000-000-000-000",
5306
+ childCodes: [],
5307
+ definition: "Corrections, probation, parole, or community supervision entity (not law enforcement).",
5308
+ canonicalCode: "02-03-05-00",
5309
+ enumConstant: "ORGANIZATION_JUSTICE_CORRECTIONS"
5310
+ },
5311
+ {
5312
+ code: "048-007-006-000-000-000-000",
5313
+ key: "adult_protective_services",
5314
+ title: "Adult Protective Services (APS)",
5315
+ selectable: true,
5316
+ parentCode: "048-007-000-000-000-000-000",
5317
+ childCodes: [],
5318
+ definition: "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.",
5319
+ canonicalCode: "02-03-06-00",
5320
+ enumConstant: "ORGANIZATION_JUSTICE_ADULTPROTECTIVE"
5321
+ },
5322
+ {
5323
+ code: "048-008-000-000-000-000-000",
5324
+ key: "health_behavioral_health",
5325
+ title: "Health / behavioral health",
5326
+ selectable: false,
5327
+ parentCode: null,
5328
+ childCodes: [
5329
+ "048-008-001-000-000-000-000",
5330
+ "048-008-002-000-000-000-000"
5331
+ ],
5332
+ definition: "Hospitals and healthcare providers (including mental health inpatient facilities).",
5333
+ canonicalCode: "02-04-00-00",
5334
+ enumConstant: "ORGANIZATION_HEALTH"
5335
+ },
5336
+ {
5337
+ code: "048-008-001-000-000-000-000",
5338
+ key: "inpatient_psychiatric_facility",
5339
+ title: "Inpatient psychiatric facility",
5340
+ selectable: true,
5341
+ parentCode: "048-008-000-000-000-000-000",
5342
+ childCodes: [],
5343
+ definition: "Inpatient psychiatric hospital or psychiatric facility.",
5344
+ canonicalCode: "02-04-01-00",
5345
+ enumConstant: "ORGANIZATION_HEALTH_PSYCHIATRIC"
5346
+ },
5347
+ {
5348
+ code: "048-008-002-000-000-000-000",
5349
+ key: "healthcare_provider",
5350
+ title: "Healthcare provider (non-inpatient psychiatric)",
5351
+ selectable: true,
5352
+ parentCode: "048-008-000-000-000-000-000",
5353
+ childCodes: [],
5354
+ definition: "Any non-inpatient healthcare provider (clinic, hospital, outpatient provider, behavioral health clinic, SANE program, substance abuse clinic, etc.).",
5355
+ canonicalCode: "02-04-02-00",
5356
+ enumConstant: "ORGANIZATION_HEALTH_HEALTHCARE"
5357
+ },
5358
+ {
5359
+ code: "048-009-000-000-000-000-000",
5360
+ key: "education",
5361
+ title: "Education",
5362
+ selectable: false,
5363
+ parentCode: null,
5364
+ childCodes: [
5365
+ "048-009-001-000-000-000-000"
5366
+ ],
5367
+ definition: "Parent category for education-related institutions.",
5368
+ canonicalCode: "02-05-00-00",
5369
+ enumConstant: "ORGANIZATION_EDUCATION"
5370
+ },
5371
+ {
5372
+ code: "048-009-001-000-000-000-000",
5373
+ key: "school_academic_institution",
5374
+ title: "School / academic institution",
5375
+ selectable: true,
5376
+ parentCode: "048-009-000-000-000-000-000",
5377
+ childCodes: [],
5378
+ definition: "School system or educational institution.",
5379
+ canonicalCode: "02-05-01-00",
5380
+ enumConstant: "ORGANIZATION_EDUCATION_SCHOOL"
5381
+ },
5382
+ {
5383
+ code: "048-010-000-000-000-000-000",
5384
+ key: "victim_community_service_providers",
5385
+ title: "Victim + Community service providers",
5386
+ selectable: false,
5387
+ parentCode: null,
5388
+ childCodes: [
5389
+ "048-010-001-000-000-000-000",
5390
+ "048-010-002-000-000-000-000",
5391
+ "048-010-003-000-000-000-000",
5392
+ "048-010-004-000-000-000-000"
5393
+ ],
5394
+ definition: "Parent category for victim service providers and community-based service providers.",
5395
+ canonicalCode: "02-06-00-00",
5396
+ enumConstant: "ORGANIZATION_COMMUNITY"
5397
+ },
5398
+ {
5399
+ code: "048-010-001-000-000-000-000",
5400
+ key: "child_advocacy_center",
5401
+ title: "Child Advocacy Center (CAC)",
5402
+ selectable: true,
5403
+ parentCode: "048-010-000-000-000-000-000",
5404
+ childCodes: [],
5405
+ definition: "A child-centered multidisciplinary center coordinating investigation and services (forensic interview, coordination, referrals, sometimes medical or therapy) for child victims.",
5406
+ canonicalCode: "02-06-01-00",
5407
+ enumConstant: "ORGANIZATION_COMMUNITY_CHILDADVOCACYCENTER"
5408
+ },
5409
+ {
5410
+ code: "048-010-002-000-000-000-000",
5411
+ key: "victim_service_provider",
5412
+ title: "Victim service provider / advocacy program",
5413
+ selectable: true,
5414
+ parentCode: "048-010-000-000-000-000-000",
5415
+ childCodes: [],
5416
+ definition: "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 \u2014 the fact HMIS 2.01 needs (Comparable Database) \u2014 is a separate per-organization attribute, self-attested by the organization at onboarding (Platform survey / Agency Hub \u201CMy agency info\u201D), not part of this category.",
5417
+ canonicalCode: "02-06-02-00",
5418
+ enumConstant: "ORGANIZATION_COMMUNITY_VICTIMSERVICEPROVIDER"
5419
+ },
5420
+ {
5421
+ code: "048-010-003-000-000-000-000",
5422
+ key: "community_based_service_provider",
5423
+ title: "Community-based service provider (general social services)",
5424
+ selectable: true,
5425
+ parentCode: "048-010-000-000-000-000-000",
5426
+ childCodes: [],
5427
+ definition: "The residual community-based provider (\u201Cother community-based service provider\u201D): 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.)",
5428
+ canonicalCode: "02-06-03-00",
5429
+ enumConstant: "ORGANIZATION_COMMUNITY_COMMUNITYSERVICEPROVIDER"
5430
+ },
5431
+ {
5432
+ code: "048-010-004-000-000-000-000",
5433
+ key: "legal_services_provider",
5434
+ title: "Legal services provider",
5435
+ selectable: true,
5436
+ parentCode: "048-010-000-000-000-000-000",
5437
+ childCodes: [],
5438
+ definition: "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.",
5439
+ canonicalCode: "02-06-04-00",
5440
+ enumConstant: "ORGANIZATION_COMMUNITY_LEGALSERVICES"
5441
+ },
5442
+ {
5443
+ code: "048-011-000-000-000-000-000",
5444
+ key: "coordination_governance",
5445
+ title: "Coordination & Governance",
5446
+ selectable: false,
5447
+ parentCode: null,
5448
+ childCodes: [
5449
+ "048-011-001-000-000-000-000",
5450
+ "048-011-002-000-000-000-000"
5451
+ ],
5452
+ definition: "Parent category for coordination and governance bodies (e.g., MDTs, coalitions).",
5453
+ canonicalCode: "02-07-00-00",
5454
+ enumConstant: "ORGANIZATION_GOVERNANCE"
5455
+ },
5456
+ {
5457
+ code: "048-011-001-000-000-000-000",
5458
+ key: "mdt",
5459
+ title: "Multidisciplinary team (MDT)",
5460
+ selectable: true,
5461
+ parentCode: "048-011-000-000-000-000-000",
5462
+ childCodes: [],
5463
+ definition: "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.)",
5464
+ canonicalCode: "02-07-01-00",
5465
+ enumConstant: "ORGANIZATION_GOVERNANCE_MDT"
5466
+ },
5467
+ {
5468
+ code: "048-011-002-000-000-000-000",
5469
+ key: "coalition",
5470
+ title: "Coalition (state/regional coalition)",
5471
+ selectable: true,
5472
+ parentCode: "048-011-000-000-000-000-000",
5473
+ childCodes: [],
5474
+ definition: "A state or regional membership body of organizations coordinating at the system level \u2014 training, standards, policy, funding \u2014 not individual cases; referrals from a coalition are typically warm handoffs to a member organization.",
5475
+ canonicalCode: "02-07-02-00",
5476
+ enumConstant: "ORGANIZATION_GOVERNANCE_COALITION"
5477
+ },
5478
+ {
5479
+ code: "048-012-000-000-000-000-000",
5480
+ key: "internal",
5481
+ title: "Internal",
5482
+ selectable: false,
5483
+ parentCode: null,
5484
+ childCodes: [
5485
+ "048-012-001-000-000-000-000"
5486
+ ],
5487
+ definition: "Parent category for internal referrals within the same umbrella agency.",
5488
+ canonicalCode: "02-08-00-00",
5489
+ enumConstant: "ORGANIZATION_INTERNAL"
5490
+ },
5491
+ {
5492
+ code: "048-012-001-000-000-000-000",
5493
+ key: "own_agency_internal",
5494
+ title: "Own agency / internal referral",
5495
+ selectable: true,
5496
+ parentCode: "048-012-000-000-000-000-000",
5497
+ childCodes: [],
5498
+ definition: "Client was referred from another program or unit within the same umbrella agency.",
5499
+ canonicalCode: "02-08-01-00",
5500
+ enumConstant: "ORGANIZATION_INTERNAL_OWNAGENCY"
5501
+ },
5502
+ {
5503
+ code: "048-013-000-000-000-000-000",
5504
+ key: "other_entity",
5505
+ title: "Other",
5506
+ selectable: false,
5507
+ parentCode: null,
5508
+ childCodes: [
5509
+ "048-013-001-000-000-000-000",
5510
+ "048-013-002-000-000-000-000",
5511
+ "048-013-003-000-000-000-000"
5512
+ ],
5513
+ definition: "Parent category for other organizations not captured by the primary sectors.",
5514
+ canonicalCode: "02-09-00-00",
5515
+ enumConstant: "ORGANIZATION_OTHER"
5516
+ },
5517
+ {
5518
+ code: "048-013-001-000-000-000-000",
5519
+ key: "employer",
5520
+ title: "Employer",
5521
+ selectable: true,
5522
+ parentCode: "048-013-000-000-000-000-000",
5523
+ childCodes: [],
5524
+ definition: "Employer, HR, or employee assistance program initiated the referral.",
5525
+ canonicalCode: "02-09-01-00",
5526
+ enumConstant: "ORGANIZATION_OTHER_EMPLOYER"
5527
+ },
5528
+ {
5529
+ code: "048-013-002-000-000-000-000",
5530
+ key: "benefits_public_assistance_office",
5531
+ title: "Benefits/public assistance office",
5532
+ selectable: true,
5533
+ parentCode: "048-013-000-000-000-000-000",
5534
+ childCodes: [],
5535
+ definition: "Government office administering public benefits or eligibility and enrollment (e.g., SNAP, TANF, Medicaid, SSA).",
5536
+ canonicalCode: "02-09-02-00",
5537
+ enumConstant: "ORGANIZATION_OTHER_PUBLICASSISTANCE"
5538
+ },
5539
+ {
5540
+ code: "048-013-003-000-000-000-000",
5541
+ key: "other_organization",
5542
+ title: "Other Organization",
5543
+ selectable: true,
5544
+ parentCode: "048-013-000-000-000-000-000",
5545
+ childCodes: [],
5546
+ definition: "Other organization not otherwise captured by the listed categories.",
5547
+ canonicalCode: "02-09-03-00",
5548
+ enumConstant: "ORGANIZATION_OTHER_UNSPECIFIED"
5549
+ }
5550
+ ]
5551
+ };
5552
+
5553
+ // src/constants/org-type.ts
5554
+ var ENTRIES = referralEntityCategory_v1_2_0_default.entries;
5555
+ var BY_KEY = new Map(ENTRIES.map((e) => [e.key, e]));
5556
+ var BY_CODE = new Map(ENTRIES.map((e) => [e.code, e]));
5557
+ var BY_CANON = new Map(
5558
+ ENTRIES.filter((e) => e.canonicalCode).map((e) => [
5559
+ e.canonicalCode,
5560
+ e
5561
+ ])
5562
+ );
5563
+ var BY_ENUM_CONSTANT = new Map(
5564
+ ENTRIES.filter((e) => e.enumConstant).map((e) => [
5565
+ e.enumConstant,
5566
+ e
5567
+ ])
5568
+ );
5569
+ var isOrgHalf = (e) => (e.canonicalCode ?? "").startsWith("02-");
5570
+ var ORG_TYPE_HEADING_KEYS = Object.freeze([
5571
+ "housing_shelter_continuum",
5572
+ "hotlines",
5573
+ "justice_protective_systems",
5574
+ "health_behavioral_health",
5575
+ "education",
5576
+ "victim_community_service_providers",
5577
+ "coordination_governance",
5578
+ "internal",
5579
+ "other_entity"
5580
+ ]);
5581
+ var ORG_TYPE_SELECTABLE_KEYS = Object.freeze([
5582
+ "outreach_project",
5583
+ "temporary_shelter",
5584
+ "residential_project",
5585
+ "national_hotline",
5586
+ "local_other_hotline",
5587
+ "hotline",
5588
+ "child_welfare_cps",
5589
+ "juvenile_justice",
5590
+ "law_enforcement",
5591
+ "local_law_enforcement",
5592
+ "state_law_enforcement",
5593
+ "federal_law_enforcement",
5594
+ "tribal_law_enforcement",
5595
+ "other_law_enforcement",
5596
+ "courts_prosecution",
5597
+ "correction_probation",
5598
+ "adult_protective_services",
5599
+ "inpatient_psychiatric_facility",
5600
+ "healthcare_provider",
5601
+ "school_academic_institution",
5602
+ "child_advocacy_center",
5603
+ "victim_service_provider",
5604
+ "community_based_service_provider",
5605
+ "legal_services_provider",
5606
+ "mdt",
5607
+ "coalition",
5608
+ "employer",
5609
+ "benefits_public_assistance_office",
5610
+ "other_organization"
5611
+ ]);
5612
+ var ORG_TYPE_NONPICKABLE_LEAF_KEYS = Object.freeze([
5613
+ "own_agency_internal"
5614
+ ]);
5615
+ var ORG_TYPE_KEYS = Object.freeze([
5616
+ ...ORG_TYPE_HEADING_KEYS,
5617
+ ...ORG_TYPE_SELECTABLE_KEYS,
5618
+ ...ORG_TYPE_NONPICKABLE_LEAF_KEYS
5619
+ ]);
5620
+ var AGENCY_TYPE_KEYS = Object.freeze([
5621
+ ...ORG_TYPE_SELECTABLE_KEYS,
5622
+ ...ORG_TYPE_NONPICKABLE_LEAF_KEYS,
5623
+ "unknown"
5624
+ ]);
5625
+ var ORG_TYPE_KEY_SET = new Set(ORG_TYPE_KEYS);
5626
+ var AGENCY_TYPE_KEY_SET = new Set(AGENCY_TYPE_KEYS);
5627
+ function isAgencyTypeKey(value) {
5628
+ return typeof value === "string" && AGENCY_TYPE_KEY_SET.has(value);
5629
+ }
5630
+ function lookup(value) {
5631
+ if (typeof value !== "string") return null;
5632
+ const v = value.trim();
5633
+ if (!v) return null;
5634
+ return BY_KEY.get(v.toLowerCase()) ?? BY_ENUM_CONSTANT.get(v.toUpperCase()) ?? BY_CANON.get(v) ?? BY_CODE.get(v) ?? null;
5635
+ }
5636
+ function resolveAgencyTypeKey(value) {
5637
+ const hit = lookup(value);
5638
+ return hit && isAgencyTypeKey(hit.key) ? hit.key : null;
5639
+ }
5640
+ var LEGACY_NUMERIC_TO_REFERRAL_ENTITY_KEY = Object.freeze({
5641
+ 0: "unknown",
5642
+ 1: "own_agency_internal",
5643
+ 2: "self_referred",
5644
+ 3: "family_guardian_friend",
5645
+ 4: "peer",
5646
+ 5: "other_individual",
5647
+ 10: "housing_shelter_continuum",
5648
+ 11: "hotline",
5649
+ 12: "justice_protective_systems",
5650
+ 13: "outreach_project",
5651
+ 14: "temporary_shelter",
5652
+ 15: "residential_project",
5653
+ 16: "health_behavioral_health",
5654
+ 17: "education",
5655
+ 18: "law_enforcement",
5656
+ 19: "other_entity",
5657
+ 20: "child_welfare_cps",
5658
+ 21: "juvenile_justice",
5659
+ 22: "courts_prosecution",
5660
+ 23: "correction_probation",
5661
+ 24: "inpatient_psychiatric_facility",
5662
+ 25: "healthcare_provider",
5663
+ 26: "victim_community_service_providers",
5664
+ 27: "child_advocacy_center",
5665
+ 28: "victim_service_provider",
5666
+ 29: "community_based_service_provider",
5667
+ 30: "employer",
5668
+ 31: "benefits_public_assistance_office"
5669
+ });
5670
+ var ORG_TYPE_PARENT_KEY = Object.freeze(
5671
+ Object.fromEntries(
5672
+ ENTRIES.filter(isOrgHalf).map((e) => [
5673
+ e.key,
5674
+ e.parentCode ? BY_CODE.get(e.parentCode)?.key ?? null : null
5675
+ ])
5676
+ )
5677
+ );
5678
+ var VICTIM_SERVING_ORG_TYPE_KEYS = Object.freeze([
5679
+ "victim_service_provider",
5680
+ "child_advocacy_center"
5681
+ ]);
5682
+ var LAW_ENFORCEMENT_ORG_TYPE_KEYS = Object.freeze([
5683
+ "law_enforcement",
5684
+ "local_law_enforcement",
5685
+ "state_law_enforcement",
5686
+ "federal_law_enforcement",
5687
+ "tribal_law_enforcement",
5688
+ "other_law_enforcement"
5689
+ ]);
5690
+ var LEGAL_ORG_TYPE_KEYS = Object.freeze([
5691
+ "courts_prosecution",
5692
+ "legal_services_provider"
5693
+ ]);
5694
+ var HEALTHCARE_ORG_TYPE_KEYS = Object.freeze([
5695
+ "health_behavioral_health",
5696
+ "inpatient_psychiatric_facility",
5697
+ "healthcare_provider"
5698
+ ]);
5699
+ var REPORT_AUTHORITY_ORG_TYPE_KEYS = Object.freeze([
5700
+ "justice_protective_systems",
5701
+ "child_welfare_cps",
5702
+ "juvenile_justice",
5703
+ "law_enforcement",
5704
+ "local_law_enforcement",
5705
+ "state_law_enforcement",
5706
+ "federal_law_enforcement",
5707
+ "tribal_law_enforcement",
5708
+ "other_law_enforcement",
5709
+ "courts_prosecution",
5710
+ "correction_probation",
5711
+ "adult_protective_services"
5712
+ ]);
5713
+ var NO_SECTOR_ORG_TYPE_KEYS = Object.freeze([
5714
+ "internal",
5715
+ "own_agency_internal",
5716
+ "unknown"
5717
+ ]);
5718
+ var asSet = (keys) => new Set(keys);
5719
+ var VICTIM_SERVING = asSet(VICTIM_SERVING_ORG_TYPE_KEYS);
5720
+ var LAW_ENFORCEMENT = asSet(LAW_ENFORCEMENT_ORG_TYPE_KEYS);
5721
+ var LEGAL = asSet(LEGAL_ORG_TYPE_KEYS);
5722
+ var HEALTHCARE = asSet(HEALTHCARE_ORG_TYPE_KEYS);
5723
+ var REPORT_AUTHORITY = asSet(REPORT_AUTHORITY_ORG_TYPE_KEYS);
5724
+ var NO_SECTOR = asSet(NO_SECTOR_ORG_TYPE_KEYS);
5725
+
5726
+ // src/schemas/agency.ts
5727
+ function vspTwoStepHolds(v) {
5728
+ return v.vspPrivateNonprofit == null || v.vsp === true;
5729
+ }
5730
+ var VSP_TWO_STEP_ISSUE = {
5731
+ message: "vspPrivateNonprofit is step 2 of the HMIS VSP two-step and requires vsp: true",
5732
+ path: ["vspPrivateNonprofit"]
5733
+ };
5734
+ function vspTwoStepHoldsOnUpdate(update) {
5735
+ if (!update || typeof update !== "object") return true;
5736
+ const u = update;
5737
+ const set = { ...u, ...u.$set ?? {} };
5738
+ return vspTwoStepHolds({
5739
+ vsp: set.vsp,
5740
+ vspPrivateNonprofit: set.vspPrivateNonprofit
5741
+ });
5742
+ }
5743
+ var orgTypeSchemaDefinition = {
5744
+ /**
5745
+ * The agency's organization type: a CVC-48 key from
5746
+ * {@link AGENCY_TYPE_KEYS} (a selectable org-type leaf, or the pre-backfill
5747
+ * `unknown`). Set once in the Admin Hub; carried from the Org. Never free
5748
+ * text — a value outside the enum fails validation on `save()` and, when
5749
+ * the fragment is added with {@link addAgencyOrgTypeFields} (default
5750
+ * options), on `updateOne` / `updateMany` / `findOneAndUpdate` too.
5751
+ *
5752
+ * ORDER OF ADOPTION (review MG2, pinned in org-type-contract.test.ts):
5753
+ * Mongoose validates `init`-ed paths on `save()`, not only modified ones,
5754
+ * so once a consumer adds this fragment, an agency document that carries a
5755
+ * NON-KEY `type` (free text, "UNKNOWN", "multi_service", a number) fails
5756
+ * its next save of ANY field. A document with no `type` at all saves fine.
5757
+ * Backfill first (every stored value → a key or `unknown`), then adopt.
5758
+ */
5759
+ type: {
5760
+ type: String,
5761
+ enum: [...AGENCY_TYPE_KEYS],
5762
+ index: true
5763
+ },
5764
+ /**
5765
+ * Is this organization a DV/SA victim service provider — the HMIS 2.01
5766
+ * (Comparable Database) fact. Captured in the Admin Hub (never inferred
5767
+ * from the type; the type only PROPOSES it — `orgTypeDefaultVsp`, the
5768
+ * Hub's pre-fill — and HTI Labs affirms or changes it there). Tri-state:
5769
+ * `true` / `false` / absent (not yet captured — a reader falls back to the
5770
+ * proposal).
5771
+ */
5772
+ vsp: {
5773
+ type: Boolean
5774
+ },
5775
+ /**
5776
+ * Step 2 of the two-step: private non-profit VSP (VOCA/OVC PMT
5777
+ * distinction). Captured; tri-state; may only be `true`/`false` when
5778
+ * `vsp === true` ({@link vspTwoStepHolds}, enforced at the mount).
5779
+ */
5780
+ vspPrivateNonprofit: {
5781
+ type: Boolean
5782
+ }
5783
+ };
5784
+ var agencyOrgTypeSchemaDefinition = orgTypeSchemaDefinition;
5785
+ var ORG_TYPE_FIELD_NAMES = Object.freeze([
5786
+ "type",
5787
+ "vsp",
5788
+ "vspPrivateNonprofit"
5789
+ ]);
5790
+ var AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS = Object.freeze([
5791
+ "updateOne",
5792
+ "updateMany",
5793
+ "findOneAndUpdate"
5794
+ ]);
5795
+ function applyRunValidatorsIfUnset(query) {
5796
+ if (query.getOptions().runValidators === void 0) {
5797
+ query.setOptions({ runValidators: true });
5798
+ }
5799
+ }
5800
+ function mountOrgTypeFields(schema, options) {
5801
+ schema.add(orgTypeSchemaDefinition);
5802
+ schema.pre("validate", function() {
5803
+ const doc = this;
5804
+ if (!vspTwoStepHolds(doc)) {
5805
+ const err = new import_mongoose11.Error.ValidationError();
5806
+ err.addError(
5807
+ "vspPrivateNonprofit",
5808
+ new import_mongoose11.Error.ValidatorError({
5809
+ path: "vspPrivateNonprofit",
5810
+ message: VSP_TWO_STEP_ISSUE.message,
5811
+ value: doc.vspPrivateNonprofit
5812
+ })
5813
+ );
5814
+ throw err;
5815
+ }
5816
+ });
5817
+ const validateOnUpdate = options.validateOnUpdate ?? true;
5818
+ schema.pre(
5819
+ [...AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS],
5820
+ function() {
5821
+ if (!vspTwoStepHoldsOnUpdate(this.getUpdate())) {
5822
+ throw new Error(VSP_TWO_STEP_ISSUE.message);
5823
+ }
5824
+ if (validateOnUpdate) applyRunValidatorsIfUnset(this);
5825
+ }
5826
+ );
5827
+ return schema;
5828
+ }
5829
+ function addOrgTypeFields(schema, options = {}) {
5830
+ return mountOrgTypeFields(schema, options);
5831
+ }
5832
+ function addAgencyOrgTypeFields(schema, options = {}) {
5833
+ return mountOrgTypeFields(schema, options);
5834
+ }
5835
+ function pickOrgTypeFields(src) {
5836
+ const out = {};
5837
+ if (src) {
5838
+ for (const k of ORG_TYPE_FIELD_NAMES) {
5839
+ const v = src[k];
5840
+ if (v != null) out[k] = v;
5841
+ }
5842
+ }
5843
+ return out;
5844
+ }
5845
+ function mirrorOrgTypeFields(org) {
5846
+ const out = pickOrgTypeFields(org);
5847
+ if (!vspTwoStepHolds(out)) {
5848
+ throw new Error(`mirrorOrgTypeFields: ${VSP_TWO_STEP_ISSUE.message}`);
5849
+ }
5850
+ return out;
5851
+ }
5852
+ function resolveEffectiveOrgTypeFields(org, agency) {
5853
+ const linked = agency != null && agency.organizationId != null;
5854
+ if (linked && org) return pickOrgTypeFields(org);
5855
+ return pickOrgTypeFields(agency);
5856
+ }
5857
+ function resolveEffectiveOrgType(org, agency) {
5858
+ return resolveAgencyTypeKey(resolveEffectiveOrgTypeFields(org, agency).type);
5859
+ }
5860
+ function orgTypeFieldsDiffer(org, agency) {
5861
+ const a = pickOrgTypeFields(org);
5862
+ const b = pickOrgTypeFields(agency);
5863
+ return ORG_TYPE_FIELD_NAMES.filter((k) => a[k] !== b[k]);
5864
+ }
4904
5865
  // Annotate the CommonJS export names for ESM import in node:
4905
5866
  0 && (module.exports = {
5867
+ AGENCY_ORG_TYPE_VALIDATED_UPDATE_OPS,
5868
+ ORG_TYPE_FIELD_NAMES,
4906
5869
  TEAM_MODEL_NAME,
5870
+ VSP_TWO_STEP_ISSUE,
5871
+ addAgencyOrgTypeFields,
5872
+ addOrgTypeFields,
4907
5873
  addTeamDirectoryFields,
4908
5874
  addressSchema,
5875
+ agencyOrgTypeSchemaDefinition,
5876
+ applyRunValidatorsIfUnset,
4909
5877
  buildCvcEntrySchema,
4910
5878
  buildCvcRegistrySchema,
4911
5879
  buildFormSchema,
@@ -4926,6 +5894,9 @@ var _cvcEntrySchema = buildCvcEntrySchema();
4926
5894
  formSectionRefSchema,
4927
5895
  guidanceSchema,
4928
5896
  layoutSchema,
5897
+ mirrorOrgTypeFields,
5898
+ orgTypeFieldsDiffer,
5899
+ orgTypeSchemaDefinition,
4929
5900
  personNameSchema,
4930
5901
  phoneSchema,
4931
5902
  platformFunctionSchemaDefinition,
@@ -4934,6 +5905,8 @@ var _cvcEntrySchema = buildCvcEntrySchema();
4934
5905
  platformRoleSchemaOptions,
4935
5906
  questionSchemaDefinition,
4936
5907
  questionSchemaOptions,
5908
+ resolveEffectiveOrgType,
5909
+ resolveEffectiveOrgTypeFields,
4937
5910
  scoringConditionSchema,
4938
5911
  scoringRecommendationSchema,
4939
5912
  scoringRuleSchemaDefinition,
@@ -4943,6 +5916,8 @@ var _cvcEntrySchema = buildCvcEntrySchema();
4943
5916
  sectionSchemaDefinition,
4944
5917
  sectionSchemaOptions,
4945
5918
  teamDirectorySchemaDefinition,
4946
- visibilityRuleSchema
5919
+ visibilityRuleSchema,
5920
+ vspTwoStepHolds,
5921
+ vspTwoStepHoldsOnUpdate
4947
5922
  });
4948
5923
  //# sourceMappingURL=index.cjs.map