fhir-data-utils-ts 0.2.4 → 0.3.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.
Files changed (285) hide show
  1. package/.codex/skills/govern-fhir-data-utilities/SKILL.md +58 -0
  2. package/.codex/skills/govern-fhir-data-utilities/agents/openai.yaml +4 -0
  3. package/.codex/skills/govern-fhir-observation-components/SKILL.md +18 -0
  4. package/CHANGELOG.md +30 -0
  5. package/README.md +39 -0
  6. package/dist/builders/immunization-graph.d.ts +36 -0
  7. package/dist/builders/immunization-graph.js +115 -0
  8. package/dist/builders/immunization-reminders.d.ts +35 -0
  9. package/dist/builders/immunization-reminders.js +104 -0
  10. package/dist/builders/index.d.ts +2 -0
  11. package/dist/builders/index.js +2 -0
  12. package/dist/claim-helpers/claim-list-helpers.d.ts +21 -0
  13. package/dist/claim-helpers/claim-list-helpers.js +54 -0
  14. package/dist/claim-helpers/claims-helpers-allergy-intolerance.d.ts +18 -0
  15. package/dist/claim-helpers/claims-helpers-allergy-intolerance.js +65 -0
  16. package/dist/claim-helpers/claims-helpers-appointment-response.d.ts +8 -0
  17. package/dist/claim-helpers/claims-helpers-appointment-response.js +20 -0
  18. package/dist/claim-helpers/claims-helpers-appointment.d.ts +10 -0
  19. package/dist/claim-helpers/claims-helpers-appointment.js +26 -0
  20. package/dist/claim-helpers/claims-helpers-care-plan.d.ts +8 -0
  21. package/dist/claim-helpers/claims-helpers-care-plan.js +20 -0
  22. package/dist/claim-helpers/claims-helpers-clinical-impression.d.ts +10 -0
  23. package/dist/claim-helpers/claims-helpers-clinical-impression.js +26 -0
  24. package/dist/claim-helpers/claims-helpers-communication.d.ts +19 -0
  25. package/dist/claim-helpers/claims-helpers-communication.js +63 -0
  26. package/dist/claim-helpers/claims-helpers-composition.d.ts +12 -0
  27. package/dist/claim-helpers/claims-helpers-composition.js +32 -0
  28. package/dist/claim-helpers/claims-helpers-condition.d.ts +18 -0
  29. package/dist/claim-helpers/claims-helpers-condition.js +65 -0
  30. package/dist/claim-helpers/claims-helpers-coverage.d.ts +10 -0
  31. package/dist/claim-helpers/claims-helpers-coverage.js +26 -0
  32. package/dist/claim-helpers/claims-helpers-device-use-statement.d.ts +8 -0
  33. package/dist/claim-helpers/claims-helpers-device-use-statement.js +20 -0
  34. package/dist/claim-helpers/claims-helpers-device.d.ts +8 -0
  35. package/dist/claim-helpers/claims-helpers-device.js +20 -0
  36. package/dist/claim-helpers/claims-helpers-diagnostic-report.d.ts +16 -0
  37. package/dist/claim-helpers/claims-helpers-diagnostic-report.js +47 -0
  38. package/dist/claim-helpers/claims-helpers-document-reference.d.ts +8 -0
  39. package/dist/claim-helpers/claims-helpers-document-reference.js +20 -0
  40. package/dist/claim-helpers/claims-helpers-encounter.d.ts +10 -0
  41. package/dist/claim-helpers/claims-helpers-encounter.js +26 -0
  42. package/dist/claim-helpers/claims-helpers-flag.d.ts +8 -0
  43. package/dist/claim-helpers/claims-helpers-flag.js +20 -0
  44. package/dist/claim-helpers/claims-helpers-immunization.d.ts +8 -0
  45. package/dist/claim-helpers/claims-helpers-immunization.js +20 -0
  46. package/dist/claim-helpers/claims-helpers-location.d.ts +10 -0
  47. package/dist/claim-helpers/claims-helpers-location.js +26 -0
  48. package/dist/claim-helpers/claims-helpers-medication-statement.d.ts +96 -0
  49. package/dist/claim-helpers/claims-helpers-medication-statement.js +278 -0
  50. package/dist/claim-helpers/claims-helpers-observation.d.ts +8 -0
  51. package/dist/claim-helpers/claims-helpers-observation.js +20 -0
  52. package/dist/claim-helpers/claims-helpers-organization.d.ts +12 -0
  53. package/dist/claim-helpers/claims-helpers-organization.js +32 -0
  54. package/dist/claim-helpers/claims-helpers-procedure.d.ts +8 -0
  55. package/dist/claim-helpers/claims-helpers-procedure.js +20 -0
  56. package/dist/claim-helpers/claims-helpers-related-person.d.ts +22 -0
  57. package/dist/claim-helpers/claims-helpers-related-person.js +53 -0
  58. package/dist/claim-helpers/index.d.ts +23 -0
  59. package/dist/claim-helpers/index.js +23 -0
  60. package/dist/claims/allergy-intolerance-claims.d.ts +153 -0
  61. package/dist/claims/allergy-intolerance-claims.js +194 -0
  62. package/dist/claims/appointment-claims.d.ts +226 -0
  63. package/dist/claims/appointment-claims.js +218 -0
  64. package/dist/claims/appointment-response-claims.d.ts +63 -0
  65. package/dist/claims/appointment-response-claims.js +58 -0
  66. package/dist/claims/care-plan-claims.d.ts +37 -0
  67. package/dist/claims/care-plan-claims.js +59 -0
  68. package/dist/claims/claim-types.d.ts +9 -0
  69. package/dist/claims/claim-types.js +3 -0
  70. package/dist/claims/clinical-impression-claims.d.ts +17 -0
  71. package/dist/claims/clinical-impression-claims.js +30 -0
  72. package/dist/claims/communication-claims.d.ts +55 -0
  73. package/dist/claims/communication-claims.js +57 -0
  74. package/dist/claims/composition-claims.d.ts +27 -0
  75. package/dist/claims/composition-claims.js +27 -0
  76. package/dist/claims/condition-claims.d.ts +79 -0
  77. package/dist/claims/condition-claims.js +104 -0
  78. package/dist/claims/consent-claims.d.ts +195 -0
  79. package/dist/claims/consent-claims.js +74 -0
  80. package/dist/claims/coverage-claims.d.ts +16 -0
  81. package/dist/claims/coverage-claims.js +28 -0
  82. package/dist/claims/device-claims.d.ts +20 -0
  83. package/dist/claims/device-claims.js +36 -0
  84. package/dist/claims/device-use-statement-claims.d.ts +17 -0
  85. package/dist/claims/device-use-statement-claims.js +28 -0
  86. package/dist/claims/diagnostic-report-claims.d.ts +109 -0
  87. package/dist/claims/diagnostic-report-claims.js +120 -0
  88. package/dist/claims/document-reference-claims.d.ts +39 -0
  89. package/dist/claims/document-reference-claims.js +96 -0
  90. package/dist/claims/encounter-claims.d.ts +18 -0
  91. package/dist/claims/encounter-claims.js +32 -0
  92. package/dist/claims/flag-claims.d.ts +19 -0
  93. package/dist/claims/flag-claims.js +33 -0
  94. package/dist/claims/immunization-claims.d.ts +31 -0
  95. package/dist/claims/immunization-claims.js +54 -0
  96. package/dist/claims/immunization-recommendation-claims.d.ts +19 -0
  97. package/dist/claims/immunization-recommendation-claims.js +26 -0
  98. package/dist/claims/index.d.ts +29 -0
  99. package/dist/claims/index.js +29 -0
  100. package/dist/claims/invoice-claims.d.ts +277 -0
  101. package/dist/claims/invoice-claims.js +357 -0
  102. package/dist/claims/location-claims.d.ts +22 -0
  103. package/dist/claims/location-claims.js +34 -0
  104. package/dist/claims/medication-claims.d.ts +15 -0
  105. package/dist/claims/medication-claims.js +23 -0
  106. package/dist/claims/medication-statement-claims.d.ts +539 -0
  107. package/dist/claims/medication-statement-claims.js +469 -0
  108. package/dist/claims/organization-claims.d.ts +18 -0
  109. package/dist/claims/organization-claims.js +27 -0
  110. package/dist/claims/practitioner-role-claims.d.ts +18 -0
  111. package/dist/claims/practitioner-role-claims.js +33 -0
  112. package/dist/claims/procedure-claims.d.ts +24 -0
  113. package/dist/claims/procedure-claims.js +44 -0
  114. package/dist/claims/related-person-claims.d.ts +30 -0
  115. package/dist/claims/related-person-claims.js +44 -0
  116. package/dist/claims/research-subject-claims.d.ts +4 -0
  117. package/dist/claims/research-subject-claims.js +4 -0
  118. package/dist/claims/task-claims.d.ts +61 -0
  119. package/dist/claims/task-claims.js +64 -0
  120. package/dist/clinical-terminology.d.ts +73 -0
  121. package/dist/clinical-terminology.js +77 -0
  122. package/dist/constants/clinical-statuses.d.ts +102 -0
  123. package/dist/constants/clinical-statuses.js +93 -0
  124. package/dist/constants/fhir-code-systems.d.ts +15 -0
  125. package/dist/constants/fhir-code-systems.js +15 -0
  126. package/dist/constants/fhir-resource-types.d.ts +162 -0
  127. package/dist/constants/fhir-resource-types.js +70 -0
  128. package/dist/constants/fhir-versions.d.ts +10 -0
  129. package/dist/constants/fhir-versions.js +10 -0
  130. package/dist/constants/index.d.ts +4 -0
  131. package/dist/constants/index.js +4 -0
  132. package/dist/converters/convert-allergy-intolerance.d.ts +3 -0
  133. package/dist/converters/convert-allergy-intolerance.js +85 -0
  134. package/dist/converters/convert-appointment-response.d.ts +3 -0
  135. package/dist/converters/convert-appointment-response.js +32 -0
  136. package/dist/converters/convert-appointment.d.ts +3 -0
  137. package/dist/converters/convert-appointment.js +61 -0
  138. package/dist/converters/convert-care-plan.d.ts +3 -0
  139. package/dist/converters/convert-care-plan.js +93 -0
  140. package/dist/converters/convert-clinical-impression.d.ts +3 -0
  141. package/dist/converters/convert-clinical-impression.js +42 -0
  142. package/dist/converters/convert-composition.d.ts +3 -0
  143. package/dist/converters/convert-composition.js +70 -0
  144. package/dist/converters/convert-condition.d.ts +3 -0
  145. package/dist/converters/convert-condition.js +51 -0
  146. package/dist/converters/convert-consent.d.ts +9 -0
  147. package/dist/converters/convert-consent.js +174 -0
  148. package/dist/converters/convert-coverage.d.ts +3 -0
  149. package/dist/converters/convert-coverage.js +51 -0
  150. package/dist/converters/convert-device-use-statement.d.ts +3 -0
  151. package/dist/converters/convert-device-use-statement.js +36 -0
  152. package/dist/converters/convert-device.d.ts +3 -0
  153. package/dist/converters/convert-device.js +48 -0
  154. package/dist/converters/convert-diagnostic-report.d.ts +3 -0
  155. package/dist/converters/convert-diagnostic-report.js +63 -0
  156. package/dist/converters/convert-document-reference.d.ts +3 -0
  157. package/dist/converters/convert-document-reference.js +54 -0
  158. package/dist/converters/convert-encounter.d.ts +3 -0
  159. package/dist/converters/convert-encounter.js +68 -0
  160. package/dist/converters/convert-flag.d.ts +3 -0
  161. package/dist/converters/convert-flag.js +42 -0
  162. package/dist/converters/convert-immunization.d.ts +3 -0
  163. package/dist/converters/convert-immunization.js +80 -0
  164. package/dist/converters/convert-location.d.ts +3 -0
  165. package/dist/converters/convert-location.js +44 -0
  166. package/dist/converters/convert-medication-statement.d.ts +3 -0
  167. package/dist/converters/convert-medication-statement.js +130 -0
  168. package/dist/converters/convert-observation.d.ts +33 -0
  169. package/dist/converters/convert-observation.js +246 -0
  170. package/dist/converters/convert-organization.d.ts +3 -0
  171. package/dist/converters/convert-organization.js +39 -0
  172. package/dist/converters/convert-practitioner-role.d.ts +3 -0
  173. package/dist/converters/convert-practitioner-role.js +62 -0
  174. package/dist/converters/convert-procedure.d.ts +3 -0
  175. package/dist/converters/convert-procedure.js +64 -0
  176. package/dist/converters/convert-related-person.d.ts +3 -0
  177. package/dist/converters/convert-related-person.js +31 -0
  178. package/dist/converters/convert-shared.d.ts +33 -0
  179. package/dist/converters/convert-shared.js +181 -0
  180. package/dist/converters/index.d.ts +24 -0
  181. package/dist/converters/index.js +24 -0
  182. package/dist/fhir-bundle.d.ts +9 -0
  183. package/dist/fhir-bundle.js +43 -0
  184. package/dist/fhir-search-parameters.d.ts +18 -0
  185. package/dist/fhir-search-parameters.js +52 -0
  186. package/dist/fhir-tokens.d.ts +11 -0
  187. package/dist/fhir-tokens.js +26 -0
  188. package/dist/fhir-types.d.ts +77 -0
  189. package/dist/fhir-types.js +1 -0
  190. package/dist/fhir-values.d.ts +13 -0
  191. package/dist/fhir-values.js +53 -0
  192. package/dist/group-r5.d.ts +121 -0
  193. package/dist/group-r5.js +301 -0
  194. package/dist/imaging-types.d.ts +30 -0
  195. package/dist/imaging-types.js +1 -0
  196. package/dist/immunization-flat-claims.d.ts +2 -0
  197. package/dist/immunization-flat-claims.js +2 -0
  198. package/dist/immunization-reminder-plan.d.ts +2 -0
  199. package/dist/immunization-reminder-plan.js +2 -0
  200. package/dist/index.d.ts +19 -0
  201. package/dist/index.js +19 -0
  202. package/dist/observation-claims.d.ts +170 -0
  203. package/dist/observation-claims.js +184 -0
  204. package/dist/related-person.d.ts +16 -0
  205. package/dist/related-person.js +14 -0
  206. package/dist/research-study-r5.d.ts +163 -0
  207. package/dist/research-study-r5.js +490 -0
  208. package/dist/search-models/index.d.ts +7 -0
  209. package/dist/search-models/index.js +7 -0
  210. package/dist/search-models/params/AdverseEvent.params.model.d.ts +14 -0
  211. package/dist/search-models/params/AdverseEvent.params.model.js +16 -0
  212. package/dist/search-models/params/AllergyIntolerance.params.model.d.ts +24 -0
  213. package/dist/search-models/params/AllergyIntolerance.params.model.js +27 -0
  214. package/dist/search-models/params/Appointment.params.model.d.ts +12 -0
  215. package/dist/search-models/params/Appointment.params.model.js +14 -0
  216. package/dist/search-models/params/ClinicalImpression.params.model.d.ts +14 -0
  217. package/dist/search-models/params/ClinicalImpression.params.model.js +15 -0
  218. package/dist/search-models/params/Condition.params.model.d.ts +16 -0
  219. package/dist/search-models/params/Condition.params.model.js +17 -0
  220. package/dist/search-models/params/DetectedIssue.params.model.d.ts +9 -0
  221. package/dist/search-models/params/DetectedIssue.params.model.js +11 -0
  222. package/dist/search-models/params/DiagnosticReport.params.model.d.ts +13 -0
  223. package/dist/search-models/params/DiagnosticReport.params.model.js +14 -0
  224. package/dist/search-models/params/Encounter.params.model.d.ts +15 -0
  225. package/dist/search-models/params/Encounter.params.model.js +17 -0
  226. package/dist/search-models/params/Immunization.params.model.d.ts +14 -0
  227. package/dist/search-models/params/Immunization.params.model.js +16 -0
  228. package/dist/search-models/params/Medication.params.model.d.ts +35 -0
  229. package/dist/search-models/params/Medication.params.model.js +45 -0
  230. package/dist/search-models/params/Observation.params.model.d.ts +326 -0
  231. package/dist/search-models/params/Observation.params.model.js +244 -0
  232. package/dist/search-models/params/Procedure.params.model.d.ts +15 -0
  233. package/dist/search-models/params/Procedure.params.model.js +17 -0
  234. package/dist/search-models/params/Search.params.model.d.ts +75 -0
  235. package/dist/search-models/params/Search.params.model.js +69 -0
  236. package/dist/search-models/params/ServiceRequest.params.model.d.ts +14 -0
  237. package/dist/search-models/params/ServiceRequest.params.model.js +16 -0
  238. package/dist/search-models/params/Specimen.params.model.d.ts +10 -0
  239. package/dist/search-models/params/Specimen.params.model.js +12 -0
  240. package/dist/search-models/params/index.d.ts +15 -0
  241. package/dist/search-models/params/index.js +15 -0
  242. package/dist/search-models/templates/AdverseEvent.template.model.d.ts +16 -0
  243. package/dist/search-models/templates/AdverseEvent.template.model.js +2 -0
  244. package/dist/search-models/templates/AllergyIntolerance.template.model.d.ts +24 -0
  245. package/dist/search-models/templates/AllergyIntolerance.template.model.js +1 -0
  246. package/dist/search-models/templates/Appointment.template.model.d.ts +13 -0
  247. package/dist/search-models/templates/Appointment.template.model.js +1 -0
  248. package/dist/search-models/templates/ClinicalImpression.template.model.d.ts +16 -0
  249. package/dist/search-models/templates/ClinicalImpression.template.model.js +1 -0
  250. package/dist/search-models/templates/Condition.template.model.d.ts +18 -0
  251. package/dist/search-models/templates/Condition.template.model.js +1 -0
  252. package/dist/search-models/templates/DetectedIssue.template.model.d.ts +11 -0
  253. package/dist/search-models/templates/DetectedIssue.template.model.js +1 -0
  254. package/dist/search-models/templates/DiagnosticReport.template.model.d.ts +15 -0
  255. package/dist/search-models/templates/DiagnosticReport.template.model.js +1 -0
  256. package/dist/search-models/templates/Encounter.template.model.d.ts +17 -0
  257. package/dist/search-models/templates/Encounter.template.model.js +1 -0
  258. package/dist/search-models/templates/Immunization.template.model.d.ts +18 -0
  259. package/dist/search-models/templates/Immunization.template.model.js +2 -0
  260. package/dist/search-models/templates/Medication.template.model.d.ts +37 -0
  261. package/dist/search-models/templates/Medication.template.model.js +1 -0
  262. package/dist/search-models/templates/Observation.template.model.d.ts +18 -0
  263. package/dist/search-models/templates/Observation.template.model.js +1 -0
  264. package/dist/search-models/templates/Procedure.template.model.d.ts +17 -0
  265. package/dist/search-models/templates/Procedure.template.model.js +1 -0
  266. package/dist/search-models/templates/ServiceRequest.template.model.d.ts +16 -0
  267. package/dist/search-models/templates/ServiceRequest.template.model.js +1 -0
  268. package/dist/search-models/templates/Specimen.template.model.d.ts +12 -0
  269. package/dist/search-models/templates/Specimen.template.model.js +1 -0
  270. package/dist/search-models/templates/index.d.ts +14 -0
  271. package/dist/search-models/templates/index.js +14 -0
  272. package/dist/terminology-models/AtcModel.d.ts +15 -0
  273. package/dist/terminology-models/AtcModel.js +2 -0
  274. package/dist/terminology-models/CommonModels.d.ts +70 -0
  275. package/dist/terminology-models/CommonModels.js +55 -0
  276. package/dist/terminology-models/FhirModels.d.ts +60 -0
  277. package/dist/terminology-models/FhirModels.js +34 -0
  278. package/dist/terminology-models/LoincModels.d.ts +24 -0
  279. package/dist/terminology-models/LoincModels.js +2 -0
  280. package/dist/terminology-models/SnomedModels.d.ts +13 -0
  281. package/dist/terminology-models/SnomedModels.js +2 -0
  282. package/dist/terminology-models/index.d.ts +6 -0
  283. package/dist/terminology-models/index.js +6 -0
  284. package/docs/UHC_FHIR_UTILS_MIGRATION.md +51 -8
  285. package/package.json +83 -2
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Canonical FHIR R4 `resourceType` names shared across GW and SDK packages.
3
+ *
4
+ * Use these constants instead of inline strings such as `"Observation"`
5
+ * or `"DocumentReference"` when building bundles, filters, or SDK facades.
6
+ */
7
+ export declare const ResourceTypesFhirR4: Readonly<{
8
+ readonly AdverseEvent: "AdverseEvent";
9
+ readonly AllergyIntolerance: "AllergyIntolerance";
10
+ readonly Appointment: "Appointment";
11
+ readonly AppointmentResponse: "AppointmentResponse";
12
+ readonly Bundle: "Bundle";
13
+ readonly CarePlan: "CarePlan";
14
+ readonly ClinicalImpression: "ClinicalImpression";
15
+ readonly Communication: "Communication";
16
+ readonly Composition: "Composition";
17
+ readonly Condition: "Condition";
18
+ readonly Consent: "Consent";
19
+ readonly Coverage: "Coverage";
20
+ readonly Device: "Device";
21
+ readonly DeviceUseStatement: "DeviceUseStatement";
22
+ readonly DiagnosticReport: "DiagnosticReport";
23
+ readonly DocumentReference: "DocumentReference";
24
+ readonly Encounter: "Encounter";
25
+ readonly Flag: "Flag";
26
+ readonly Group: "Group";
27
+ readonly ImagingStudy: "ImagingStudy";
28
+ readonly Immunization: "Immunization";
29
+ readonly ImmunizationRecommendation: "ImmunizationRecommendation";
30
+ readonly Invoice: "Invoice";
31
+ readonly Location: "Location";
32
+ readonly Medication: "Medication";
33
+ readonly MedicationAdministration: "MedicationAdministration";
34
+ readonly MedicationDispense: "MedicationDispense";
35
+ readonly MedicationRequest: "MedicationRequest";
36
+ readonly MedicationStatement: "MedicationStatement";
37
+ readonly Observation: "Observation";
38
+ readonly OperationOutcome: "OperationOutcome";
39
+ readonly Organization: "Organization";
40
+ readonly Parameters: "Parameters";
41
+ readonly Patient: "Patient";
42
+ readonly Person: "Person";
43
+ readonly Practitioner: "Practitioner";
44
+ readonly PractitionerRole: "PractitionerRole";
45
+ readonly Procedure: "Procedure";
46
+ readonly RelatedPerson: "RelatedPerson";
47
+ readonly ResearchStudy: "ResearchStudy";
48
+ readonly ResearchSubject: "ResearchSubject";
49
+ readonly Specimen: "Specimen";
50
+ readonly ServiceRequest: "ServiceRequest";
51
+ readonly Task: "Task";
52
+ readonly DetectedIssue: "DetectedIssue";
53
+ }>;
54
+ /** One canonical FHIR R4 `resourceType` value. */
55
+ export type ResourceTypeFhirR4 = typeof ResourceTypesFhirR4[keyof typeof ResourceTypesFhirR4];
56
+ /**
57
+ * Backwards-compatible alias for the former generic name.
58
+ *
59
+ * Prefer `ResourceTypesFhirR4` in new code so later R5/R6 catalogs can coexist
60
+ * without ambiguity.
61
+ */
62
+ export declare const FhirResourceTypes: Readonly<{
63
+ readonly AdverseEvent: "AdverseEvent";
64
+ readonly AllergyIntolerance: "AllergyIntolerance";
65
+ readonly Appointment: "Appointment";
66
+ readonly AppointmentResponse: "AppointmentResponse";
67
+ readonly Bundle: "Bundle";
68
+ readonly CarePlan: "CarePlan";
69
+ readonly ClinicalImpression: "ClinicalImpression";
70
+ readonly Communication: "Communication";
71
+ readonly Composition: "Composition";
72
+ readonly Condition: "Condition";
73
+ readonly Consent: "Consent";
74
+ readonly Coverage: "Coverage";
75
+ readonly Device: "Device";
76
+ readonly DeviceUseStatement: "DeviceUseStatement";
77
+ readonly DiagnosticReport: "DiagnosticReport";
78
+ readonly DocumentReference: "DocumentReference";
79
+ readonly Encounter: "Encounter";
80
+ readonly Flag: "Flag";
81
+ readonly Group: "Group";
82
+ readonly ImagingStudy: "ImagingStudy";
83
+ readonly Immunization: "Immunization";
84
+ readonly ImmunizationRecommendation: "ImmunizationRecommendation";
85
+ readonly Invoice: "Invoice";
86
+ readonly Location: "Location";
87
+ readonly Medication: "Medication";
88
+ readonly MedicationAdministration: "MedicationAdministration";
89
+ readonly MedicationDispense: "MedicationDispense";
90
+ readonly MedicationRequest: "MedicationRequest";
91
+ readonly MedicationStatement: "MedicationStatement";
92
+ readonly Observation: "Observation";
93
+ readonly OperationOutcome: "OperationOutcome";
94
+ readonly Organization: "Organization";
95
+ readonly Parameters: "Parameters";
96
+ readonly Patient: "Patient";
97
+ readonly Person: "Person";
98
+ readonly Practitioner: "Practitioner";
99
+ readonly PractitionerRole: "PractitionerRole";
100
+ readonly Procedure: "Procedure";
101
+ readonly RelatedPerson: "RelatedPerson";
102
+ readonly ResearchStudy: "ResearchStudy";
103
+ readonly ResearchSubject: "ResearchSubject";
104
+ readonly Specimen: "Specimen";
105
+ readonly ServiceRequest: "ServiceRequest";
106
+ readonly Task: "Task";
107
+ readonly DetectedIssue: "DetectedIssue";
108
+ }>;
109
+ /** FHIR R5-only resources currently emitted by shared subscription contracts. */
110
+ export declare const ResourceTypesFhirR5: Readonly<{
111
+ readonly SubscriptionStatus: "SubscriptionStatus";
112
+ readonly AdverseEvent: "AdverseEvent";
113
+ readonly AllergyIntolerance: "AllergyIntolerance";
114
+ readonly Appointment: "Appointment";
115
+ readonly AppointmentResponse: "AppointmentResponse";
116
+ readonly Bundle: "Bundle";
117
+ readonly CarePlan: "CarePlan";
118
+ readonly ClinicalImpression: "ClinicalImpression";
119
+ readonly Communication: "Communication";
120
+ readonly Composition: "Composition";
121
+ readonly Condition: "Condition";
122
+ readonly Consent: "Consent";
123
+ readonly Coverage: "Coverage";
124
+ readonly Device: "Device";
125
+ readonly DeviceUseStatement: "DeviceUseStatement";
126
+ readonly DiagnosticReport: "DiagnosticReport";
127
+ readonly DocumentReference: "DocumentReference";
128
+ readonly Encounter: "Encounter";
129
+ readonly Flag: "Flag";
130
+ readonly Group: "Group";
131
+ readonly ImagingStudy: "ImagingStudy";
132
+ readonly Immunization: "Immunization";
133
+ readonly ImmunizationRecommendation: "ImmunizationRecommendation";
134
+ readonly Invoice: "Invoice";
135
+ readonly Location: "Location";
136
+ readonly Medication: "Medication";
137
+ readonly MedicationAdministration: "MedicationAdministration";
138
+ readonly MedicationDispense: "MedicationDispense";
139
+ readonly MedicationRequest: "MedicationRequest";
140
+ readonly MedicationStatement: "MedicationStatement";
141
+ readonly Observation: "Observation";
142
+ readonly OperationOutcome: "OperationOutcome";
143
+ readonly Organization: "Organization";
144
+ readonly Parameters: "Parameters";
145
+ readonly Patient: "Patient";
146
+ readonly Person: "Person";
147
+ readonly Practitioner: "Practitioner";
148
+ readonly PractitionerRole: "PractitionerRole";
149
+ readonly Procedure: "Procedure";
150
+ readonly RelatedPerson: "RelatedPerson";
151
+ readonly ResearchStudy: "ResearchStudy";
152
+ readonly ResearchSubject: "ResearchSubject";
153
+ readonly Specimen: "Specimen";
154
+ readonly ServiceRequest: "ServiceRequest";
155
+ readonly Task: "Task";
156
+ readonly DetectedIssue: "DetectedIssue";
157
+ }>;
158
+ /** FHIR complex datatypes used as discriminators inside claims-first payloads. */
159
+ export declare const FhirDataTypes: Readonly<{
160
+ readonly Annotation: "Annotation";
161
+ readonly Attachment: "Attachment";
162
+ }>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Canonical FHIR R4 `resourceType` names shared across GW and SDK packages.
3
+ *
4
+ * Use these constants instead of inline strings such as `"Observation"`
5
+ * or `"DocumentReference"` when building bundles, filters, or SDK facades.
6
+ */
7
+ export const ResourceTypesFhirR4 = Object.freeze({
8
+ AdverseEvent: 'AdverseEvent',
9
+ AllergyIntolerance: 'AllergyIntolerance',
10
+ Appointment: 'Appointment',
11
+ AppointmentResponse: 'AppointmentResponse',
12
+ Bundle: 'Bundle',
13
+ CarePlan: 'CarePlan',
14
+ ClinicalImpression: 'ClinicalImpression',
15
+ Communication: 'Communication',
16
+ Composition: 'Composition',
17
+ Condition: 'Condition',
18
+ Consent: 'Consent',
19
+ Coverage: 'Coverage',
20
+ Device: 'Device',
21
+ DeviceUseStatement: 'DeviceUseStatement',
22
+ DiagnosticReport: 'DiagnosticReport',
23
+ DocumentReference: 'DocumentReference',
24
+ Encounter: 'Encounter',
25
+ Flag: 'Flag',
26
+ Group: 'Group',
27
+ ImagingStudy: 'ImagingStudy',
28
+ Immunization: 'Immunization',
29
+ ImmunizationRecommendation: 'ImmunizationRecommendation',
30
+ Invoice: 'Invoice',
31
+ Location: 'Location',
32
+ Medication: 'Medication',
33
+ MedicationAdministration: 'MedicationAdministration',
34
+ MedicationDispense: 'MedicationDispense',
35
+ MedicationRequest: 'MedicationRequest',
36
+ MedicationStatement: 'MedicationStatement',
37
+ Observation: 'Observation',
38
+ OperationOutcome: 'OperationOutcome',
39
+ Organization: 'Organization',
40
+ Parameters: 'Parameters',
41
+ Patient: 'Patient',
42
+ Person: 'Person',
43
+ Practitioner: 'Practitioner',
44
+ PractitionerRole: 'PractitionerRole',
45
+ Procedure: 'Procedure',
46
+ RelatedPerson: 'RelatedPerson',
47
+ ResearchStudy: 'ResearchStudy',
48
+ ResearchSubject: 'ResearchSubject',
49
+ Specimen: 'Specimen',
50
+ ServiceRequest: 'ServiceRequest',
51
+ Task: 'Task',
52
+ DetectedIssue: 'DetectedIssue',
53
+ });
54
+ /**
55
+ * Backwards-compatible alias for the former generic name.
56
+ *
57
+ * Prefer `ResourceTypesFhirR4` in new code so later R5/R6 catalogs can coexist
58
+ * without ambiguity.
59
+ */
60
+ export const FhirResourceTypes = ResourceTypesFhirR4;
61
+ /** FHIR R5-only resources currently emitted by shared subscription contracts. */
62
+ export const ResourceTypesFhirR5 = Object.freeze({
63
+ ...ResourceTypesFhirR4,
64
+ SubscriptionStatus: 'SubscriptionStatus',
65
+ });
66
+ /** FHIR complex datatypes used as discriminators inside claims-first payloads. */
67
+ export const FhirDataTypes = Object.freeze({
68
+ Annotation: 'Annotation',
69
+ Attachment: 'Attachment',
70
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Canonical FHIR version labels shared across GW and SDK packages.
3
+ *
4
+ * Use these constants instead of inline strings such as `"4.0"` or `"5.0"`.
5
+ */
6
+ export declare const FhirVersions: Readonly<{
7
+ readonly R4: "4.0";
8
+ readonly R401: "4.0.1";
9
+ readonly R5: "5.0";
10
+ }>;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Canonical FHIR version labels shared across GW and SDK packages.
3
+ *
4
+ * Use these constants instead of inline strings such as `"4.0"` or `"5.0"`.
5
+ */
6
+ export const FhirVersions = Object.freeze({
7
+ R4: '4.0',
8
+ R401: '4.0.1',
9
+ R5: '5.0',
10
+ });
@@ -0,0 +1,4 @@
1
+ export * from './fhir-code-systems.js';
2
+ export * from './fhir-resource-types.js';
3
+ export * from './fhir-versions.js';
4
+ export * from './clinical-statuses.js';
@@ -0,0 +1,4 @@
1
+ export * from './fhir-code-systems.js';
2
+ export * from './fhir-resource-types.js';
3
+ export * from './fhir-versions.js';
4
+ export * from './clinical-statuses.js';
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function allergyIntoleranceFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function allergyIntoleranceFhirR4ToFlat(resource: FhirResource): FlatClaims;
@@ -0,0 +1,85 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/utils/convert-allergy-intolerance.ts
3
+ import { AllergyIntoleranceClaim } from '../claims/allergy-intolerance-claims.js';
4
+ import { codingFromValue, codingToValue, requireDidWeb, requireSubjectIdentifier } from './convert-shared.js';
5
+ export function allergyIntoleranceFlatToFhirR4(claims) {
6
+ const patient = claims[AllergyIntoleranceClaim.Subject] ?? claims[AllergyIntoleranceClaim.Patient];
7
+ const recorder = claims[AllergyIntoleranceClaim.Recorder];
8
+ const manifestation = claims[AllergyIntoleranceClaim.Manifestation];
9
+ const severity = claims[AllergyIntoleranceClaim.Severity];
10
+ const reactionOnset = claims[AllergyIntoleranceClaim.Onset];
11
+ const route = claims[AllergyIntoleranceClaim.Route];
12
+ if (!patient)
13
+ throw new Error(`Missing required claim: ${AllergyIntoleranceClaim.Subject}`);
14
+ if ((severity || reactionOnset || route) && !manifestation) {
15
+ throw new Error(`${severity ? AllergyIntoleranceClaim.Severity : reactionOnset ? AllergyIntoleranceClaim.Onset : AllergyIntoleranceClaim.Route} requires ${AllergyIntoleranceClaim.Manifestation}`);
16
+ }
17
+ requireSubjectIdentifier(patient, AllergyIntoleranceClaim.Subject);
18
+ if (recorder)
19
+ requireDidWeb(recorder, AllergyIntoleranceClaim.Recorder);
20
+ return {
21
+ resourceType: 'AllergyIntolerance',
22
+ identifier: claims[AllergyIntoleranceClaim.Identifier] ? [{ value: claims[AllergyIntoleranceClaim.Identifier] }] : undefined,
23
+ patient: { reference: patient },
24
+ code: claims[AllergyIntoleranceClaim.Code]
25
+ ? {
26
+ coding: codingFromValue(claims[AllergyIntoleranceClaim.Code])?.map((coding) => ({
27
+ ...coding,
28
+ ...(claims[AllergyIntoleranceClaim.CodeDisplay]
29
+ ? { display: claims[AllergyIntoleranceClaim.CodeDisplay] }
30
+ : {}),
31
+ })),
32
+ ...(claims[AllergyIntoleranceClaim.CodeText]
33
+ ? { text: claims[AllergyIntoleranceClaim.CodeText] }
34
+ : {}),
35
+ }
36
+ : undefined,
37
+ clinicalStatus: claims[AllergyIntoleranceClaim.ClinicalStatus] ? { coding: [{ code: claims[AllergyIntoleranceClaim.ClinicalStatus] }] } : undefined,
38
+ verificationStatus: claims[AllergyIntoleranceClaim.VerificationStatus] ? { coding: [{ code: claims[AllergyIntoleranceClaim.VerificationStatus] }] } : undefined,
39
+ category: claims[AllergyIntoleranceClaim.Category] ? [claims[AllergyIntoleranceClaim.Category]] : undefined,
40
+ criticality: claims[AllergyIntoleranceClaim.Criticality],
41
+ type: claims[AllergyIntoleranceClaim.Type],
42
+ onsetDateTime: claims[AllergyIntoleranceClaim.OnsetDateTime],
43
+ recordedDate: claims[AllergyIntoleranceClaim.RecordedDate],
44
+ lastOccurrence: claims[AllergyIntoleranceClaim.LastOccurrence],
45
+ asserter: claims[AllergyIntoleranceClaim.Asserter]
46
+ ? { reference: claims[AllergyIntoleranceClaim.Asserter] }
47
+ : undefined,
48
+ recorder: recorder ? { reference: recorder } : undefined,
49
+ reaction: manifestation ? [{
50
+ manifestation: [{ coding: codingFromValue(manifestation) }],
51
+ onset: reactionOnset,
52
+ severity,
53
+ exposureRoute: route ? { coding: codingFromValue(route) } : undefined,
54
+ }] : undefined,
55
+ };
56
+ }
57
+ export function allergyIntoleranceFhirR4ToFlat(resource) {
58
+ const subject = resource.patient?.reference;
59
+ const code = resource.code;
60
+ const reaction = resource.reaction?.[0];
61
+ const manifestation = reaction?.manifestation?.[0];
62
+ const exposureRoute = reaction?.exposureRoute;
63
+ return {
64
+ [AllergyIntoleranceClaim.Identifier]: resource.identifier?.[0]?.value,
65
+ [AllergyIntoleranceClaim.Subject]: subject,
66
+ [AllergyIntoleranceClaim.Patient]: subject,
67
+ [AllergyIntoleranceClaim.Code]: codingToValue(code?.coding?.[0]) || code?.text,
68
+ [AllergyIntoleranceClaim.CodeText]: code?.text,
69
+ [AllergyIntoleranceClaim.CodeDisplay]: code?.coding?.[0]?.display,
70
+ [AllergyIntoleranceClaim.ClinicalStatus]: resource.clinicalStatus?.coding?.[0]?.code,
71
+ [AllergyIntoleranceClaim.VerificationStatus]: resource.verificationStatus?.coding?.[0]?.code,
72
+ [AllergyIntoleranceClaim.Category]: resource.category?.[0],
73
+ [AllergyIntoleranceClaim.Criticality]: resource.criticality,
74
+ [AllergyIntoleranceClaim.Type]: resource.type,
75
+ [AllergyIntoleranceClaim.OnsetDateTime]: resource.onsetDateTime,
76
+ [AllergyIntoleranceClaim.RecordedDate]: resource.recordedDate,
77
+ [AllergyIntoleranceClaim.LastOccurrence]: resource.lastOccurrence,
78
+ [AllergyIntoleranceClaim.Asserter]: resource.asserter?.reference,
79
+ [AllergyIntoleranceClaim.Manifestation]: codingToValue(manifestation?.coding?.[0]),
80
+ [AllergyIntoleranceClaim.Onset]: reaction?.onset,
81
+ [AllergyIntoleranceClaim.Route]: codingToValue(exposureRoute?.coding?.[0]),
82
+ [AllergyIntoleranceClaim.Severity]: reaction?.severity,
83
+ [AllergyIntoleranceClaim.Recorder]: resource.recorder?.reference,
84
+ };
85
+ }
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function appointmentResponseFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function appointmentResponseFhirR4ToFlat(resource: FhirResource): FlatClaims;
@@ -0,0 +1,32 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/utils/convert-appointment-response.ts
3
+ import { AppointmentResponseClaim } from '../claims/appointment-response-claims.js';
4
+ import { codingFromValue, codingToValue, referenceToValue } from './convert-shared.js';
5
+ export function appointmentResponseFlatToFhirR4(claims) {
6
+ return {
7
+ resourceType: 'AppointmentResponse',
8
+ identifier: claims[AppointmentResponseClaim.Identifier] ? [{ value: claims[AppointmentResponseClaim.Identifier] }] : undefined,
9
+ appointment: claims[AppointmentResponseClaim.Appointment] ? { reference: claims[AppointmentResponseClaim.Appointment] } : undefined,
10
+ actor: claims[AppointmentResponseClaim.Actor] ? { reference: claims[AppointmentResponseClaim.Actor] } : undefined,
11
+ participantStatus: claims[AppointmentResponseClaim.ParticipantStatus],
12
+ participantType: claims[AppointmentResponseClaim.ParticipantType] ? [{ coding: codingFromValue(claims[AppointmentResponseClaim.ParticipantType]) }] : undefined,
13
+ start: claims[AppointmentResponseClaim.Start],
14
+ end: claims[AppointmentResponseClaim.End],
15
+ comment: claims[AppointmentResponseClaim.Comment],
16
+ };
17
+ }
18
+ export function appointmentResponseFhirR4ToFlat(resource) {
19
+ return {
20
+ [AppointmentResponseClaim.Actor]: referenceToValue(resource.actor),
21
+ [AppointmentResponseClaim.Appointment]: referenceToValue(resource.appointment),
22
+ [AppointmentResponseClaim.Comment]: resource.comment,
23
+ [AppointmentResponseClaim.Identifier]: resource.identifier?.[0]?.value,
24
+ [AppointmentResponseClaim.Start]: resource.start,
25
+ [AppointmentResponseClaim.End]: resource.end,
26
+ [AppointmentResponseClaim.ParticipantType]: codingToValue(resource.participantType?.[0]?.coding?.[0]),
27
+ [AppointmentResponseClaim.ParticipantStatus]: resource.participantStatus,
28
+ [AppointmentResponseClaim.Patient]: undefined,
29
+ [AppointmentResponseClaim.Practitioner]: undefined,
30
+ [AppointmentResponseClaim.Location]: undefined,
31
+ };
32
+ }
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function appointmentFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function appointmentFhirR4ToFlat(resource: FhirResource): FlatClaims;
@@ -0,0 +1,61 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/utils/convert-appointment.ts
3
+ import { AppointmentClaim } from '../claims/appointment-claims.js';
4
+ import { codingFromValue, codingToValue, referenceListToCsv, referenceToValue } from './convert-shared.js';
5
+ export function appointmentFlatToFhirR4(claims) {
6
+ return {
7
+ resourceType: 'Appointment',
8
+ identifier: claims[AppointmentClaim.Identifier] ? [{ value: claims[AppointmentClaim.Identifier] }] : undefined,
9
+ status: claims[AppointmentClaim.Status],
10
+ serviceCategory: claims[AppointmentClaim.ServiceCategory] ? [{ coding: codingFromValue(claims[AppointmentClaim.ServiceCategory]) }] : undefined,
11
+ serviceType: claims[AppointmentClaim.ServiceType] ? [{ coding: codingFromValue(claims[AppointmentClaim.ServiceType]) }] : undefined,
12
+ specialty: claims[AppointmentClaim.Specialty] ? [{ coding: codingFromValue(claims[AppointmentClaim.Specialty]) }] : undefined,
13
+ appointmentType: claims[AppointmentClaim.AppointmentType] ? { coding: codingFromValue(claims[AppointmentClaim.AppointmentType]) } : undefined,
14
+ reasonCode: claims[AppointmentClaim.ReasonCode] ? [{ coding: codingFromValue(claims[AppointmentClaim.ReasonCode]) }] : undefined,
15
+ reasonReference: claims[AppointmentClaim.ReasonReference] ? claims[AppointmentClaim.ReasonReference].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
16
+ description: claims[AppointmentClaim.Description],
17
+ start: claims[AppointmentClaim.Start],
18
+ end: claims[AppointmentClaim.End],
19
+ minutesDuration: claims[AppointmentClaim.MinutesDuration] ? Number(claims[AppointmentClaim.MinutesDuration]) : undefined,
20
+ created: claims[AppointmentClaim.Created],
21
+ note: claims[AppointmentClaim.NoteText] ? [{ text: claims[AppointmentClaim.NoteText] }] : undefined,
22
+ patientInstruction: claims[AppointmentClaim.PatientInstruction],
23
+ basedOn: claims[AppointmentClaim.BasedOn] ? claims[AppointmentClaim.BasedOn].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
24
+ participant: claims[AppointmentClaim.ParticipantActor]
25
+ ? claims[AppointmentClaim.ParticipantActor].split(',').map((reference) => ({
26
+ actor: { reference: reference.trim() },
27
+ status: claims[AppointmentClaim.ParticipantStatus],
28
+ type: claims[AppointmentClaim.ParticipantType] ? [{ coding: codingFromValue(claims[AppointmentClaim.ParticipantType]) }] : undefined,
29
+ }))
30
+ : undefined,
31
+ };
32
+ }
33
+ export function appointmentFhirR4ToFlat(resource) {
34
+ const participant = Array.isArray(resource.participant) ? resource.participant[0] : undefined;
35
+ return {
36
+ [AppointmentClaim.Identifier]: resource.identifier?.[0]?.value,
37
+ [AppointmentClaim.Status]: resource.status,
38
+ [AppointmentClaim.ServiceCategory]: codingToValue(resource.serviceCategory?.[0]?.coding?.[0]),
39
+ [AppointmentClaim.ServiceType]: codingToValue(resource.serviceType?.[0]?.coding?.[0]),
40
+ [AppointmentClaim.Specialty]: codingToValue(resource.specialty?.[0]?.coding?.[0]),
41
+ [AppointmentClaim.AppointmentType]: codingToValue(resource.appointmentType?.coding?.[0]),
42
+ [AppointmentClaim.ReasonCode]: codingToValue(resource.reasonCode?.[0]?.coding?.[0]),
43
+ [AppointmentClaim.ReasonReference]: referenceListToCsv(resource.reasonReference),
44
+ [AppointmentClaim.Description]: resource.description,
45
+ [AppointmentClaim.Start]: resource.start,
46
+ [AppointmentClaim.End]: resource.end,
47
+ [AppointmentClaim.MinutesDuration]: resource.minutesDuration === undefined ? undefined : String(resource.minutesDuration),
48
+ [AppointmentClaim.Created]: resource.created,
49
+ [AppointmentClaim.NoteText]: resource.note?.[0]?.text,
50
+ [AppointmentClaim.PatientInstruction]: resource.patientInstruction,
51
+ [AppointmentClaim.BasedOn]: referenceListToCsv(resource.basedOn),
52
+ [AppointmentClaim.ParticipantActor]: Array.isArray(resource.participant)
53
+ ? resource.participant
54
+ .map((item) => referenceToValue(item?.actor))
55
+ .filter((item) => Boolean(item))
56
+ .join(',')
57
+ : undefined,
58
+ [AppointmentClaim.ParticipantStatus]: participant?.status,
59
+ [AppointmentClaim.ParticipantType]: codingToValue(participant?.type?.[0]?.coding?.[0]),
60
+ };
61
+ }
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function carePlanFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function carePlanFhirR4ToFlat(resource: FhirResource): FlatClaims;
@@ -0,0 +1,93 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/utils/convert-care-plan.ts
3
+ import { CarePlanClaim } from '../claims/care-plan-claims.js';
4
+ import { codingFromValue, codingToValue, referenceListToCsv, referenceToValue } from './convert-shared.js';
5
+ export function carePlanFlatToFhirR4(claims) {
6
+ const subject = claims[CarePlanClaim.Subject] ?? claims[CarePlanClaim.Patient];
7
+ const categoryCoding = codingFromValue(claims[CarePlanClaim.Category])?.map((coding) => ({
8
+ ...coding,
9
+ ...(claims[CarePlanClaim.CategoryDisplay] ? { display: claims[CarePlanClaim.CategoryDisplay] } : {}),
10
+ }));
11
+ return {
12
+ resourceType: 'CarePlan',
13
+ identifier: claims[CarePlanClaim.Identifier] ? [{ value: claims[CarePlanClaim.Identifier] }] : undefined,
14
+ status: claims[CarePlanClaim.Status],
15
+ intent: claims[CarePlanClaim.Intent],
16
+ subject: subject ? { reference: subject } : undefined,
17
+ category: claims[CarePlanClaim.Category] || claims[CarePlanClaim.CategoryText] || claims[CarePlanClaim.CategoryDisplay]
18
+ ? [{
19
+ ...(categoryCoding ? { coding: categoryCoding } : {}),
20
+ ...(claims[CarePlanClaim.CategoryText] ? { text: claims[CarePlanClaim.CategoryText] } : {}),
21
+ }]
22
+ : undefined,
23
+ created: claims[CarePlanClaim.Date],
24
+ description: claims[CarePlanClaim.Description],
25
+ period: claims[CarePlanClaim.PeriodStart] || claims[CarePlanClaim.PeriodEnd] ? { start: claims[CarePlanClaim.PeriodStart], end: claims[CarePlanClaim.PeriodEnd] } : undefined,
26
+ note: claims[CarePlanClaim.Note] ? [{ text: claims[CarePlanClaim.Note] }] : undefined,
27
+ basedOn: claims[CarePlanClaim.BasedOn] ? claims[CarePlanClaim.BasedOn].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
28
+ careTeam: claims[CarePlanClaim.CareTeam] ? claims[CarePlanClaim.CareTeam].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
29
+ addresses: claims[CarePlanClaim.Condition] ? claims[CarePlanClaim.Condition].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
30
+ encounter: claims[CarePlanClaim.Encounter] ? { reference: claims[CarePlanClaim.Encounter] } : undefined,
31
+ goal: claims[CarePlanClaim.Goal] ? claims[CarePlanClaim.Goal].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
32
+ partOf: claims[CarePlanClaim.PartOf] ? claims[CarePlanClaim.PartOf].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
33
+ replaces: claims[CarePlanClaim.Replaces] ? claims[CarePlanClaim.Replaces].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
34
+ activity: (claims[CarePlanClaim.ActivityCode] || claims[CarePlanClaim.ActivityDate] || claims[CarePlanClaim.ActivityReference] || claims[CarePlanClaim.Performer] || claims[CarePlanClaim.ActivityStatus]) ? [{
35
+ outcomeCodeableConcept: claims[CarePlanClaim.ActivityOutcome] ? [{ coding: codingFromValue(claims[CarePlanClaim.ActivityOutcome]) }] : undefined,
36
+ reference: claims[CarePlanClaim.ActivityReference] ? { reference: claims[CarePlanClaim.ActivityReference] } : undefined,
37
+ detail: {
38
+ code: claims[CarePlanClaim.ActivityCode] ? { coding: codingFromValue(claims[CarePlanClaim.ActivityCode]) } : undefined,
39
+ scheduledString: claims[CarePlanClaim.ActivityDate],
40
+ performer: claims[CarePlanClaim.Performer] ? claims[CarePlanClaim.Performer].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
41
+ status: claims[CarePlanClaim.ActivityStatus],
42
+ statusReason: claims[CarePlanClaim.ActivityStatusReason] ? { text: claims[CarePlanClaim.ActivityStatusReason] } : undefined,
43
+ doNotPerform: claims[CarePlanClaim.ActivityDoNotPerform] === undefined ? undefined : claims[CarePlanClaim.ActivityDoNotPerform] === 'true',
44
+ scheduledTiming: claims[CarePlanClaim.ActivityTimingFrequency] || claims[CarePlanClaim.ActivityTimingPeriod] ? { repeat: {
45
+ frequency: claims[CarePlanClaim.ActivityTimingFrequency] ? Number(claims[CarePlanClaim.ActivityTimingFrequency]) : undefined,
46
+ period: claims[CarePlanClaim.ActivityTimingPeriod] ? Number(claims[CarePlanClaim.ActivityTimingPeriod]) : undefined,
47
+ periodUnit: claims[CarePlanClaim.ActivityTimingPeriodUnit],
48
+ } } : undefined,
49
+ location: claims[CarePlanClaim.ActivityLocationDisplay] ? { display: claims[CarePlanClaim.ActivityLocationDisplay] } : undefined,
50
+ },
51
+ }] : undefined,
52
+ };
53
+ }
54
+ export function carePlanFhirR4ToFlat(resource) {
55
+ const activity = Array.isArray(resource.activity) ? resource.activity[0] : undefined;
56
+ const detail = activity?.detail;
57
+ const period = resource.period;
58
+ const repeat = detail?.scheduledTiming?.repeat;
59
+ return {
60
+ [CarePlanClaim.ActivityCode]: codingToValue(detail?.code?.coding?.[0]),
61
+ [CarePlanClaim.ActivityDate]: detail?.scheduledString,
62
+ [CarePlanClaim.ActivityReference]: referenceToValue(activity?.reference),
63
+ [CarePlanClaim.BasedOn]: referenceListToCsv(resource.basedOn),
64
+ [CarePlanClaim.CareTeam]: referenceListToCsv(resource.careTeam),
65
+ [CarePlanClaim.Category]: codingToValue(resource.category?.[0]?.coding?.[0]),
66
+ [CarePlanClaim.CategoryText]: resource.category?.[0]?.text,
67
+ [CarePlanClaim.CategoryDisplay]: resource.category?.[0]?.coding?.[0]?.display,
68
+ [CarePlanClaim.Condition]: referenceListToCsv(resource.addresses),
69
+ [CarePlanClaim.Date]: resource.created || period?.start,
70
+ [CarePlanClaim.Encounter]: referenceToValue(resource.encounter),
71
+ [CarePlanClaim.Goal]: referenceListToCsv(resource.goal),
72
+ [CarePlanClaim.Identifier]: resource.identifier?.[0]?.value,
73
+ [CarePlanClaim.Intent]: resource.intent,
74
+ [CarePlanClaim.PartOf]: referenceListToCsv(resource.partOf),
75
+ [CarePlanClaim.Patient]: referenceToValue(resource.subject),
76
+ [CarePlanClaim.Performer]: referenceListToCsv(detail?.performer),
77
+ [CarePlanClaim.Replaces]: referenceListToCsv(resource.replaces),
78
+ [CarePlanClaim.Status]: resource.status,
79
+ [CarePlanClaim.Subject]: referenceToValue(resource.subject),
80
+ [CarePlanClaim.Note]: resource.note?.[0]?.text,
81
+ [CarePlanClaim.Description]: resource.description,
82
+ [CarePlanClaim.PeriodStart]: period?.start,
83
+ [CarePlanClaim.PeriodEnd]: period?.end,
84
+ [CarePlanClaim.ActivityStatus]: detail?.status,
85
+ [CarePlanClaim.ActivityStatusReason]: detail?.statusReason?.text,
86
+ [CarePlanClaim.ActivityDoNotPerform]: detail?.doNotPerform === undefined ? undefined : String(detail.doNotPerform),
87
+ [CarePlanClaim.ActivityOutcome]: codingToValue(activity?.outcomeCodeableConcept?.[0]?.coding?.[0]),
88
+ [CarePlanClaim.ActivityLocationDisplay]: detail?.location?.display,
89
+ [CarePlanClaim.ActivityTimingFrequency]: repeat?.frequency === undefined ? undefined : String(repeat.frequency),
90
+ [CarePlanClaim.ActivityTimingPeriod]: repeat?.period === undefined ? undefined : String(repeat.period),
91
+ [CarePlanClaim.ActivityTimingPeriodUnit]: repeat?.periodUnit,
92
+ };
93
+ }
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function clinicalImpressionFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function clinicalImpressionFhirR4ToFlat(resource: FhirResource): FlatClaims;
@@ -0,0 +1,42 @@
1
+ // Copyright 2026 Conéctate Soluciones y Aplicaciones SL under the Apache License, Version 2.0.
2
+ // File: src/utils/convert-clinical-impression.ts
3
+ import { ClinicalImpressionClaim } from '../claims/clinical-impression-claims.js';
4
+ import { codingFromValue, codingToValue, referenceListToCsv, referenceToValue } from './convert-shared.js';
5
+ export function clinicalImpressionFlatToFhirR4(claims) {
6
+ return {
7
+ resourceType: 'ClinicalImpression',
8
+ identifier: claims[ClinicalImpressionClaim.Identifier] ? [{ value: claims[ClinicalImpressionClaim.Identifier] }] : undefined,
9
+ status: claims[ClinicalImpressionClaim.Status],
10
+ description: claims[ClinicalImpressionClaim.Description],
11
+ subject: claims[ClinicalImpressionClaim.Subject] ? { reference: claims[ClinicalImpressionClaim.Subject] } : undefined,
12
+ encounter: claims[ClinicalImpressionClaim.Encounter] ? { reference: claims[ClinicalImpressionClaim.Encounter] } : undefined,
13
+ effectiveDateTime: claims[ClinicalImpressionClaim.EffectiveDateTime],
14
+ date: claims[ClinicalImpressionClaim.Date],
15
+ assessor: claims[ClinicalImpressionClaim.Assessor] ? { reference: claims[ClinicalImpressionClaim.Assessor] } : undefined,
16
+ problem: claims[ClinicalImpressionClaim.Problem] ? claims[ClinicalImpressionClaim.Problem].split(',').map((reference) => ({ reference: reference.trim() })) : undefined,
17
+ finding: claims[ClinicalImpressionClaim.Finding] ? claims[ClinicalImpressionClaim.Finding].split(',').map((reference) => ({ itemReference: { reference: reference.trim() } })) : undefined,
18
+ prognosisCodeableConcept: claims[ClinicalImpressionClaim.PrognosisCode] ? [{ coding: codingFromValue(claims[ClinicalImpressionClaim.PrognosisCode]) }] : undefined,
19
+ summary: claims[ClinicalImpressionClaim.Summary],
20
+ };
21
+ }
22
+ export function clinicalImpressionFhirR4ToFlat(resource) {
23
+ return {
24
+ [ClinicalImpressionClaim.Identifier]: resource.identifier?.[0]?.value,
25
+ [ClinicalImpressionClaim.Status]: resource.status,
26
+ [ClinicalImpressionClaim.Description]: resource.description,
27
+ [ClinicalImpressionClaim.Subject]: referenceToValue(resource.subject),
28
+ [ClinicalImpressionClaim.Encounter]: referenceToValue(resource.encounter),
29
+ [ClinicalImpressionClaim.EffectiveDateTime]: resource.effectiveDateTime,
30
+ [ClinicalImpressionClaim.Date]: resource.date,
31
+ [ClinicalImpressionClaim.Assessor]: referenceToValue(resource.assessor),
32
+ [ClinicalImpressionClaim.Problem]: referenceListToCsv(resource.problem),
33
+ [ClinicalImpressionClaim.Finding]: Array.isArray(resource.finding)
34
+ ? resource.finding
35
+ .map((item) => referenceToValue(item?.itemReference))
36
+ .filter((item) => Boolean(item))
37
+ .join(',')
38
+ : undefined,
39
+ [ClinicalImpressionClaim.PrognosisCode]: codingToValue(resource.prognosisCodeableConcept?.[0]?.coding?.[0]),
40
+ [ClinicalImpressionClaim.Summary]: resource.summary,
41
+ };
42
+ }
@@ -0,0 +1,3 @@
1
+ import type { FhirResource, FlatClaims } from './convert-shared.js';
2
+ export declare function compositionFlatToFhirR4(claims: FlatClaims): FhirResource;
3
+ export declare function compositionFhirR4ToFlat(resource: FhirResource): FlatClaims;