001package ca.cdr.api.model.enm;
002
003/*-
004 * #%L
005 * Smile CDR - CDR
006 * %%
007 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
008 * %%
009 * All rights reserved.
010 * #L%
011 */
012
013import ca.cdr.api.util.PublicApiConstants;
014import ca.uhn.fhir.context.FhirContext;
015import ca.uhn.fhir.context.FhirVersionEnum;
016import org.hl7.fhir.dstu3.model.Coding;
017
018import java.util.Collections;
019import java.util.HashMap;
020import java.util.Map;
021
022/**
023 * Stores commonly used CodeSystem information. Includes both the DSTU3 and R4 URIs, which can be accessed via
024 * FHIR context.
025 */
026public enum CodeSystemEnum {
027        /*
028         *   List more major, general use code systems up top
029         */
030        SNOMED("2.16.840.1.113883.6.96", "SNOMED CT", "http://snomed.info/sct", "http://snomed.info/sct"),
031        LOINC("2.16.840.1.113883.6.1", "LOINC", "http://loinc.org", "http://loinc.org"),
032        RX_NORM(
033                        "2.16.840.1.113883.6.88",
034                        "RxNorm",
035                        "http://www.nlm.nih.gov/research/umls/rxnorm",
036                        "http://www.nlm.nih.gov/research/umls/rxnorm"),
037        NCI_THESAURUS(
038                        "2.16.840.1.113883.3.26.1.1", "NCI Thesaurus", "http://ncicb.nci.nih.gov", "http://ncicb.nci.nih.gov"),
039        ICD_10_CM(
040                        "2.16.840.1.113883.6.90",
041                        "ICD-10-CM",
042                        "http://hl7.org/fhir/sid/icd-10-cm",
043                        "http://hl7.org/fhir/sid/icd-10-cm"),
044        ICD_10("2.16.840.1.113883.6.3", "ICD-10", "http://hl7.org/fhir/sid/icd-10", "http://hl7.org/fhir/sid/icd-10"),
045        ICD_9("2.16.840.1.113883.6.42", "ICD-9", "http://hl7.org/fhir/sid/icd-9-cm", "http://hl7.org/fhir/sid/icd-9-cm"),
046        ICD_9CM_DIAGNOSIS_CODES(
047                        "2.16.840.1.113883.6.103",
048                        "ICD-9-CM Diagnosis Codes",
049                        "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes",
050                        "http://terminology.hl7.org/CodeSystem/ICD-9CM-diagnosiscodes"),
051        NDC("2.16.840.1.113883.6.69", "NDC/NHRIC", "http://hl7.org/fhir/sid/ndc", "http://hl7.org/fhir/sid/ndc"),
052        CVX("2.16.840.1.113883.12.292", "CDC Vaccine Code", "http://hl7.org/fhir/sid/cvx", "http://hl7.org/fhir/sid/cvx"),
053        PCS(
054                        "2.16.840.1.113883.6.4",
055                        "ICD-10 PCS Codes",
056                        "http://www.icd10data.com/icd10pcs",
057                        "http://www.icd10data.com/icd10pcs"),
058        CDT_2("2.16.840.1.113883.6.13", "Current Dental Terminology", "http://ada.org/cdt", "http://ada.org/cdt"),
059        UCUM(
060                        "2.16.840.1.113883.6.8",
061                        "UCUM - Unified Code for Units of Measure",
062                        "http://unitsofmeasure.org",
063                        "http://unitsofmeasure.org"),
064
065        /*
066         *   Smaller more specific code systems
067         */
068        HL7_ACT_CLASS(
069                        "2.16.840.1.113883.5.6",
070                        "v3 Code System ActClass",
071                        "http://hl7.org/fhir/v3/ActClass",
072                        "http://terminology.hl7.org/CodeSystem/v3-ActClass"),
073        HL7_ACT_CODE(
074                        "2.16.840.1.113883.5.4",
075                        "v3 Code System ActCode",
076                        "http://hl7.org/fhir/v3/ActCode",
077                        "http://terminology.hl7.org/CodeSystem/v3-ActCode"),
078        HL7_ACT_REASON(
079                        "2.16.840.1.113883.5.8",
080                        "v3 Code System ActReason",
081                        "http://hl7.org/fhir/v3/ActReason",
082                        "http://terminology.hl7.org/CodeSystem/v3-ActReason"),
083        CONDITION_CATEGORY_CS(
084                        null,
085                        "ConditionCategoryCS",
086                        "http://standardhealthrecord.org/shr/condition/vs/ConditionCategoryVS",
087                        null // JV 20210826: I did a quick look around the site but couldn't seem to find this ValueSet
088                        ),
089        MARITAL_STATUS(
090                        "2.16.840.1.113883.5.2",
091                        "Code System MaritalStatus",
092                        "http://hl7.org/fhir/v3/MaritalStatus",
093                        "http://terminology.hl7.org/CodeSystem/v3-MaritalStatus"),
094        NULL_FLAVOR(
095                        "2.16.840.1.113883.5.1008",
096                        "Code System NullFlavor",
097                        "http://hl7.org/fhir/v3/NullFlavor",
098                        "http://terminology.hl7.org/CodeSystem/v3-NullFlavor"),
099        DIAGNOSIS_ROLE(
100                        "2.16.840.1.113883.4.642.1.1054",
101                        "Code System DiagnosisRole",
102                        "http://hl7.org/fhir/diagnosis-role",
103                        "http://terminology.hl7.org/CodeSystem/diagnosis-role"),
104        MEDICATION_ADMIN_STATUS(
105                        "2.16.840.1.113883.4.642.4.1311",
106                        "Code System MedicationAdmin Status",
107                        "http://hl7.org/fhir/medication-admin-status",
108                        "http://terminology.hl7.org/CodeSystem/medication-admin-status"),
109        ALLERGY_INTOLERANCE_CATEGORY(
110                        "2.16.840.1.113883.4.642.4.134",
111                        "Code System AllergyIntoleranceCategory",
112                        "http://hl7.org/fhir/allergy-intolerance-category",
113                        "http://hl7.org/fhir/allergy-intolerance-category"),
114        MEDICATION_REQUEST_STATUS_REASON(
115                        "2.16.840.1.113883.4.642.1.1325",
116                        "Code System MedicationRequest Status Reason",
117                        null,
118                        "http://terminology.hl7.org/CodeSystem/medicationrequest-status-reason"),
119        HL7_TBL_0063_RELATIONSHIP(
120                        "2.16.840.1.113883.18.24",
121                        "Code System Relationship",
122                        "http://hl7.org/fhir/v2/0063",
123                        "http://terminology.hl7.org/CodeSystem/v2-0063"),
124        HL7_TBL_0074_DIAGNOSTIC_SERVICE_SECTION(
125                        "2.16.840.1.113883.18.29",
126                        "Code System DiagnosticServiceSectionId",
127                        "http://hl7.org/fhir/v2/0074",
128                        "http://terminology.hl7.org/CodeSystem/v2-0074"),
129        HL7V2_TBL_0078(
130                        null,
131                        "v2 Interpretation Codes",
132                        "http://hl7.org/fhir/v2/0078",
133                        "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"),
134        ADMINISTRATIVE_GENDER(
135                        "2.16.840.1.113883.4.642.4.2",
136                        "AdministrativeGender",
137                        "http://hl7.org/fhir/administrative-gender",
138                        "http://hl7.org/fhir/administrative-gender"),
139        LOCATION_PHYSICAL_TYPE(
140                        "2.16.840.1.113883.4.642.1.1108",
141                        "Location Type",
142                        "http://hl7.org/fhir/location-physical-type",
143                        "http://terminology.hl7.org/CodeSystem/location-physical-type"),
144        HL7_TBL_0203(
145                        "2.16.840.1.113883.18.108",
146                        "Identifier Type",
147                        "http://hl7.org/fhir/v2/0203",
148                        "http://terminology.hl7.org/CodeSystem/v2-0203"),
149        HL7V2_TBL_0001(
150                        "2.16.840.1.113883.18.2",
151                        "v2 Sex",
152                        "http://hl7.org/fhir/v2/0001",
153                        "http://terminology.hl7.org/CodeSystem/v2-0001"),
154        HL7V2_TBL_0002(
155                        "2.16.840.1.113883.18.179",
156                        "v2 Marital Status",
157                        "http://hl7.org/fhir/v2/0002",
158                        "http://terminology.hl7.org/CodeSystem/v2-0002"),
159        HL7V2_TBL_0004(
160                        "2.16.840.1.113883.18.5",
161                        "v2 Patient Class",
162                        PublicApiConstants.TABLE_0004_DSTU3,
163                        PublicApiConstants.TABLE_0004_R4),
164        HL7V2_TBL_0003(
165                        "2.16.840.1.113883.18.4",
166                        "v2 Event Type",
167                        PublicApiConstants.TABLE_0003_DSTU3,
168                        PublicApiConstants.TABLE_0003_R4),
169        HL7V2_TBL_0038(
170                        "2.16.840.1.113883.18.18",
171                        "v2 Order Status",
172                        "http://hl7.org/fhir/v2/0038",
173                        "http://terminology.hl7.org/CodeSystem/v2-0038"),
174        HL7V2_TBL_0119(
175                        "2.16.840.1.113883.18.48",
176                        "v2 Order Control",
177                        "http://hl7.org/fhir/v2/0119",
178                        "http://terminology.hl7.org/CodeSystem/v2-0119"),
179        HL7V2_TBL_0123(
180                        "2.16.840.1.113883.18.51",
181                        "v2 Result status",
182                        "http://hl7.org/fhir/v2/0123",
183                        "http://terminology.hl7.org/CodeSystem/v2-0123"),
184        HL7V2_TBL_0127(
185                        "2.16.840.1.113883.18.54",
186                        "v2 Allergen Type",
187                        "http://hl7.org/fhir/v2/0127",
188                        "http://terminology.hl7.org/CodeSystem/v2-0127"),
189        HL7V2_TBL_0128(
190                        "2.16.840.1.113883.18.55",
191                        "v2 Allergy Severity",
192                        "http://hl7.org/fhir/v2/0128",
193                        "http://terminology.hl7.org/CodeSystem/v2-0128"),
194        HL7V2_TBL_0190(
195                        "2.16.840.1.113883.18.101",
196                        "v2 Address Type",
197                        "http://hl7.org/fhir/v2/0190",
198                        "http://terminology.hl7.org/CodeSystem/v2-0190"),
199        HL7V2_TBL_0191(
200                        "2.16.840.1.113883.18.102",
201                        "Content Data Type",
202                        "http://hl7.org/fhir/v2/0191",
203                        "http://terminology.hl7.org/CodeSystem/v2-0191"),
204        HL7V2_TBL_0834(
205                        "2.16.840.1.113883.18.408",
206                        "MimeTypes",
207                        "http://hl7.org/fhir/v2/0834",
208                        "http://terminology.hl7.org/CodeSystem/v2-0834"),
209        HL7V2_TBL_0202(
210                        "2.16.840.1.113883.18.107",
211                        "v2 Telecommunication Equipment Type",
212                        "http://hl7.org/fhir/v2/0202",
213                        "http://terminology.hl7.org/CodeSystem/v2-0202"),
214        HL7V2_TBL_0278(
215                        "2.16.840.1.113883.18.171",
216                        "v2 Filler status codes",
217                        "http://hl7.org/fhir/v2/0278",
218                        "http://terminology.hl7.org/CodeSystem/v2-0278"),
219        HL7V2_TBL_0276(
220                        "2.16.840.1.113883.18.169",
221                        "v2 Appointment Reason",
222                        "http://hl7.org/fhir/v2/0276",
223                        "http://terminology.hl7.org/CodeSystem/v2-0276"),
224        HL7V2_TBL_0305(
225                        "2.16.840.1.113883.18.187",
226                        "Person Location Type",
227                        "http://hl7.org/fhir/v2/0305",
228                        "http://terminology.hl7.org/CodeSystem/v2-0305"),
229        HL7V2_TBL_0322(
230                        "2.16.840.1.113883.18.195",
231                        "v2 Completion Status",
232                        "http://hl7.org/fhir/v2/0322",
233                        "http://terminology.hl7.org/CodeSystem/v2-0322"),
234        HL7V2_TBL_0438(
235                        "2.16.840.1.113883.18.279",
236                        "Allergy Clinical Status",
237                        "http://hl7.org/fhir/v2/0438",
238                        "http://terminology.hl7.org/CodeSystem/v2-0438"),
239        OBSERVATION_STATUS_CATEGORY(
240                        "2.16.840.1.113883.4.642.1.393",
241                        "Observation Category Codes",
242                        "http://hl7.org/fhir/observation-category",
243                        null // JV 20210826: this seems defunct as of R4--searching for the OID was useless
244                        ),
245        OBSERVATION_VALUE(
246                        "2.16.840.1.113883.5.1063",
247                        "v3 Code System ObservationValue",
248                        "http://hl7.org/fhir/v3/ObservationValue",
249                        "http://terminology.hl7.org/CodeSystem/v3-ObservationValue"),
250        OBSERVATION_CATEGORY(
251                        "2.16.840.1.113883.4.642.4.1125",
252                        "Observation Category Codes",
253                        null,
254                        "http://terminology.hl7.org/CodeSystem/observation-category"),
255        OBSERVATION_INTERPRETATION(
256                        "2.16.840.1.113883.5.83",
257                        "v3 Code System ObservationInterpretation",
258                        "http://hl7.org/fhir/v3/ObservationInterpretation",
259                        "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation"),
260        ROLE_CODE(
261                        "2.16.840.1.113883.5.111",
262                        "Role Code",
263                        "http://hl7.org/fhir/v3/RoleCode",
264                        "http://terminology.hl7.org/CodeSystem/v3-RoleCode"),
265        NUCC_HEALTHCARE_PROVIDER_TAXONOMY(
266                        "2.16.840.1.113883.6.101",
267                        "HealthCare Provider Taxonomy",
268                        "http://nucc.org/provider-taxonomy",
269                        "http://taxonomy.nucc.org"),
270        HSLOC(
271                        "2.16.840.1.113883.6.259",
272                        "NHSN Healthcare Facility Patient Care Location",
273                        "https://www.cdc.gov/nhsn/cdaportal/terminology/codesystem/hsloc.html",
274                        "https://www.cdc.gov/nhsn/cdaportal/terminology/codesystem/hsloc.html"),
275        IMMUNIZATION_RECOMMENDATION_STATUS(
276                        "2.16.840.1.113883.4.642.4.1104",
277                        "Immunization Recommendation Status Codes",
278                        "http://hl7.org/fhir/immunization-recommendation-status",
279                        "http://terminology.hl7.org/CodeSystem/immunization-recommendation-status"),
280        CPT_4(
281                        "2.16.840.1.113883.6.12",
282                        "Current Procedural Terminology",
283                        "http://www.ama-assn.org/go/cpt",
284                        "http://www.ama-assn.org/go/cpt"),
285        NDF_RT(
286                        "2.16.840.1.113883.6.209",
287                        "National Drug File ? Reference Terminology",
288                        "http://hl7.org/fhir/ndfrt",
289                        "http://hl7.org/fhir/ndfrt"),
290        ORGANIZATION_TYPE(
291                        "2.16.840.1.113883.4.642.1.1128",
292                        "Organization Type",
293                        "http://hl7.org/fhir/organization-type",
294                        "http://terminology.hl7.org/CodeSystem/organization-type"),
295        ADMIT_SOURCE(
296                        "2.16.840.1.113883.4.642.1.1092",
297                        "Admit Source",
298                        "http://hl7.org/fhir/admit-source",
299                        "http://terminology.hl7.org/CodeSystem/admit-source"),
300        DISCHARGE_DISPOSITION(
301                        "2.16.840.1.113883.4.642.1.1093",
302                        "Discharge Disposition",
303                        "http://hl7.org/fhir/discharge-disposition",
304                        "http://terminology.hl7.org/CodeSystem/discharge-disposition"),
305        CONDITION_CATEGORY(
306                        "2.16.840.1.113883.4.642.1.1073",
307                        "Condition Category",
308                        "http://hl7.org/fhir/condition-category",
309                        "http://terminology.hl7.org/CodeSystem/condition-category"),
310        ALLERGY_INTOLERANCE_CLINICAL_STATUS(
311                        "2.16.840.1.113883.4.642.1.1373",
312                        "Allergy Intolerance Clinical Status",
313                        "http://hl7.org/fhir/allergy-clinical-status",
314                        "http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical"),
315        ALLERGY_INTOLERANCE_VERIFICATION_STATUS(
316                        "2.16.840.1.113883.4.642.1.1371",
317                        "Allergy Intolerance Verification Status",
318                        "http://hl7.org/fhir/allergy-verification-status",
319                        "http://terminology.hl7.org/CodeSystem/allergyintolerance-verification"),
320        SERVICE_TYPE(
321                        "2.16.840.1.113883.4.642.1.1145",
322                        "Service Type",
323                        "http://hl7.org/fhir/service-type",
324                        "http://terminology.hl7.org/CodeSystem/service-type"),
325        ENCOUNTER_STATUS(
326                        "2.16.840.1.113883.4.642.4.247",
327                        "Encounter Status",
328                        "http://hl7.org/fhir/encounter-status",
329                        "http://hl7.org/fhir/encounter-status"),
330        APPOINTMENT_STATUS(
331                        "2.16.840.1.113883.4.642.4.485",
332                        "Appointment Status",
333                        "http://hl7.org/fhir/appointmentstatus",
334                        "http://hl7.org/fhir/appointmentstatus"),
335        MEDICATION_REQUEST_STATUS(
336                        "2.16.840.1.113883.4.642.4.1377",
337                        "Medication Request Status Codes",
338                        "http://hl7.org/fhir/medication-request-status",
339                        "http://hl7.org/fhir/CodeSystem/medicationrequest-status"),
340        DIAGNOSTIC_REPORT_STATUS(
341                        "2.16.840.1.113883.4.642.4.236",
342                        "Diagnostic Report Status",
343                        "http://hl7.org/fhir/diagnostic-report-status",
344                        "http://hl7.org/fhir/diagnostic-report-status"),
345        REQUEST_STATUS(
346                        "2.16.840.1.113883.4.642.1.112",
347                        "Request Status",
348                        "http://hl7.org/fhir/request-status",
349                        "http://hl7.org/fhir/request-status"),
350        IMMUNIZATION_EVENT_STATUS(
351                        "2.16.840.1.113883.4.642.1.110",
352                        "Event Status",
353                        "http://hl7.org/fhir/event-status",
354                        "http://hl7.org/fhir/event-status"),
355        ADDRESS_TYPE(
356                        "2.16.840.1.113883.4.642.1.70",
357                        "Address Type",
358                        "http://hl7.org/fhir/address-type",
359                        "http://hl7.org/fhir/address-type"),
360        ADDRESS_USE(
361                        "2.16.840.1.113883.4.642.1.68",
362                        "Address Use",
363                        "http://hl7.org/fhir/address-use",
364                        "http://hl7.org/fhir/address-use"),
365        ALLERGY_INTOLERANCE_CRITICALITY(
366                        "2.16.840.1.113883.4.642.4.130",
367                        "Allergy Intolerance Criticality",
368                        "http://hl7.org/fhir/allergy-intolerance-criticality",
369                        "http://hl7.org/fhir/allergy-intolerance-criticality"),
370        CONTACT_POINT_USE(
371                        "2.16.840.1.113883.4.642.1.74",
372                        "Contact Point Use",
373                        "http://hl7.org/fhir/contact-point-use",
374                        "http://hl7.org/fhir/contact-point-use"),
375        CONTACT_POINT_SYSTEM(
376                        "2.16.840.1.113883.4.642.1.72",
377                        "Contact Point System",
378                        "http://hl7.org/fhir/contact-point-system",
379                        "http://hl7.org/fhir/contact-point-system"),
380        ACT_STATUS(
381                        "2.16.840.1.113883.5.14",
382                        "Act Status",
383                        "http://terminology.hl7.org/CodeSystem/v3-ActStatus",
384                        "http://terminology.hl7.org/CodeSystem/v3-ActStatus"),
385        HL7_TERMINOLOGY_ADMINISTRATIVE_GENDER(
386                        "2.16.840.1.113883.5.1",
387                        "HL7 Terminology Administrative Gender",
388                        "http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender",
389                        "http://terminology.hl7.org/CodeSystem/v3-AdministrativeGender"),
390        ALLERGY_INTOLERANCE_TYPE(
391                        "2.16.840.1.113883.4.642.4.132",
392                        "Allergy Intolerance Type",
393                        "http://hl7.org/fhir/allergy-intolerance-type",
394                        "http://hl7.org/fhir/allergy-intolerance-type"),
395        ALLERGY_INTOLERANCE_REACTION_SEVERITY(
396                        "2.16.840.1.113883.4.642.4.136",
397                        "Allergy Intolerance Severity",
398                        "http://hl7.org/fhir/reaction-event-severity",
399                        "http://hl7.org/fhir/reaction-event-severity"),
400        DEVICE_STATUS(
401                        "2.16.840.1.113883.4.642.4.210",
402                        "Device Status",
403                        "http://hl7.org/fhir/device-status",
404                        "http://hl7.org/fhir/device-status"),
405        MEDICATION_STATUS(
406                        "2.16.840.1.113883.4.642.4.1380",
407                        "Nedication Status",
408                        "http://hl7.org/fhir/CodeSystem/medication-status",
409                        "http://hl7.org/fhir/CodeSystem/medication-status"),
410        OBSERVATION_STATUS(
411                        "2.16.840.1.113883.4.642.4.401",
412                        "Status of an observation",
413                        "http://hl7.org/fhir/observation-status",
414                        "http://hl7.org/fhir/observation-status"),
415        HISTORY_STATUS(
416                        "2.16.840.1.113883.4.642.4.268",
417                        "Family History Status",
418                        "http://hl7.org/fhir/history-status",
419                        "http://hl7.org/fhir/history-status"),
420        V2_TABLE_0131(
421                        "2.16.840.1.113883.18.58",
422                        "Master Code System for V2 table 0131 (Contact Role)",
423                        "http://hl7.org/fhir/v2/0131",
424                        "http://terminology.hl7.org/CodeSystem/v2-0131"),
425        HL7_CONDITION_CLINICAL_STATUS(
426                        "2.16.840.1.113883.4.642.1.1074 ",
427                        "Preferred value set for Condition Clinical Status",
428                        "http://terminology.hl7.org/CodeSystem/condition-clinical",
429                        "http://terminology.hl7.org/CodeSystem/condition-clinical"),
430        CONDITION_VERIFICATION_STATUS(
431                        "2.16.840.1.113883.4.642.1.1075 ",
432                        "The verification status to support or decline the clinical status of the condition or diagnosis",
433                        "http://terminology.hl7.org/CodeSystem/condition-ver-status",
434                        "http://terminology.hl7.org/CodeSystem/condition-ver-status"),
435        DATA_ABSENT_REASON(
436                        "2.16.840.1.113883.4.642.4.1048",
437                        "DataAbsentReason",
438                        "http://hl7.org/fhir/data-absent-reason",
439                        "http://terminology.hl7.org/CodeSystem/data-absent-reason"),
440        PROBLEM_ACT(
441                        "2.16.840.1.113883.11.20.9.19",
442                        "ProblemAct",
443                        "urn:oid:2.16.840.1.113883.11.20.9.19",
444                        "urn:oid:2.16.840.1.113883.11.20.9.19"),
445        RELIGIOUS_AFFILIATION(
446                        "2.16.840.1.113883.5.1076",
447                        "Assignment of spiritual faith affiliation",
448                        "http://terminology.hl7.org/CodeSystem/v3-ReligiousAffiliation",
449                        "http://terminology.hl7.org/CodeSystem/v3-ReligiousAffiliation"),
450        FAMILY_MEMBER_HISTORY(
451                        "2.16.840.1.113883.4.642.4.268",
452                        "FamilyHistoryStatus",
453                        "http://hl7.org/fhir/history-status",
454                        "http://hl7.org/fhir/history-status"),
455        NUBC_DISCHARGE_DISPOSITION(
456                        "2.16.840.1.113883.6.301.5",
457                        "NUBC code system for Patient Discharge Status",
458                        "http://www.nubc.org/patient-discharge",
459                        "http://www.nubc.org/patient-discharge"),
460        HL7_PARTICIPATION_FUNCTION(
461                        "2.16.840.1.113883.5.88",
462                        "ParticipationFunction",
463                        "http://hl7.org/fhir/v3/ParticipationFunction",
464                        "http://terminology.hl7.org/CodeSystem/v3-ParticipationFunction"),
465        HL7_ROLE_CLASS(
466                        "2.16.840.1.113883.5.110",
467                        "RoleClass",
468                        "http://hl7.org/fhir/v3/RoleClass",
469                        "http://terminology.hl7.org/CodeSystem/v3-RoleClass"),
470        CDA_CONFIDENTIALITY(
471                        "2.16.840.1.113883.5.25",
472                        null,
473                        "http://hl7.org/fhir/v3/Confidentiality",
474                        "http://terminology.hl7.org/CodeSystem/v3-Confidentiality"),
475        GOAL_LIFECYCLE_STATUS(
476                        "2.16.840.1.113883.4.642.4.272",
477                        "GoalLifecycleStatus",
478                        "http://hl7.org/fhir/goal-status",
479                        "http://hl7.org/fhir/goal-status"),
480
481        HL7_COMPOSITION_STATUS(
482                        "2.16.840.1.113883.4.642.4.242",
483                        "Composition Status",
484                        "http://hl7.org/fhir/composition-status",
485                        "http://hl7.org/fhir/composition-status"),
486
487        HL7_ENTITY_NAME_USE(
488                        "2.16.840.1.113883.5.45",
489                        "Entity Name Use",
490                        "http://terminology.hl7.org/CodeSystem/v3-EntityNameUse",
491                        "http://terminology.hl7.org/CodeSystem/v3-EntityNameUse"),
492        NAME_USE(
493                        "2.16.840.1.113883.4.642.4.66", "Name Use", "http://hl7.org/fhir/name-use", "http://hl7.org/fhir/name-use"),
494        HL7_URL_SCHEME(
495                        "2.16.840.1.113883.5.143",
496                        "URL Scheme",
497                        "http://terminology.hl7.org/CodeSystem/v3-URLScheme",
498                        "http://terminology.hl7.org/CodeSystem/v3-URLScheme"),
499        US_CORE_DOCUMENT_REFERENCE_CATEGORY_CODES(
500                        null,
501                        "US Core DocumentReferences Category Codes",
502                        "http://hl7.org/fhir/us/core/CodeSystem/us-core-documentreference-category",
503                        "http://hl7.org/fhir/us/core/CodeSystem/us-core-documentreference-category"),
504        EVENT_STATUS(
505                        "2.16.840.1.113883.4.642.4.110",
506                        "Event Status",
507                        "http://hl7.org/fhir/event-status",
508                        "http://hl7.org/fhir/event-status"),
509        NCTS_DATA_COMPONENTS(
510                        "1.2.36.1.2001.1001.101",
511                        "Data Components",
512                        "https://healthterminologies.gov.au/fhir/CodeSystem/nctis-data-components-1",
513                        "https://healthterminologies.gov.au/fhir/CodeSystem/nctis-data-components-1"),
514        CONSENT_CATEGORY_CODES(
515                        "2.16.840.1.113883.4.642.4.1226",
516                        "Consent Category Codes",
517                        "http://hl7.org/fhir/consentcategorycodes",
518                        "http://terminology.hl7.org/CodeSystem/consentcategorycodes"),
519        HL7V2_TBL_0270(
520                        "2.16.840.1.113883.18.163",
521                        "Document Type",
522                        "http://terminology.hl7.org/CodeSystem/v2-0270",
523                        "http://terminology.hl7.org/CodeSystem/v2-0270"),
524        COVERAGE_CLASS(
525                        "2.16.840.1.113883.4.642.4.1147",
526                        "Coverage Class",
527                        "http://terminology.hl7.org/CodeSystem/coverage-class",
528                        "http://terminology.hl7.org/CodeSystem/coverage-class"),
529        SUBSCRIBER_RELATIONSHIP(
530                        "2.16.840.1.113883.4.642.4.1386",
531                        "Subscriber Relationship",
532                        "http://terminology.hl7.org/CodeSystem/subscriber-relationship",
533                        "http://terminology.hl7.org/CodeSystem/subscriber-relationship"),
534        US_CORE_CATEGORY(
535                        "2.16.840.1.113883.4.642.40.2.16.3",
536                        "US Core Category",
537                        "http://hl7.org/fhir/us/core/CodeSystem/us-core-category",
538                        "http://hl7.org/fhir/us/core/CodeSystem/us-core-category"),
539        FM_STATUS(
540                        "2.16.840.1.113883.4.642.4.593",
541                        "Financial Resource Status Codes",
542                        "http://hl7.org/fhir/fm-status",
543                        "http://hl7.org/fhir/fm-status");
544
545        final String myOid;
546        final String myDisplay;
547        final String myCodeSystemUriDstu3;
548        final String myCodeSystemUriR4;
549        static Map<String, CodeSystemEnum> ourByOid;
550        static Map<FhirContext, Map<String, CodeSystemEnum>> ourByFhirUris = new HashMap<>();
551
552        CodeSystemEnum(String oid, String display, String codeSystemUriDstu3, String codeSystemUriR4) {
553                this.myOid = oid;
554                this.myDisplay = display;
555                this.myCodeSystemUriDstu3 = codeSystemUriDstu3;
556                this.myCodeSystemUriR4 = codeSystemUriR4;
557        }
558
559        public static CodeSystemEnum fromOid(String theOid) {
560                if (theOid == null) {
561                        return null;
562                }
563
564                if (ourByOid == null) {
565                        HashMap<String, CodeSystemEnum> values = new HashMap<>();
566                        for (CodeSystemEnum next : values()) {
567                                values.put(next.getOid(), next);
568                        }
569                        ourByOid = Collections.unmodifiableMap(values);
570                }
571                return ourByOid.get(theOid);
572        }
573
574        public static CodeSystemEnum fromCodeSystemUri(String theFhirUri) {
575                // The legacy implementation assumes DSTU3, we have to preserve that for now.
576                // We can get rid of this after the old module is removed.
577                return fromCodeSystemUri(theFhirUri, FhirContext.forDstu3Cached());
578        }
579
580        public static CodeSystemEnum fromCodeSystemUri(String theFhirUri, FhirContext theFhirContext) {
581                if (!ourByFhirUris.containsKey(theFhirContext)) {
582                        HashMap<String, CodeSystemEnum> values = new HashMap<>();
583                        for (CodeSystemEnum next : values()) {
584                                values.put(next.getCodeSystemUri(theFhirContext), next);
585                        }
586                        ourByFhirUris.put(theFhirContext, Collections.unmodifiableMap(values));
587                }
588                return ourByFhirUris.get(theFhirContext).get(theFhirUri);
589        }
590
591        public String getOid() {
592                return myOid;
593        }
594
595        public boolean hasOid() {
596                return this.getOid() != null && !this.getOid().equals("");
597        }
598
599        public String getDisplay() {
600                return myDisplay;
601        }
602
603        public boolean hasDisplay() {
604                return myDisplay != null;
605        }
606
607        public String getCodeSystemUri() {
608                return getCodeSystemUri((FhirVersionEnum) null);
609        }
610
611        public String getCodeSystemUri(FhirContext theCtx) {
612                if (theCtx != null) {
613                        return getCodeSystemUri(theCtx.getVersion().getVersion());
614                }
615                return myCodeSystemUriDstu3;
616        }
617
618        public String getCodeSystemUri(FhirVersionEnum theVersion) {
619                String retVal = myCodeSystemUriDstu3;
620                if ((null != theVersion) && theVersion.isEqualOrNewerThan(FhirVersionEnum.R4)) {
621                        retVal = myCodeSystemUriR4;
622                }
623                return retVal;
624        }
625
626        public boolean hasCodeSystemUri() {
627                return myCodeSystemUriDstu3 != null;
628        }
629
630        /**
631         * @deprecated Only used in the legacy CDA transformer
632         */
633        public Coding seedCoding() {
634                return new Coding().setSystem(this.getOid());
635        }
636
637        public boolean isTheStringReferringToThisSystem(String systemCode) {
638                if (systemCode == null) {
639                        return false;
640                }
641                return systemCode.equals(this.myCodeSystemUriDstu3)
642                                || systemCode.equals(this.myOid)
643                                || systemCode.equals("urn:oid:" + this.myOid);
644        }
645}