@medplum/core 0.2.1 → 0.4.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 (660) hide show
  1. package/README.md +32 -26
  2. package/dist/cjs/index.js +1818 -0
  3. package/dist/cjs/index.js.map +1 -0
  4. package/dist/cjs/index.min.js +16 -0
  5. package/dist/cjs/index.min.js.map +1 -0
  6. package/dist/esm/index.js +1769 -0
  7. package/dist/esm/index.js.map +1 -0
  8. package/dist/esm/index.min.js +16 -0
  9. package/dist/esm/index.min.js.map +1 -0
  10. package/dist/{cache.d.ts → types/cache.d.ts} +2 -3
  11. package/dist/types/client.d.ts +230 -0
  12. package/dist/{crypto.d.ts → types/crypto.d.ts} +0 -0
  13. package/dist/{eventtarget.d.ts → types/eventtarget.d.ts} +3 -3
  14. package/dist/{format.d.ts → types/format.d.ts} +1 -1
  15. package/dist/{index.d.ts → types/index.d.ts} +0 -2
  16. package/dist/types/jwt.d.ts +5 -0
  17. package/dist/{outcomes.d.ts → types/outcomes.d.ts} +7 -2
  18. package/dist/{search.d.ts → types/search.d.ts} +4 -0
  19. package/dist/{searchparams.d.ts → types/searchparams.d.ts} +1 -1
  20. package/dist/{storage.d.ts → types/storage.d.ts} +2 -2
  21. package/dist/{types.d.ts → types/types.d.ts} +18 -4
  22. package/dist/{utils.d.ts → types/utils.d.ts} +7 -1
  23. package/package.json +14 -9
  24. package/dist/cache.js +0 -36
  25. package/dist/cache.js.map +0 -1
  26. package/dist/client.d.ts +0 -233
  27. package/dist/client.js +0 -541
  28. package/dist/client.js.map +0 -1
  29. package/dist/crypto.js +0 -33
  30. package/dist/crypto.js.map +0 -1
  31. package/dist/eventtarget.js +0 -38
  32. package/dist/eventtarget.js.map +0 -1
  33. package/dist/fhir/AccessPolicy.d.ts +0 -75
  34. package/dist/fhir/AccessPolicy.js +0 -7
  35. package/dist/fhir/AccessPolicy.js.map +0 -1
  36. package/dist/fhir/Account.d.ts +0 -247
  37. package/dist/fhir/Account.js +0 -7
  38. package/dist/fhir/Account.js.map +0 -1
  39. package/dist/fhir/ActivityDefinition.d.ts +0 -500
  40. package/dist/fhir/ActivityDefinition.js +0 -7
  41. package/dist/fhir/ActivityDefinition.js.map +0 -1
  42. package/dist/fhir/Address.d.ts +0 -75
  43. package/dist/fhir/Address.js +0 -7
  44. package/dist/fhir/Address.js.map +0 -1
  45. package/dist/fhir/AdverseEvent.d.ts +0 -303
  46. package/dist/fhir/AdverseEvent.js +0 -7
  47. package/dist/fhir/AdverseEvent.js.map +0 -1
  48. package/dist/fhir/Age.d.ts +0 -47
  49. package/dist/fhir/Age.js +0 -7
  50. package/dist/fhir/Age.js.map +0 -1
  51. package/dist/fhir/AllergyIntolerance.d.ts +0 -283
  52. package/dist/fhir/AllergyIntolerance.js +0 -7
  53. package/dist/fhir/AllergyIntolerance.js.map +0 -1
  54. package/dist/fhir/Annotation.d.ts +0 -42
  55. package/dist/fhir/Annotation.js +0 -7
  56. package/dist/fhir/Annotation.js.map +0 -1
  57. package/dist/fhir/Appointment.d.ts +0 -284
  58. package/dist/fhir/Appointment.js +0 -7
  59. package/dist/fhir/Appointment.js.map +0 -1
  60. package/dist/fhir/AppointmentResponse.d.ts +0 -131
  61. package/dist/fhir/AppointmentResponse.js +0 -7
  62. package/dist/fhir/AppointmentResponse.js.map +0 -1
  63. package/dist/fhir/Attachment.d.ts +0 -58
  64. package/dist/fhir/Attachment.js +0 -7
  65. package/dist/fhir/Attachment.js.map +0 -1
  66. package/dist/fhir/AuditEvent.d.ts +0 -458
  67. package/dist/fhir/AuditEvent.js +0 -7
  68. package/dist/fhir/AuditEvent.js.map +0 -1
  69. package/dist/fhir/Basic.d.ts +0 -110
  70. package/dist/fhir/Basic.js +0 -7
  71. package/dist/fhir/Basic.js.map +0 -1
  72. package/dist/fhir/Binary.d.ts +0 -59
  73. package/dist/fhir/Binary.js +0 -7
  74. package/dist/fhir/Binary.js.map +0 -1
  75. package/dist/fhir/BiologicallyDerivedProduct.d.ts +0 -358
  76. package/dist/fhir/BiologicallyDerivedProduct.js +0 -7
  77. package/dist/fhir/BiologicallyDerivedProduct.js.map +0 -1
  78. package/dist/fhir/BodyStructure.d.ts +0 -119
  79. package/dist/fhir/BodyStructure.js +0 -7
  80. package/dist/fhir/BodyStructure.js.map +0 -1
  81. package/dist/fhir/Bot.d.ts +0 -49
  82. package/dist/fhir/Bot.js +0 -7
  83. package/dist/fhir/Bot.js.map +0 -1
  84. package/dist/fhir/Bundle.d.ts +0 -379
  85. package/dist/fhir/Bundle.js +0 -7
  86. package/dist/fhir/Bundle.js.map +0 -1
  87. package/dist/fhir/CapabilityStatement.d.ts +0 -1044
  88. package/dist/fhir/CapabilityStatement.js +0 -7
  89. package/dist/fhir/CapabilityStatement.js.map +0 -1
  90. package/dist/fhir/CarePlan.d.ts +0 -446
  91. package/dist/fhir/CarePlan.js +0 -7
  92. package/dist/fhir/CarePlan.js.map +0 -1
  93. package/dist/fhir/CareTeam.d.ts +0 -211
  94. package/dist/fhir/CareTeam.js +0 -7
  95. package/dist/fhir/CareTeam.js.map +0 -1
  96. package/dist/fhir/CatalogEntry.d.ts +0 -195
  97. package/dist/fhir/CatalogEntry.js +0 -7
  98. package/dist/fhir/CatalogEntry.js.map +0 -1
  99. package/dist/fhir/ChargeItem.d.ts +0 -287
  100. package/dist/fhir/ChargeItem.js +0 -7
  101. package/dist/fhir/ChargeItem.js.map +0 -1
  102. package/dist/fhir/ChargeItemDefinition.d.ts +0 -401
  103. package/dist/fhir/ChargeItemDefinition.js +0 -7
  104. package/dist/fhir/ChargeItemDefinition.js.map +0 -1
  105. package/dist/fhir/Claim.d.ts +0 -1092
  106. package/dist/fhir/Claim.js +0 -7
  107. package/dist/fhir/Claim.js.map +0 -1
  108. package/dist/fhir/ClaimResponse.d.ts +0 -1040
  109. package/dist/fhir/ClaimResponse.js +0 -7
  110. package/dist/fhir/ClaimResponse.js.map +0 -1
  111. package/dist/fhir/ClientApplication.d.ts +0 -46
  112. package/dist/fhir/ClientApplication.js +0 -7
  113. package/dist/fhir/ClientApplication.js.map +0 -1
  114. package/dist/fhir/ClinicalImpression.d.ts +0 -306
  115. package/dist/fhir/ClinicalImpression.js +0 -7
  116. package/dist/fhir/ClinicalImpression.js.map +0 -1
  117. package/dist/fhir/CodeSystem.d.ts +0 -541
  118. package/dist/fhir/CodeSystem.js +0 -7
  119. package/dist/fhir/CodeSystem.js.map +0 -1
  120. package/dist/fhir/CodeableConcept.d.ts +0 -33
  121. package/dist/fhir/CodeableConcept.js +0 -7
  122. package/dist/fhir/CodeableConcept.js.map +0 -1
  123. package/dist/fhir/Coding.d.ts +0 -50
  124. package/dist/fhir/Coding.js +0 -7
  125. package/dist/fhir/Coding.js.map +0 -1
  126. package/dist/fhir/Communication.d.ts +0 -264
  127. package/dist/fhir/Communication.js +0 -7
  128. package/dist/fhir/Communication.js.map +0 -1
  129. package/dist/fhir/CommunicationRequest.d.ts +0 -261
  130. package/dist/fhir/CommunicationRequest.js +0 -7
  131. package/dist/fhir/CommunicationRequest.js.map +0 -1
  132. package/dist/fhir/CompartmentDefinition.d.ts +0 -217
  133. package/dist/fhir/CompartmentDefinition.js +0 -7
  134. package/dist/fhir/CompartmentDefinition.js.map +0 -1
  135. package/dist/fhir/Composition.d.ts +0 -429
  136. package/dist/fhir/Composition.js +0 -7
  137. package/dist/fhir/Composition.js.map +0 -1
  138. package/dist/fhir/ConceptMap.d.ts +0 -518
  139. package/dist/fhir/ConceptMap.js +0 -7
  140. package/dist/fhir/ConceptMap.js.map +0 -1
  141. package/dist/fhir/Condition.d.ts +0 -326
  142. package/dist/fhir/Condition.js +0 -7
  143. package/dist/fhir/Condition.js.map +0 -1
  144. package/dist/fhir/Consent.d.ts +0 -460
  145. package/dist/fhir/Consent.js +0 -7
  146. package/dist/fhir/Consent.js.map +0 -1
  147. package/dist/fhir/ContactDetail.d.ts +0 -31
  148. package/dist/fhir/ContactDetail.js +0 -7
  149. package/dist/fhir/ContactDetail.js.map +0 -1
  150. package/dist/fhir/ContactPoint.d.ts +0 -47
  151. package/dist/fhir/ContactPoint.js +0 -7
  152. package/dist/fhir/ContactPoint.js.map +0 -1
  153. package/dist/fhir/Contract.d.ts +0 -1452
  154. package/dist/fhir/Contract.js +0 -7
  155. package/dist/fhir/Contract.js.map +0 -1
  156. package/dist/fhir/Contributor.d.ts +0 -37
  157. package/dist/fhir/Contributor.js +0 -7
  158. package/dist/fhir/Contributor.js.map +0 -1
  159. package/dist/fhir/Count.d.ts +0 -49
  160. package/dist/fhir/Count.js +0 -7
  161. package/dist/fhir/Count.js.map +0 -1
  162. package/dist/fhir/Coverage.d.ts +0 -327
  163. package/dist/fhir/Coverage.js +0 -7
  164. package/dist/fhir/Coverage.js.map +0 -1
  165. package/dist/fhir/CoverageEligibilityRequest.d.ts +0 -404
  166. package/dist/fhir/CoverageEligibilityRequest.js +0 -7
  167. package/dist/fhir/CoverageEligibilityRequest.js.map +0 -1
  168. package/dist/fhir/CoverageEligibilityResponse.d.ts +0 -434
  169. package/dist/fhir/CoverageEligibilityResponse.js +0 -7
  170. package/dist/fhir/CoverageEligibilityResponse.js.map +0 -1
  171. package/dist/fhir/DataRequirement.d.ts +0 -239
  172. package/dist/fhir/DataRequirement.js +0 -7
  173. package/dist/fhir/DataRequirement.js.map +0 -1
  174. package/dist/fhir/DetectedIssue.d.ts +0 -252
  175. package/dist/fhir/DetectedIssue.js +0 -7
  176. package/dist/fhir/DetectedIssue.js.map +0 -1
  177. package/dist/fhir/Device.d.ts +0 -493
  178. package/dist/fhir/Device.js +0 -7
  179. package/dist/fhir/Device.js.map +0 -1
  180. package/dist/fhir/DeviceDefinition.d.ts +0 -486
  181. package/dist/fhir/DeviceDefinition.js +0 -7
  182. package/dist/fhir/DeviceDefinition.js.map +0 -1
  183. package/dist/fhir/DeviceMetric.d.ts +0 -199
  184. package/dist/fhir/DeviceMetric.js +0 -7
  185. package/dist/fhir/DeviceMetric.js.map +0 -1
  186. package/dist/fhir/DeviceRequest.d.ts +0 -296
  187. package/dist/fhir/DeviceRequest.js +0 -7
  188. package/dist/fhir/DeviceRequest.js.map +0 -1
  189. package/dist/fhir/DeviceUseStatement.d.ts +0 -168
  190. package/dist/fhir/DeviceUseStatement.js +0 -7
  191. package/dist/fhir/DeviceUseStatement.js.map +0 -1
  192. package/dist/fhir/DiagnosticReport.d.ts +0 -254
  193. package/dist/fhir/DiagnosticReport.js +0 -7
  194. package/dist/fhir/DiagnosticReport.js.map +0 -1
  195. package/dist/fhir/Distance.d.ts +0 -47
  196. package/dist/fhir/Distance.js +0 -7
  197. package/dist/fhir/Distance.js.map +0 -1
  198. package/dist/fhir/DocumentManifest.d.ts +0 -196
  199. package/dist/fhir/DocumentManifest.js +0 -7
  200. package/dist/fhir/DocumentManifest.js.map +0 -1
  201. package/dist/fhir/DocumentReference.d.ts +0 -349
  202. package/dist/fhir/DocumentReference.js +0 -7
  203. package/dist/fhir/DocumentReference.js.map +0 -1
  204. package/dist/fhir/Dosage.d.ts +0 -152
  205. package/dist/fhir/Dosage.js +0 -7
  206. package/dist/fhir/Dosage.js.map +0 -1
  207. package/dist/fhir/Duration.d.ts +0 -46
  208. package/dist/fhir/Duration.js +0 -7
  209. package/dist/fhir/Duration.js.map +0 -1
  210. package/dist/fhir/EffectEvidenceSynthesis.d.ts +0 -591
  211. package/dist/fhir/EffectEvidenceSynthesis.js +0 -7
  212. package/dist/fhir/EffectEvidenceSynthesis.js.map +0 -1
  213. package/dist/fhir/Element.d.ts +0 -21
  214. package/dist/fhir/Element.js +0 -7
  215. package/dist/fhir/Element.js.map +0 -1
  216. package/dist/fhir/ElementDefinition.d.ts +0 -2701
  217. package/dist/fhir/ElementDefinition.js +0 -7
  218. package/dist/fhir/ElementDefinition.js.map +0 -1
  219. package/dist/fhir/Encounter.d.ts +0 -558
  220. package/dist/fhir/Encounter.js +0 -7
  221. package/dist/fhir/Encounter.js.map +0 -1
  222. package/dist/fhir/Endpoint.d.ts +0 -140
  223. package/dist/fhir/Endpoint.js +0 -7
  224. package/dist/fhir/Endpoint.js.map +0 -1
  225. package/dist/fhir/EnrollmentRequest.d.ts +0 -113
  226. package/dist/fhir/EnrollmentRequest.js +0 -7
  227. package/dist/fhir/EnrollmentRequest.js.map +0 -1
  228. package/dist/fhir/EnrollmentResponse.d.ts +0 -117
  229. package/dist/fhir/EnrollmentResponse.js +0 -7
  230. package/dist/fhir/EnrollmentResponse.js.map +0 -1
  231. package/dist/fhir/EpisodeOfCare.d.ts +0 -246
  232. package/dist/fhir/EpisodeOfCare.js +0 -7
  233. package/dist/fhir/EpisodeOfCare.js.map +0 -1
  234. package/dist/fhir/EventDefinition.d.ts +0 -253
  235. package/dist/fhir/EventDefinition.js +0 -7
  236. package/dist/fhir/EventDefinition.js.map +0 -1
  237. package/dist/fhir/Evidence.d.ts +0 -252
  238. package/dist/fhir/Evidence.js +0 -7
  239. package/dist/fhir/Evidence.js.map +0 -1
  240. package/dist/fhir/EvidenceVariable.d.ts +0 -370
  241. package/dist/fhir/EvidenceVariable.js +0 -7
  242. package/dist/fhir/EvidenceVariable.js.map +0 -1
  243. package/dist/fhir/ExampleScenario.d.ts +0 -628
  244. package/dist/fhir/ExampleScenario.js +0 -7
  245. package/dist/fhir/ExampleScenario.js.map +0 -1
  246. package/dist/fhir/ExplanationOfBenefit.d.ts +0 -1841
  247. package/dist/fhir/ExplanationOfBenefit.js +0 -7
  248. package/dist/fhir/ExplanationOfBenefit.js.map +0 -1
  249. package/dist/fhir/Expression.d.ts +0 -45
  250. package/dist/fhir/Expression.js +0 -7
  251. package/dist/fhir/Expression.js.map +0 -1
  252. package/dist/fhir/Extension.d.ts +0 -306
  253. package/dist/fhir/Extension.js +0 -7
  254. package/dist/fhir/Extension.js.map +0 -1
  255. package/dist/fhir/FamilyMemberHistory.d.ts +0 -306
  256. package/dist/fhir/FamilyMemberHistory.js +0 -7
  257. package/dist/fhir/FamilyMemberHistory.js.map +0 -1
  258. package/dist/fhir/Flag.d.ts +0 -132
  259. package/dist/fhir/Flag.js +0 -7
  260. package/dist/fhir/Flag.js.map +0 -1
  261. package/dist/fhir/Goal.d.ts +0 -299
  262. package/dist/fhir/Goal.js +0 -7
  263. package/dist/fhir/Goal.js.map +0 -1
  264. package/dist/fhir/GraphDefinition.d.ts +0 -350
  265. package/dist/fhir/GraphDefinition.js +0 -7
  266. package/dist/fhir/GraphDefinition.js.map +0 -1
  267. package/dist/fhir/Group.d.ts +0 -271
  268. package/dist/fhir/Group.js +0 -7
  269. package/dist/fhir/Group.js.map +0 -1
  270. package/dist/fhir/GuidanceResponse.d.ts +0 -196
  271. package/dist/fhir/GuidanceResponse.js +0 -7
  272. package/dist/fhir/GuidanceResponse.js.map +0 -1
  273. package/dist/fhir/HealthcareService.d.ts +0 -356
  274. package/dist/fhir/HealthcareService.js +0 -7
  275. package/dist/fhir/HealthcareService.js.map +0 -1
  276. package/dist/fhir/HumanName.d.ts +0 -58
  277. package/dist/fhir/HumanName.js +0 -7
  278. package/dist/fhir/HumanName.js.map +0 -1
  279. package/dist/fhir/Identifier.d.ts +0 -53
  280. package/dist/fhir/Identifier.js +0 -7
  281. package/dist/fhir/Identifier.js.map +0 -1
  282. package/dist/fhir/ImagingStudy.d.ts +0 -407
  283. package/dist/fhir/ImagingStudy.js +0 -7
  284. package/dist/fhir/ImagingStudy.js.map +0 -1
  285. package/dist/fhir/Immunization.d.ts +0 -444
  286. package/dist/fhir/Immunization.js +0 -7
  287. package/dist/fhir/Immunization.js.map +0 -1
  288. package/dist/fhir/ImmunizationEvaluation.d.ts +0 -149
  289. package/dist/fhir/ImmunizationEvaluation.js +0 -7
  290. package/dist/fhir/ImmunizationEvaluation.js.map +0 -1
  291. package/dist/fhir/ImmunizationRecommendation.d.ts +0 -254
  292. package/dist/fhir/ImmunizationRecommendation.js +0 -7
  293. package/dist/fhir/ImmunizationRecommendation.js.map +0 -1
  294. package/dist/fhir/ImplementationGuide.d.ts +0 -824
  295. package/dist/fhir/ImplementationGuide.js +0 -7
  296. package/dist/fhir/ImplementationGuide.js.map +0 -1
  297. package/dist/fhir/InsurancePlan.d.ts +0 -624
  298. package/dist/fhir/InsurancePlan.js +0 -7
  299. package/dist/fhir/InsurancePlan.js.map +0 -1
  300. package/dist/fhir/Invoice.d.ts +0 -346
  301. package/dist/fhir/Invoice.js +0 -7
  302. package/dist/fhir/Invoice.js.map +0 -1
  303. package/dist/fhir/JsonWebKey.d.ts +0 -99
  304. package/dist/fhir/JsonWebKey.js +0 -7
  305. package/dist/fhir/JsonWebKey.js.map +0 -1
  306. package/dist/fhir/Library.d.ts +0 -277
  307. package/dist/fhir/Library.js +0 -7
  308. package/dist/fhir/Library.js.map +0 -1
  309. package/dist/fhir/Linkage.d.ts +0 -146
  310. package/dist/fhir/Linkage.js +0 -7
  311. package/dist/fhir/Linkage.js.map +0 -1
  312. package/dist/fhir/List.d.ts +0 -200
  313. package/dist/fhir/List.js +0 -7
  314. package/dist/fhir/List.js.map +0 -1
  315. package/dist/fhir/Location.d.ts +0 -277
  316. package/dist/fhir/Location.js +0 -7
  317. package/dist/fhir/Location.js.map +0 -1
  318. package/dist/fhir/Login.d.ts +0 -119
  319. package/dist/fhir/Login.js +0 -7
  320. package/dist/fhir/Login.js.map +0 -1
  321. package/dist/fhir/MarketingStatus.d.ts +0 -82
  322. package/dist/fhir/MarketingStatus.js +0 -7
  323. package/dist/fhir/MarketingStatus.js.map +0 -1
  324. package/dist/fhir/Measure.d.ts +0 -620
  325. package/dist/fhir/Measure.js +0 -7
  326. package/dist/fhir/Measure.js.map +0 -1
  327. package/dist/fhir/MeasureReport.d.ts +0 -463
  328. package/dist/fhir/MeasureReport.js +0 -7
  329. package/dist/fhir/MeasureReport.js.map +0 -1
  330. package/dist/fhir/Media.d.ts +0 -205
  331. package/dist/fhir/Media.js +0 -7
  332. package/dist/fhir/Media.js.map +0 -1
  333. package/dist/fhir/Medication.d.ts +0 -230
  334. package/dist/fhir/Medication.js +0 -7
  335. package/dist/fhir/Medication.js.map +0 -1
  336. package/dist/fhir/MedicationAdministration.d.ts +0 -352
  337. package/dist/fhir/MedicationAdministration.js +0 -7
  338. package/dist/fhir/MedicationAdministration.js.map +0 -1
  339. package/dist/fhir/MedicationDispense.d.ts +0 -343
  340. package/dist/fhir/MedicationDispense.js +0 -7
  341. package/dist/fhir/MedicationDispense.js.map +0 -1
  342. package/dist/fhir/MedicationKnowledge.d.ts +0 -992
  343. package/dist/fhir/MedicationKnowledge.js +0 -7
  344. package/dist/fhir/MedicationKnowledge.js.map +0 -1
  345. package/dist/fhir/MedicationRequest.d.ts +0 -481
  346. package/dist/fhir/MedicationRequest.js +0 -7
  347. package/dist/fhir/MedicationRequest.js.map +0 -1
  348. package/dist/fhir/MedicationStatement.d.ts +0 -228
  349. package/dist/fhir/MedicationStatement.js +0 -7
  350. package/dist/fhir/MedicationStatement.js.map +0 -1
  351. package/dist/fhir/MedicinalProduct.d.ts +0 -453
  352. package/dist/fhir/MedicinalProduct.js +0 -7
  353. package/dist/fhir/MedicinalProduct.js.map +0 -1
  354. package/dist/fhir/MedicinalProductAuthorization.d.ts +0 -271
  355. package/dist/fhir/MedicinalProductAuthorization.js +0 -7
  356. package/dist/fhir/MedicinalProductAuthorization.js.map +0 -1
  357. package/dist/fhir/MedicinalProductContraindication.d.ts +0 -170
  358. package/dist/fhir/MedicinalProductContraindication.js +0 -7
  359. package/dist/fhir/MedicinalProductContraindication.js.map +0 -1
  360. package/dist/fhir/MedicinalProductIndication.d.ts +0 -179
  361. package/dist/fhir/MedicinalProductIndication.js +0 -7
  362. package/dist/fhir/MedicinalProductIndication.js.map +0 -1
  363. package/dist/fhir/MedicinalProductIngredient.d.ts +0 -336
  364. package/dist/fhir/MedicinalProductIngredient.js +0 -7
  365. package/dist/fhir/MedicinalProductIngredient.js.map +0 -1
  366. package/dist/fhir/MedicinalProductInteraction.d.ts +0 -158
  367. package/dist/fhir/MedicinalProductInteraction.js +0 -7
  368. package/dist/fhir/MedicinalProductInteraction.js.map +0 -1
  369. package/dist/fhir/MedicinalProductManufactured.d.ts +0 -113
  370. package/dist/fhir/MedicinalProductManufactured.js +0 -7
  371. package/dist/fhir/MedicinalProductManufactured.js.map +0 -1
  372. package/dist/fhir/MedicinalProductPackaged.d.ts +0 -259
  373. package/dist/fhir/MedicinalProductPackaged.js +0 -7
  374. package/dist/fhir/MedicinalProductPackaged.js.map +0 -1
  375. package/dist/fhir/MedicinalProductPharmaceutical.d.ts +0 -331
  376. package/dist/fhir/MedicinalProductPharmaceutical.js +0 -7
  377. package/dist/fhir/MedicinalProductPharmaceutical.js.map +0 -1
  378. package/dist/fhir/MedicinalProductUndesirableEffect.d.ts +0 -101
  379. package/dist/fhir/MedicinalProductUndesirableEffect.js +0 -7
  380. package/dist/fhir/MedicinalProductUndesirableEffect.js.map +0 -1
  381. package/dist/fhir/MessageDefinition.d.ts +0 -330
  382. package/dist/fhir/MessageDefinition.js +0 -7
  383. package/dist/fhir/MessageDefinition.js.map +0 -1
  384. package/dist/fhir/MessageHeader.d.ts +0 -323
  385. package/dist/fhir/MessageHeader.js +0 -7
  386. package/dist/fhir/MessageHeader.js.map +0 -1
  387. package/dist/fhir/Meta.d.ts +0 -75
  388. package/dist/fhir/Meta.js +0 -7
  389. package/dist/fhir/Meta.js.map +0 -1
  390. package/dist/fhir/MolecularSequence.d.ts +0 -760
  391. package/dist/fhir/MolecularSequence.js +0 -7
  392. package/dist/fhir/MolecularSequence.js.map +0 -1
  393. package/dist/fhir/Money.d.ts +0 -29
  394. package/dist/fhir/Money.js +0 -7
  395. package/dist/fhir/Money.js.map +0 -1
  396. package/dist/fhir/NamingSystem.d.ts +0 -218
  397. package/dist/fhir/NamingSystem.js +0 -7
  398. package/dist/fhir/NamingSystem.js.map +0 -1
  399. package/dist/fhir/Narrative.d.ts +0 -32
  400. package/dist/fhir/Narrative.js +0 -7
  401. package/dist/fhir/Narrative.js.map +0 -1
  402. package/dist/fhir/NutritionOrder.d.ts +0 -566
  403. package/dist/fhir/NutritionOrder.js +0 -7
  404. package/dist/fhir/NutritionOrder.js.map +0 -1
  405. package/dist/fhir/Observation.d.ts +0 -520
  406. package/dist/fhir/Observation.js +0 -7
  407. package/dist/fhir/Observation.js.map +0 -1
  408. package/dist/fhir/ObservationDefinition.d.ts +0 -278
  409. package/dist/fhir/ObservationDefinition.js +0 -7
  410. package/dist/fhir/ObservationDefinition.js.map +0 -1
  411. package/dist/fhir/OperationDefinition.d.ts +0 -468
  412. package/dist/fhir/OperationDefinition.js +0 -7
  413. package/dist/fhir/OperationDefinition.js.map +0 -1
  414. package/dist/fhir/OperationOutcome.d.ts +0 -160
  415. package/dist/fhir/OperationOutcome.js +0 -7
  416. package/dist/fhir/OperationOutcome.js.map +0 -1
  417. package/dist/fhir/Organization.d.ts +0 -184
  418. package/dist/fhir/Organization.js +0 -7
  419. package/dist/fhir/Organization.js.map +0 -1
  420. package/dist/fhir/OrganizationAffiliation.d.ts +0 -145
  421. package/dist/fhir/OrganizationAffiliation.js +0 -7
  422. package/dist/fhir/OrganizationAffiliation.js.map +0 -1
  423. package/dist/fhir/ParameterDefinition.d.ts +0 -57
  424. package/dist/fhir/ParameterDefinition.js +0 -7
  425. package/dist/fhir/ParameterDefinition.js.map +0 -1
  426. package/dist/fhir/Parameters.d.ts +0 -319
  427. package/dist/fhir/Parameters.js +0 -7
  428. package/dist/fhir/Parameters.js.map +0 -1
  429. package/dist/fhir/PasswordChangeRequest.d.ts +0 -51
  430. package/dist/fhir/PasswordChangeRequest.js +0 -7
  431. package/dist/fhir/PasswordChangeRequest.js.map +0 -1
  432. package/dist/fhir/Patient.d.ts +0 -342
  433. package/dist/fhir/Patient.js +0 -7
  434. package/dist/fhir/Patient.js.map +0 -1
  435. package/dist/fhir/PaymentNotice.d.ts +0 -135
  436. package/dist/fhir/PaymentNotice.js +0 -7
  437. package/dist/fhir/PaymentNotice.js.map +0 -1
  438. package/dist/fhir/PaymentReconciliation.d.ts +0 -280
  439. package/dist/fhir/PaymentReconciliation.js +0 -7
  440. package/dist/fhir/PaymentReconciliation.js.map +0 -1
  441. package/dist/fhir/Period.d.ts +0 -32
  442. package/dist/fhir/Period.js +0 -7
  443. package/dist/fhir/Period.js.map +0 -1
  444. package/dist/fhir/Person.d.ts +0 -175
  445. package/dist/fhir/Person.js +0 -7
  446. package/dist/fhir/Person.js.map +0 -1
  447. package/dist/fhir/PlanDefinition.d.ts +0 -837
  448. package/dist/fhir/PlanDefinition.js +0 -7
  449. package/dist/fhir/PlanDefinition.js.map +0 -1
  450. package/dist/fhir/Population.d.ts +0 -62
  451. package/dist/fhir/Population.js +0 -7
  452. package/dist/fhir/Population.js.map +0 -1
  453. package/dist/fhir/Practitioner.d.ts +0 -191
  454. package/dist/fhir/Practitioner.js +0 -7
  455. package/dist/fhir/Practitioner.js.map +0 -1
  456. package/dist/fhir/PractitionerRole.d.ts +0 -259
  457. package/dist/fhir/PractitionerRole.js +0 -7
  458. package/dist/fhir/PractitionerRole.js.map +0 -1
  459. package/dist/fhir/Procedure.d.ts +0 -372
  460. package/dist/fhir/Procedure.js +0 -7
  461. package/dist/fhir/Procedure.js.map +0 -1
  462. package/dist/fhir/ProdCharacteristic.d.ts +0 -112
  463. package/dist/fhir/ProdCharacteristic.js +0 -7
  464. package/dist/fhir/ProdCharacteristic.js.map +0 -1
  465. package/dist/fhir/ProductShelfLife.d.ts +0 -70
  466. package/dist/fhir/ProductShelfLife.js +0 -7
  467. package/dist/fhir/ProductShelfLife.js.map +0 -1
  468. package/dist/fhir/Project.d.ts +0 -43
  469. package/dist/fhir/Project.js +0 -7
  470. package/dist/fhir/Project.js.map +0 -1
  471. package/dist/fhir/ProjectMembership.d.ts +0 -66
  472. package/dist/fhir/ProjectMembership.js +0 -7
  473. package/dist/fhir/ProjectMembership.js.map +0 -1
  474. package/dist/fhir/Provenance.d.ts +0 -258
  475. package/dist/fhir/Provenance.js +0 -7
  476. package/dist/fhir/Provenance.js.map +0 -1
  477. package/dist/fhir/Quantity.d.ts +0 -46
  478. package/dist/fhir/Quantity.js +0 -7
  479. package/dist/fhir/Quantity.js.map +0 -1
  480. package/dist/fhir/Questionnaire.d.ts +0 -603
  481. package/dist/fhir/Questionnaire.js +0 -7
  482. package/dist/fhir/Questionnaire.js.map +0 -1
  483. package/dist/fhir/QuestionnaireResponse.d.ts +0 -313
  484. package/dist/fhir/QuestionnaireResponse.js +0 -7
  485. package/dist/fhir/QuestionnaireResponse.js.map +0 -1
  486. package/dist/fhir/Range.d.ts +0 -30
  487. package/dist/fhir/Range.js +0 -7
  488. package/dist/fhir/Range.js.map +0 -1
  489. package/dist/fhir/Ratio.d.ts +0 -30
  490. package/dist/fhir/Ratio.js +0 -7
  491. package/dist/fhir/Ratio.js.map +0 -1
  492. package/dist/fhir/Reference.d.ts +0 -67
  493. package/dist/fhir/Reference.js +0 -7
  494. package/dist/fhir/Reference.js.map +0 -1
  495. package/dist/fhir/RefreshToken.d.ts +0 -45
  496. package/dist/fhir/RefreshToken.js +0 -7
  497. package/dist/fhir/RefreshToken.js.map +0 -1
  498. package/dist/fhir/RelatedArtifact.d.ts +0 -57
  499. package/dist/fhir/RelatedArtifact.js +0 -7
  500. package/dist/fhir/RelatedArtifact.js.map +0 -1
  501. package/dist/fhir/RelatedPerson.d.ts +0 -190
  502. package/dist/fhir/RelatedPerson.js +0 -7
  503. package/dist/fhir/RelatedPerson.js.map +0 -1
  504. package/dist/fhir/RequestGroup.d.ts +0 -434
  505. package/dist/fhir/RequestGroup.js +0 -7
  506. package/dist/fhir/RequestGroup.js.map +0 -1
  507. package/dist/fhir/ResearchDefinition.d.ts +0 -291
  508. package/dist/fhir/ResearchDefinition.js +0 -7
  509. package/dist/fhir/ResearchDefinition.js.map +0 -1
  510. package/dist/fhir/ResearchElementDefinition.d.ts +0 -431
  511. package/dist/fhir/ResearchElementDefinition.js +0 -7
  512. package/dist/fhir/ResearchElementDefinition.js.map +0 -1
  513. package/dist/fhir/ResearchStudy.d.ts +0 -318
  514. package/dist/fhir/ResearchStudy.js +0 -7
  515. package/dist/fhir/ResearchStudy.js.map +0 -1
  516. package/dist/fhir/ResearchSubject.d.ts +0 -119
  517. package/dist/fhir/ResearchSubject.js +0 -7
  518. package/dist/fhir/ResearchSubject.js.map +0 -1
  519. package/dist/fhir/Resource.d.ts +0 -156
  520. package/dist/fhir/Resource.js +0 -7
  521. package/dist/fhir/Resource.js.map +0 -1
  522. package/dist/fhir/RiskAssessment.d.ts +0 -246
  523. package/dist/fhir/RiskAssessment.js +0 -7
  524. package/dist/fhir/RiskAssessment.js.map +0 -1
  525. package/dist/fhir/RiskEvidenceSynthesis.d.ts +0 -530
  526. package/dist/fhir/RiskEvidenceSynthesis.js +0 -7
  527. package/dist/fhir/RiskEvidenceSynthesis.js.map +0 -1
  528. package/dist/fhir/SampledData.d.ts +0 -62
  529. package/dist/fhir/SampledData.js +0 -7
  530. package/dist/fhir/SampledData.js.map +0 -1
  531. package/dist/fhir/Schedule.d.ts +0 -129
  532. package/dist/fhir/Schedule.js +0 -7
  533. package/dist/fhir/Schedule.js.map +0 -1
  534. package/dist/fhir/SearchParameter.d.ts +0 -277
  535. package/dist/fhir/SearchParameter.js +0 -7
  536. package/dist/fhir/SearchParameter.js.map +0 -1
  537. package/dist/fhir/ServiceRequest.d.ts +0 -309
  538. package/dist/fhir/ServiceRequest.js +0 -7
  539. package/dist/fhir/ServiceRequest.js.map +0 -1
  540. package/dist/fhir/Signature.d.ts +0 -71
  541. package/dist/fhir/Signature.js +0 -7
  542. package/dist/fhir/Signature.js.map +0 -1
  543. package/dist/fhir/Slot.d.ts +0 -134
  544. package/dist/fhir/Slot.js +0 -7
  545. package/dist/fhir/Slot.js.map +0 -1
  546. package/dist/fhir/Specimen.d.ts +0 -366
  547. package/dist/fhir/Specimen.js +0 -7
  548. package/dist/fhir/Specimen.js.map +0 -1
  549. package/dist/fhir/SpecimenDefinition.d.ts +0 -363
  550. package/dist/fhir/SpecimenDefinition.js +0 -7
  551. package/dist/fhir/SpecimenDefinition.js.map +0 -1
  552. package/dist/fhir/StructureDefinition.d.ts +0 -438
  553. package/dist/fhir/StructureDefinition.js +0 -7
  554. package/dist/fhir/StructureDefinition.js.map +0 -1
  555. package/dist/fhir/StructureMap.d.ts +0 -904
  556. package/dist/fhir/StructureMap.js +0 -7
  557. package/dist/fhir/StructureMap.js.map +0 -1
  558. package/dist/fhir/Subscription.d.ts +0 -172
  559. package/dist/fhir/Subscription.js +0 -7
  560. package/dist/fhir/Subscription.js.map +0 -1
  561. package/dist/fhir/Substance.d.ts +0 -213
  562. package/dist/fhir/Substance.js +0 -7
  563. package/dist/fhir/Substance.js.map +0 -1
  564. package/dist/fhir/SubstanceAmount.d.ts +0 -115
  565. package/dist/fhir/SubstanceAmount.js +0 -7
  566. package/dist/fhir/SubstanceAmount.js.map +0 -1
  567. package/dist/fhir/SubstanceNucleicAcid.d.ts +0 -309
  568. package/dist/fhir/SubstanceNucleicAcid.js +0 -7
  569. package/dist/fhir/SubstanceNucleicAcid.js.map +0 -1
  570. package/dist/fhir/SubstancePolymer.d.ts +0 -405
  571. package/dist/fhir/SubstancePolymer.js +0 -7
  572. package/dist/fhir/SubstancePolymer.js.map +0 -1
  573. package/dist/fhir/SubstanceProtein.d.ts +0 -218
  574. package/dist/fhir/SubstanceProtein.js +0 -7
  575. package/dist/fhir/SubstanceProtein.js.map +0 -1
  576. package/dist/fhir/SubstanceReferenceInformation.d.ts +0 -330
  577. package/dist/fhir/SubstanceReferenceInformation.js +0 -7
  578. package/dist/fhir/SubstanceReferenceInformation.js.map +0 -1
  579. package/dist/fhir/SubstanceSourceMaterial.d.ts +0 -521
  580. package/dist/fhir/SubstanceSourceMaterial.js +0 -7
  581. package/dist/fhir/SubstanceSourceMaterial.js.map +0 -1
  582. package/dist/fhir/SubstanceSpecification.d.ts +0 -827
  583. package/dist/fhir/SubstanceSpecification.js +0 -7
  584. package/dist/fhir/SubstanceSpecification.js.map +0 -1
  585. package/dist/fhir/SupplyDelivery.d.ts +0 -205
  586. package/dist/fhir/SupplyDelivery.js +0 -7
  587. package/dist/fhir/SupplyDelivery.js.map +0 -1
  588. package/dist/fhir/SupplyRequest.d.ts +0 -237
  589. package/dist/fhir/SupplyRequest.js +0 -7
  590. package/dist/fhir/SupplyRequest.js.map +0 -1
  591. package/dist/fhir/Task.d.ts +0 -807
  592. package/dist/fhir/Task.js +0 -7
  593. package/dist/fhir/Task.js.map +0 -1
  594. package/dist/fhir/TerminologyCapabilities.d.ts +0 -716
  595. package/dist/fhir/TerminologyCapabilities.js +0 -7
  596. package/dist/fhir/TerminologyCapabilities.js.map +0 -1
  597. package/dist/fhir/TestReport.d.ts +0 -549
  598. package/dist/fhir/TestReport.js +0 -7
  599. package/dist/fhir/TestReport.js.map +0 -1
  600. package/dist/fhir/TestScript.d.ts +0 -1184
  601. package/dist/fhir/TestScript.js +0 -7
  602. package/dist/fhir/TestScript.js.map +0 -1
  603. package/dist/fhir/Timing.d.ts +0 -178
  604. package/dist/fhir/Timing.js +0 -7
  605. package/dist/fhir/Timing.js.map +0 -1
  606. package/dist/fhir/TriggerDefinition.d.ts +0 -65
  607. package/dist/fhir/TriggerDefinition.js +0 -7
  608. package/dist/fhir/TriggerDefinition.js.map +0 -1
  609. package/dist/fhir/UsageContext.d.ts +0 -61
  610. package/dist/fhir/UsageContext.js +0 -7
  611. package/dist/fhir/UsageContext.js.map +0 -1
  612. package/dist/fhir/User.d.ts +0 -45
  613. package/dist/fhir/User.js +0 -7
  614. package/dist/fhir/User.js.map +0 -1
  615. package/dist/fhir/ValueSet.d.ts +0 -725
  616. package/dist/fhir/ValueSet.js +0 -7
  617. package/dist/fhir/ValueSet.js.map +0 -1
  618. package/dist/fhir/VerificationResult.d.ts +0 -340
  619. package/dist/fhir/VerificationResult.js +0 -7
  620. package/dist/fhir/VerificationResult.js.map +0 -1
  621. package/dist/fhir/VisionPrescription.d.ts +0 -264
  622. package/dist/fhir/VisionPrescription.js +0 -7
  623. package/dist/fhir/VisionPrescription.js.map +0 -1
  624. package/dist/fhir/index.d.ts +0 -196
  625. package/dist/fhir/index.js +0 -213
  626. package/dist/fhir/index.js.map +0 -1
  627. package/dist/fhirpath/functions.d.ts +0 -6
  628. package/dist/fhirpath/functions.js +0 -349
  629. package/dist/fhirpath/functions.js.map +0 -1
  630. package/dist/fhirpath/index.d.ts +0 -2
  631. package/dist/fhirpath/index.js +0 -15
  632. package/dist/fhirpath/index.js.map +0 -1
  633. package/dist/fhirpath/parse.d.ts +0 -10
  634. package/dist/fhirpath/parse.js +0 -266
  635. package/dist/fhirpath/parse.js.map +0 -1
  636. package/dist/fhirpath/tokenize.d.ts +0 -13
  637. package/dist/fhirpath/tokenize.js +0 -39
  638. package/dist/fhirpath/tokenize.js.map +0 -1
  639. package/dist/fhirpath/utils.d.ts +0 -13
  640. package/dist/fhirpath/utils.js +0 -34
  641. package/dist/fhirpath/utils.js.map +0 -1
  642. package/dist/format.js +0 -56
  643. package/dist/format.js.map +0 -1
  644. package/dist/index.js +0 -22
  645. package/dist/index.js.map +0 -1
  646. package/dist/jwt.d.ts +0 -5
  647. package/dist/jwt.js +0 -28
  648. package/dist/jwt.js.map +0 -1
  649. package/dist/outcomes.js +0 -140
  650. package/dist/outcomes.js.map +0 -1
  651. package/dist/search.js +0 -120
  652. package/dist/search.js.map +0 -1
  653. package/dist/searchparams.js +0 -129
  654. package/dist/searchparams.js.map +0 -1
  655. package/dist/storage.js +0 -90
  656. package/dist/storage.js.map +0 -1
  657. package/dist/types.js +0 -171
  658. package/dist/types.js.map +0 -1
  659. package/dist/utils.js +0 -234
  660. package/dist/utils.js.map +0 -1
@@ -0,0 +1,1769 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ function __awaiter(thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ }
25
+
26
+ function __classPrivateFieldGet(receiver, state, kind, f) {
27
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
28
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
+ }
31
+
32
+ function __classPrivateFieldSet(receiver, state, value, kind, f) {
33
+ if (kind === "m") throw new TypeError("Private method is not writable");
34
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
35
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
36
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
37
+ }
38
+
39
+ var _LRUCache_instances, _LRUCache_max, _LRUCache_cache, _LRUCache_first;
40
+ /**
41
+ * LRU cache (least recently used)
42
+ * Source: https://stackoverflow.com/a/46432113
43
+ */
44
+ class LRUCache {
45
+ constructor(max = 10) {
46
+ _LRUCache_instances.add(this);
47
+ _LRUCache_max.set(this, void 0);
48
+ _LRUCache_cache.set(this, void 0);
49
+ __classPrivateFieldSet(this, _LRUCache_max, max, "f");
50
+ __classPrivateFieldSet(this, _LRUCache_cache, new Map(), "f");
51
+ }
52
+ clear() {
53
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").clear();
54
+ }
55
+ get(key) {
56
+ const item = __classPrivateFieldGet(this, _LRUCache_cache, "f").get(key);
57
+ if (item) {
58
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").delete(key);
59
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").set(key, item);
60
+ }
61
+ return item;
62
+ }
63
+ set(key, val) {
64
+ if (__classPrivateFieldGet(this, _LRUCache_cache, "f").has(key)) {
65
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").delete(key);
66
+ }
67
+ else if (__classPrivateFieldGet(this, _LRUCache_cache, "f").size >= __classPrivateFieldGet(this, _LRUCache_max, "f")) {
68
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").delete(__classPrivateFieldGet(this, _LRUCache_instances, "m", _LRUCache_first).call(this));
69
+ }
70
+ __classPrivateFieldGet(this, _LRUCache_cache, "f").set(key, val);
71
+ }
72
+ }
73
+ _LRUCache_max = new WeakMap(), _LRUCache_cache = new WeakMap(), _LRUCache_instances = new WeakSet(), _LRUCache_first = function _LRUCache_first() {
74
+ // This works because the Map class maintains ordered keys.
75
+ return __classPrivateFieldGet(this, _LRUCache_cache, "f").keys().next().value;
76
+ };
77
+
78
+ function formatAddress(address, options) {
79
+ const builder = [];
80
+ if (address.line) {
81
+ builder.push(...address.line);
82
+ }
83
+ if (address.city) {
84
+ builder.push(address.city);
85
+ }
86
+ if (address.state) {
87
+ builder.push(address.state);
88
+ }
89
+ if (address.postalCode) {
90
+ builder.push(address.postalCode);
91
+ }
92
+ if (address.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
93
+ builder.push('[' + address.use + ']');
94
+ }
95
+ return builder.join(', ').trim();
96
+ }
97
+ function formatHumanName(name, options) {
98
+ const builder = [];
99
+ if (name.prefix && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.prefix))) {
100
+ builder.push(...name.prefix);
101
+ }
102
+ if (name.given) {
103
+ builder.push(...name.given);
104
+ }
105
+ if (name.family) {
106
+ builder.push(name.family);
107
+ }
108
+ if (name.suffix && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.suffix))) {
109
+ builder.push(...name.suffix);
110
+ }
111
+ if (name.use && ((options === null || options === void 0 ? void 0 : options.all) || (options === null || options === void 0 ? void 0 : options.use))) {
112
+ builder.push('[' + name.use + ']');
113
+ }
114
+ return builder.join(' ').trim();
115
+ }
116
+ function formatGivenName(name) {
117
+ const builder = [];
118
+ if (name.given) {
119
+ builder.push(...name.given);
120
+ }
121
+ return builder.join(' ').trim();
122
+ }
123
+ function formatFamilyName(name) {
124
+ return name.family || '';
125
+ }
126
+
127
+ /**
128
+ * Creates a reference resource.
129
+ * @param resource The FHIR reesource.
130
+ * @returns A reference resource.
131
+ */
132
+ function createReference(resource) {
133
+ const reference = getReferenceString(resource);
134
+ const display = getDisplayString(resource);
135
+ return display === reference ? { reference } : { reference, display };
136
+ }
137
+ /**
138
+ * Returns a reference string for a resource.
139
+ * @param resource The FHIR resource.
140
+ * @returns A reference string of the form resourceType/id.
141
+ */
142
+ function getReferenceString(resource) {
143
+ return resource.resourceType + '/' + resource.id;
144
+ }
145
+ /**
146
+ * Returns the ID portion of a reference.
147
+ * @param reference A FHIR reference.
148
+ * @returns The ID portion of a reference.
149
+ */
150
+ function resolveId(reference) {
151
+ var _a;
152
+ return (_a = reference === null || reference === void 0 ? void 0 : reference.reference) === null || _a === void 0 ? void 0 : _a.split('/')[1];
153
+ }
154
+ /**
155
+ * Returns true if the resource is a "ProfileResource".
156
+ * @param resource The FHIR resource.
157
+ * @returns True if the resource is a "ProfileResource".
158
+ */
159
+ function isProfileResource(resource) {
160
+ return (resource.resourceType === 'Patient' ||
161
+ resource.resourceType === 'Practitioner' ||
162
+ resource.resourceType === 'RelatedPerson');
163
+ }
164
+ /**
165
+ * Returns a display string for the resource.
166
+ * @param resource The input resource.
167
+ * @return Human friendly display string.
168
+ */
169
+ function getDisplayString(resource) {
170
+ if (isProfileResource(resource)) {
171
+ const profileName = getProfileResourceDisplayString(resource);
172
+ if (profileName) {
173
+ return profileName;
174
+ }
175
+ }
176
+ if (resource.resourceType === 'Device') {
177
+ const deviceName = getDeviceDisplayString(resource);
178
+ if (deviceName) {
179
+ return deviceName;
180
+ }
181
+ }
182
+ if (resource.resourceType === 'User') {
183
+ if (resource.email) {
184
+ return resource.email;
185
+ }
186
+ }
187
+ if ('name' in resource && resource.name && typeof resource.name === 'string') {
188
+ return resource.name;
189
+ }
190
+ return getReferenceString(resource);
191
+ }
192
+ /**
193
+ * Returns a display string for a profile resource if one is found.
194
+ * @param resource The profile resource.
195
+ * @returns The display name if one is found.
196
+ */
197
+ function getProfileResourceDisplayString(resource) {
198
+ const names = resource.name;
199
+ if (names && names.length > 0) {
200
+ return formatHumanName(names[0]);
201
+ }
202
+ return undefined;
203
+ }
204
+ /**
205
+ * Returns a display string for a device resource if one is found.
206
+ * @param device The device resource.
207
+ * @returns The display name if one is found.
208
+ */
209
+ function getDeviceDisplayString(device) {
210
+ const names = device.deviceName;
211
+ if (names && names.length > 0) {
212
+ return names[0].name;
213
+ }
214
+ return undefined;
215
+ }
216
+ /**
217
+ * Returns an image URL for the resource, if one is available.
218
+ * @param resource The input resource.
219
+ * @returns The image URL for the resource or undefined.
220
+ */
221
+ function getImageSrc(resource) {
222
+ if (isProfileResource(resource)) {
223
+ const photos = resource.photo;
224
+ if (photos) {
225
+ for (const photo of photos) {
226
+ if (photo.url && photo.contentType && photo.contentType.startsWith('image/')) {
227
+ return photo.url;
228
+ }
229
+ }
230
+ }
231
+ }
232
+ return undefined;
233
+ }
234
+ /**
235
+ * Returns a Date property as a Date.
236
+ * When working with JSON objects, Dates are often serialized as ISO-8601 strings.
237
+ * When that happens, we need to safely convert to a proper Date object.
238
+ * @param date The date property value, which could be a string or a Date object.
239
+ * @returns A Date object.
240
+ */
241
+ function getDateProperty(date) {
242
+ return date ? new Date(date) : undefined;
243
+ }
244
+ /**
245
+ * FHIR JSON stringify.
246
+ * Removes properties with empty string values.
247
+ * Removes objects with zero properties.
248
+ * See: https://www.hl7.org/fhir/json.html
249
+ * @param value The input value.
250
+ * @param pretty Optional flag to pretty-print the JSON.
251
+ * @returns The resulting JSON string.
252
+ */
253
+ function stringify(value, pretty) {
254
+ return JSON.stringify(value, stringifyReplacer, pretty ? 2 : undefined);
255
+ }
256
+ /**
257
+ * Evaluates JSON key/value pairs for FHIR JSON stringify.
258
+ * Removes properties with empty string values.
259
+ * Removes objects with zero properties.
260
+ * @param {string} k Property key.
261
+ * @param {*} v Property value.
262
+ */
263
+ function stringifyReplacer(k, v) {
264
+ return isEmpty(v) ? undefined : v;
265
+ }
266
+ /**
267
+ * Returns true if the value is empty (null, undefined, empty string, or empty object).
268
+ * @param v Any value.
269
+ * @returns True if the value is an empty string or an empty object.
270
+ */
271
+ function isEmpty(v) {
272
+ if (v === null || v === undefined) {
273
+ return true;
274
+ }
275
+ const t = typeof v;
276
+ return (t === 'string' && v === '') || (t === 'object' && Object.keys(v).length === 0);
277
+ }
278
+ /**
279
+ * Resource equality.
280
+ * Ignores meta.versionId and meta.lastUpdated.
281
+ * See: https://dmitripavlutin.com/how-to-compare-objects-in-javascript/#4-deep-equality
282
+ * @param object1 The first object.
283
+ * @param object2 The second object.
284
+ * @returns True if the objects are equal.
285
+ */
286
+ function deepEquals(object1, object2, path) {
287
+ let keys1 = Object.keys(object1);
288
+ let keys2 = Object.keys(object2);
289
+ if (path === 'meta') {
290
+ keys1 = keys1.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
291
+ keys2 = keys2.filter((k) => k !== 'versionId' && k !== 'lastUpdated' && k !== 'author');
292
+ }
293
+ if (keys1.length !== keys2.length) {
294
+ return false;
295
+ }
296
+ for (const key of keys1) {
297
+ const val1 = object1[key];
298
+ const val2 = object2[key];
299
+ if (isObject(val1) && isObject(val2)) {
300
+ if (!deepEquals(val1, val2, key)) {
301
+ return false;
302
+ }
303
+ }
304
+ else {
305
+ if (val1 !== val2) {
306
+ return false;
307
+ }
308
+ }
309
+ }
310
+ return true;
311
+ }
312
+ function isObject(object) {
313
+ return object !== null && typeof object === 'object';
314
+ }
315
+ // Precompute hex octets
316
+ // See: https://stackoverflow.com/a/55200387
317
+ const byteToHex = [];
318
+ for (let n = 0; n < 256; n++) {
319
+ byteToHex.push(n.toString(16).padStart(2, '0'));
320
+ }
321
+ /**
322
+ * Converts an ArrayBuffer to hex string.
323
+ * See: https://stackoverflow.com/a/55200387
324
+ * @param arrayBuffer The input array buffer.
325
+ * @returns The resulting hex string.
326
+ */
327
+ function arrayBufferToHex(arrayBuffer) {
328
+ const bytes = new Uint8Array(arrayBuffer);
329
+ const result = new Array(bytes.length);
330
+ for (let i = 0; i < bytes.length; i++) {
331
+ result[i] = byteToHex[bytes[i]];
332
+ }
333
+ return result.join('');
334
+ }
335
+ /**
336
+ * Converts an ArrayBuffer to a base-64 encoded string.
337
+ * @param arrayBuffer The input array buffer.
338
+ * @returns The base-64 encoded string.
339
+ */
340
+ function arrayBufferToBase64(arrayBuffer) {
341
+ const bytes = new Uint8Array(arrayBuffer);
342
+ const result = [];
343
+ for (let i = 0; i < bytes.length; i++) {
344
+ result[i] = String.fromCharCode(bytes[i]);
345
+ }
346
+ return window.btoa(result.join(''));
347
+ }
348
+ function capitalize(word) {
349
+ return word.charAt(0).toUpperCase() + word.substr(1);
350
+ }
351
+ function isLowerCase(c) {
352
+ return c === c.toLowerCase();
353
+ }
354
+
355
+ /**
356
+ * Returns a cryptographically secure random string.
357
+ */
358
+ function getRandomString() {
359
+ const randomItems = new Uint32Array(28);
360
+ crypto.getRandomValues(randomItems);
361
+ return arrayBufferToHex(randomItems.buffer);
362
+ }
363
+ /**
364
+ * Encrypts a string with SHA256 encryption.
365
+ * @param str
366
+ */
367
+ function encryptSHA256(str) {
368
+ return __awaiter(this, void 0, void 0, function* () {
369
+ return crypto.subtle.digest('SHA-256', new TextEncoder().encode(str));
370
+ });
371
+ }
372
+
373
+ /*
374
+ * Based on: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
375
+ */
376
+ var _EventTarget_listeners;
377
+ class EventTarget {
378
+ constructor() {
379
+ _EventTarget_listeners.set(this, void 0);
380
+ __classPrivateFieldSet(this, _EventTarget_listeners, {}, "f");
381
+ }
382
+ addEventListener(type, callback) {
383
+ if (!__classPrivateFieldGet(this, _EventTarget_listeners, "f")[type]) {
384
+ __classPrivateFieldGet(this, _EventTarget_listeners, "f")[type] = [];
385
+ }
386
+ __classPrivateFieldGet(this, _EventTarget_listeners, "f")[type].push(callback);
387
+ }
388
+ removeEventListeneer(type, callback) {
389
+ const array = __classPrivateFieldGet(this, _EventTarget_listeners, "f")[type];
390
+ if (!array) {
391
+ return;
392
+ }
393
+ for (let i = 0; i < array.length; i++) {
394
+ if (array[i] === callback) {
395
+ array.splice(i, 1);
396
+ return;
397
+ }
398
+ }
399
+ }
400
+ dispatchEvent(event) {
401
+ const array = __classPrivateFieldGet(this, _EventTarget_listeners, "f")[event.type];
402
+ if (array) {
403
+ array.forEach((listener) => listener.call(this, event));
404
+ }
405
+ return !event.defaultPrevented;
406
+ }
407
+ }
408
+ _EventTarget_listeners = new WeakMap();
409
+
410
+ /**
411
+ * Decodes a section of a JWT.
412
+ * See: https://tools.ietf.org/html/rfc7519
413
+ * @param payload
414
+ */
415
+ function decodePayload(payload) {
416
+ const cleanedPayload = payload.replace(/-/g, '+').replace(/_/g, '/');
417
+ const decodedPayload = window.atob(cleanedPayload);
418
+ const uriEncodedPayload = Array.from(decodedPayload).reduce((acc, char) => {
419
+ const uriEncodedChar = ('00' + char.charCodeAt(0).toString(16)).slice(-2);
420
+ return `${acc}%${uriEncodedChar}`;
421
+ }, '');
422
+ const jsonPayload = decodeURIComponent(uriEncodedPayload);
423
+ return JSON.parse(jsonPayload);
424
+ }
425
+ /**
426
+ * Parses the JWT payload.
427
+ * @param token JWT token
428
+ */
429
+ function parseJWTPayload(token) {
430
+ const [_header, payload, _signature] = token.split('.');
431
+ return decodePayload(payload);
432
+ }
433
+
434
+ const OK_ID = 'ok';
435
+ const CREATED_ID = 'created';
436
+ const GONE_ID = 'gone';
437
+ const NOT_MODIFIED_ID = 'not-modified';
438
+ const NOT_FOUND_ID = 'not-found';
439
+ const ACCESS_DENIED = 'access-denied';
440
+ const allOk = {
441
+ resourceType: 'OperationOutcome',
442
+ id: OK_ID,
443
+ issue: [
444
+ {
445
+ severity: 'information',
446
+ code: 'information',
447
+ details: {
448
+ text: 'All OK',
449
+ },
450
+ },
451
+ ],
452
+ };
453
+ const created = {
454
+ resourceType: 'OperationOutcome',
455
+ id: CREATED_ID,
456
+ issue: [
457
+ {
458
+ severity: 'information',
459
+ code: 'information',
460
+ details: {
461
+ text: 'Created',
462
+ },
463
+ },
464
+ ],
465
+ };
466
+ const notModified = {
467
+ resourceType: 'OperationOutcome',
468
+ id: NOT_MODIFIED_ID,
469
+ issue: [
470
+ {
471
+ severity: 'information',
472
+ code: 'information',
473
+ details: {
474
+ text: 'Not Modified',
475
+ },
476
+ },
477
+ ],
478
+ };
479
+ const notFound = {
480
+ resourceType: 'OperationOutcome',
481
+ id: NOT_FOUND_ID,
482
+ issue: [
483
+ {
484
+ severity: 'error',
485
+ code: 'not-found',
486
+ details: {
487
+ text: 'Not found',
488
+ },
489
+ },
490
+ ],
491
+ };
492
+ const gone = {
493
+ resourceType: 'OperationOutcome',
494
+ id: GONE_ID,
495
+ issue: [
496
+ {
497
+ severity: 'error',
498
+ code: 'gone',
499
+ details: {
500
+ text: 'Gone',
501
+ },
502
+ },
503
+ ],
504
+ };
505
+ const accessDenied = {
506
+ resourceType: 'OperationOutcome',
507
+ id: ACCESS_DENIED,
508
+ issue: [
509
+ {
510
+ severity: 'error',
511
+ code: 'access-denied',
512
+ details: {
513
+ text: 'Access Denied',
514
+ },
515
+ },
516
+ ],
517
+ };
518
+ function badRequest(details, expression) {
519
+ return {
520
+ resourceType: 'OperationOutcome',
521
+ issue: [
522
+ {
523
+ severity: 'error',
524
+ code: 'invalid',
525
+ details: {
526
+ text: details,
527
+ },
528
+ expression: expression ? [expression] : undefined,
529
+ },
530
+ ],
531
+ };
532
+ }
533
+ function isOk(outcome) {
534
+ return outcome.id === OK_ID || outcome.id === CREATED_ID || outcome.id === NOT_MODIFIED_ID;
535
+ }
536
+ function isNotFound(outcome) {
537
+ return outcome.id === NOT_FOUND_ID;
538
+ }
539
+ function isGone(outcome) {
540
+ return outcome.id === GONE_ID;
541
+ }
542
+ function getStatus(outcome) {
543
+ if (outcome.id === OK_ID) {
544
+ return 200;
545
+ }
546
+ else if (outcome.id === CREATED_ID) {
547
+ return 201;
548
+ }
549
+ else if (outcome.id === NOT_MODIFIED_ID) {
550
+ return 304;
551
+ }
552
+ else if (outcome.id === ACCESS_DENIED) {
553
+ return 403;
554
+ }
555
+ else if (outcome.id === NOT_FOUND_ID) {
556
+ return 404;
557
+ }
558
+ else if (outcome.id === GONE_ID) {
559
+ return 410;
560
+ }
561
+ else {
562
+ return 400;
563
+ }
564
+ }
565
+ /**
566
+ * Asserts that the operation completed successfully and that the resource is defined.
567
+ * @param outcome The operation outcome.
568
+ * @param resource The resource that may or may not have been returned.
569
+ */
570
+ function assertOk(outcome, resource) {
571
+ if (!isOk(outcome) || resource === undefined) {
572
+ throw new OperationOutcomeError(outcome);
573
+ }
574
+ }
575
+ class OperationOutcomeError extends Error {
576
+ constructor(outcome) {
577
+ var _a, _b;
578
+ super((_b = (_a = outcome === null || outcome === void 0 ? void 0 : outcome.issue) === null || _a === void 0 ? void 0 : _a[0].details) === null || _b === void 0 ? void 0 : _b.text);
579
+ this.outcome = outcome;
580
+ }
581
+ }
582
+
583
+ /**
584
+ * Search operators.
585
+ * These operators represent "modifiers" and "prefixes" in FHIR search.
586
+ * See: https://www.hl7.org/fhir/search.html
587
+ */
588
+ var Operator;
589
+ (function (Operator) {
590
+ Operator["EQUALS"] = "eq";
591
+ Operator["NOT_EQUALS"] = "ne";
592
+ // Numbers
593
+ Operator["GREATER_THAN"] = "gt";
594
+ Operator["LESS_THAN"] = "lt";
595
+ Operator["GREATER_THAN_OR_EQUALS"] = "ge";
596
+ Operator["LESS_THAN_OR_EQUALS"] = "le";
597
+ // Dates
598
+ Operator["STARTS_AFTER"] = "sa";
599
+ Operator["ENDS_BEFORE"] = "eb";
600
+ Operator["APPROXIMATELY"] = "ap";
601
+ // String
602
+ Operator["CONTAINS"] = "contains";
603
+ Operator["EXACT"] = "exact";
604
+ // Token
605
+ Operator["TEXT"] = "text";
606
+ Operator["ABOVE"] = "above";
607
+ Operator["BELOW"] = "below";
608
+ Operator["IN"] = "in";
609
+ Operator["NOT_IN"] = "not-in";
610
+ Operator["OF_TYPE"] = "of-type";
611
+ })(Operator || (Operator = {}));
612
+ const MODIFIER_OPERATORS = [
613
+ Operator.CONTAINS,
614
+ Operator.EXACT,
615
+ Operator.TEXT,
616
+ Operator.ABOVE,
617
+ Operator.BELOW,
618
+ Operator.IN,
619
+ Operator.NOT_IN,
620
+ Operator.OF_TYPE,
621
+ ];
622
+ const PREFIX_OPERATORS = [
623
+ Operator.NOT_EQUALS,
624
+ Operator.GREATER_THAN,
625
+ Operator.LESS_THAN,
626
+ Operator.GREATER_THAN_OR_EQUALS,
627
+ Operator.LESS_THAN_OR_EQUALS,
628
+ Operator.STARTS_AFTER,
629
+ Operator.ENDS_BEFORE,
630
+ Operator.APPROXIMATELY,
631
+ ];
632
+ /**
633
+ * Parses a URL into a SearchRequest.
634
+ *
635
+ * See the FHIR search spec: http://hl7.org/fhir/r4/search.html
636
+ *
637
+ * @param location The URL to parse.
638
+ * @returns Parsed search definition.
639
+ */
640
+ function parseSearchDefinition(location) {
641
+ const resourceType = location.pathname.split('/').pop();
642
+ const params = new URLSearchParams(location.search);
643
+ const filters = [];
644
+ const sortRules = [];
645
+ let fields;
646
+ let page = 0;
647
+ let count = 10;
648
+ let total = undefined;
649
+ params.forEach((value, key) => {
650
+ if (key === '_fields') {
651
+ fields = value.split(',');
652
+ }
653
+ else if (key === '_page') {
654
+ page = parseInt(value);
655
+ }
656
+ else if (key === '_count') {
657
+ count = parseInt(value);
658
+ }
659
+ else if (key === '_total') {
660
+ total = value;
661
+ }
662
+ else if (key === '_sort') {
663
+ sortRules.push(parseSortRule(value));
664
+ }
665
+ else {
666
+ filters.push(parseSearchFilter(key, value));
667
+ }
668
+ });
669
+ return {
670
+ resourceType,
671
+ filters,
672
+ fields,
673
+ page,
674
+ count,
675
+ total,
676
+ sortRules,
677
+ };
678
+ }
679
+ /**
680
+ * Parses a URL query parameter into a sort rule.
681
+ *
682
+ * By default, the sort rule is the field name.
683
+ *
684
+ * Sort rules can be reversed into descending order by prefixing the field name with a minus sign.
685
+ *
686
+ * See sorting: http://hl7.org/fhir/r4/search.html#_sort
687
+ *
688
+ * @param value The URL parameter value.
689
+ * @returns The parsed sort rule.
690
+ */
691
+ function parseSortRule(value) {
692
+ if (value.startsWith('-')) {
693
+ return { code: value.substring(1), descending: true };
694
+ }
695
+ else {
696
+ return { code: value };
697
+ }
698
+ }
699
+ /**
700
+ * Parses a URL query parameter into a search filter.
701
+ *
702
+ * FHIR search filters can be specified as modifiers or prefixes.
703
+ *
704
+ * For string properties, modifiers are appended to the key, e.g. "name:contains=eve".
705
+ *
706
+ * For date and numeric properties, prefixes are prepended to the value, e.g. "birthdate=gt2000".
707
+ *
708
+ * See the FHIR search spec: http://hl7.org/fhir/r4/search.html
709
+ *
710
+ * @param key The URL parameter key.
711
+ * @param value The URL parameter value.
712
+ * @returns The parsed search filter.
713
+ */
714
+ function parseSearchFilter(key, value) {
715
+ let code = key;
716
+ let operator = Operator.EQUALS;
717
+ for (const modifier of MODIFIER_OPERATORS) {
718
+ const modifierIndex = code.indexOf(':' + modifier);
719
+ if (modifierIndex !== -1) {
720
+ operator = modifier;
721
+ code = code.substring(0, modifierIndex);
722
+ }
723
+ }
724
+ for (const prefix of PREFIX_OPERATORS) {
725
+ if (value.match(new RegExp('^' + prefix + '\\d'))) {
726
+ operator = prefix;
727
+ value = value.substring(prefix.length);
728
+ }
729
+ }
730
+ return { code, operator, value };
731
+ }
732
+ /**
733
+ * Formats a search definition object into a query string.
734
+ * Note: The return value does not include the resource type.
735
+ * @param {!SearchRequest} definition The search definition.
736
+ * @returns Formatted URL.
737
+ */
738
+ function formatSearchQuery(definition) {
739
+ const params = [];
740
+ if (definition.fields) {
741
+ params.push('_fields=' + definition.fields.join(','));
742
+ }
743
+ if (definition.filters) {
744
+ definition.filters.forEach((filter) => {
745
+ const modifier = MODIFIER_OPERATORS.includes(filter.operator) ? ':' + filter.operator : '';
746
+ const prefix = PREFIX_OPERATORS.includes(filter.operator) ? filter.operator : '';
747
+ params.push(`${filter.code}${modifier}=${prefix}${encodeURIComponent(filter.value)}`);
748
+ });
749
+ }
750
+ if (definition.sortRules) {
751
+ params.push(formatSortRules(definition.sortRules));
752
+ }
753
+ if (definition.page && definition.page > 0) {
754
+ params.push('_page=' + definition.page);
755
+ }
756
+ if (definition.count && definition.count > 0) {
757
+ params.push('_count=' + definition.count);
758
+ }
759
+ if (definition.total) {
760
+ params.push('_total=' + encodeURIComponent(definition.total));
761
+ }
762
+ if (params.length === 0) {
763
+ return '';
764
+ }
765
+ params.sort();
766
+ return '?' + params.join('&');
767
+ }
768
+ function formatSortRules(sortRules) {
769
+ if (!sortRules || sortRules.length === 0) {
770
+ return '';
771
+ }
772
+ return '_sort=' + sortRules.map((sr) => (sr.descending ? '-' + sr.code : sr.code)).join(',');
773
+ }
774
+
775
+ var _ClientStorage_storage, _MemoryStorage_data;
776
+ /**
777
+ * The ClientStorage class is a utility class for storing strings and objects.
778
+ *
779
+ * When using MedplumClient in the browser, it will be backed by browser localStorage.
780
+ *
781
+ * When Using MedplumClient in the server, it will be backed by the MemoryStorage class.
782
+ */
783
+ class ClientStorage {
784
+ constructor() {
785
+ _ClientStorage_storage.set(this, void 0);
786
+ __classPrivateFieldSet(this, _ClientStorage_storage, typeof localStorage !== 'undefined' ? localStorage : new MemoryStorage(), "f");
787
+ }
788
+ clear() {
789
+ __classPrivateFieldGet(this, _ClientStorage_storage, "f").clear();
790
+ }
791
+ getString(key) {
792
+ return __classPrivateFieldGet(this, _ClientStorage_storage, "f").getItem(key) || undefined;
793
+ }
794
+ setString(key, value) {
795
+ if (value) {
796
+ __classPrivateFieldGet(this, _ClientStorage_storage, "f").setItem(key, value);
797
+ }
798
+ else {
799
+ __classPrivateFieldGet(this, _ClientStorage_storage, "f").removeItem(key);
800
+ }
801
+ }
802
+ getObject(key) {
803
+ const str = this.getString(key);
804
+ return str ? JSON.parse(str) : undefined;
805
+ }
806
+ setObject(key, value) {
807
+ this.setString(key, value ? stringify(value) : undefined);
808
+ }
809
+ }
810
+ _ClientStorage_storage = new WeakMap();
811
+ /**
812
+ * The MemoryStorage class is a minimal in-memory implementation of the Storage interface.
813
+ */
814
+ class MemoryStorage {
815
+ constructor() {
816
+ _MemoryStorage_data.set(this, void 0);
817
+ __classPrivateFieldSet(this, _MemoryStorage_data, new Map(), "f");
818
+ }
819
+ /**
820
+ * Returns the number of key/value pairs.
821
+ */
822
+ get length() {
823
+ return __classPrivateFieldGet(this, _MemoryStorage_data, "f").size;
824
+ }
825
+ /**
826
+ * Removes all key/value pairs, if there are any.
827
+ */
828
+ clear() {
829
+ __classPrivateFieldGet(this, _MemoryStorage_data, "f").clear();
830
+ }
831
+ /**
832
+ * Returns the current value associated with the given key, or null if the given key does not exist.
833
+ */
834
+ getItem(key) {
835
+ var _a;
836
+ return (_a = __classPrivateFieldGet(this, _MemoryStorage_data, "f").get(key)) !== null && _a !== void 0 ? _a : null;
837
+ }
838
+ /**
839
+ * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
840
+ */
841
+ setItem(key, value) {
842
+ if (value) {
843
+ __classPrivateFieldGet(this, _MemoryStorage_data, "f").set(key, value);
844
+ }
845
+ else {
846
+ __classPrivateFieldGet(this, _MemoryStorage_data, "f").delete(key);
847
+ }
848
+ }
849
+ /**
850
+ * Removes the key/value pair with the given key, if a key/value pair with the given key exists.
851
+ */
852
+ removeItem(key) {
853
+ __classPrivateFieldGet(this, _MemoryStorage_data, "f").delete(key);
854
+ }
855
+ /**
856
+ * Returns the name of the nth key, or null if n is greater than or equal to the number of key/value pairs.
857
+ */
858
+ key(index) {
859
+ return Array.from(__classPrivateFieldGet(this, _MemoryStorage_data, "f").keys())[index];
860
+ }
861
+ }
862
+ _MemoryStorage_data = new WeakMap();
863
+
864
+ /**
865
+ * List of property types.
866
+ * http://www.hl7.org/fhir/valueset-defined-types.html
867
+ * The list here includes additions found from StructureDefinition resources.
868
+ */
869
+ var PropertyType;
870
+ (function (PropertyType) {
871
+ PropertyType["Address"] = "Address";
872
+ PropertyType["Age"] = "Age";
873
+ PropertyType["Annotation"] = "Annotation";
874
+ PropertyType["Attachment"] = "Attachment";
875
+ PropertyType["BackboneElement"] = "BackboneElement";
876
+ PropertyType["CodeableConcept"] = "CodeableConcept";
877
+ PropertyType["Coding"] = "Coding";
878
+ PropertyType["ContactDetail"] = "ContactDetail";
879
+ PropertyType["ContactPoint"] = "ContactPoint";
880
+ PropertyType["Contributor"] = "Contributor";
881
+ PropertyType["Count"] = "Count";
882
+ PropertyType["DataRequirement"] = "DataRequirement";
883
+ PropertyType["Distance"] = "Distance";
884
+ PropertyType["Dosage"] = "Dosage";
885
+ PropertyType["Duration"] = "Duration";
886
+ PropertyType["Expression"] = "Expression";
887
+ PropertyType["Extension"] = "Extension";
888
+ PropertyType["HumanName"] = "HumanName";
889
+ PropertyType["Identifier"] = "Identifier";
890
+ PropertyType["MarketingStatus"] = "MarketingStatus";
891
+ PropertyType["Meta"] = "Meta";
892
+ PropertyType["Money"] = "Money";
893
+ PropertyType["Narrative"] = "Narrative";
894
+ PropertyType["ParameterDefinition"] = "ParameterDefinition";
895
+ PropertyType["Period"] = "Period";
896
+ PropertyType["Population"] = "Population";
897
+ PropertyType["ProdCharacteristic"] = "ProdCharacteristic";
898
+ PropertyType["ProductShelfLife"] = "ProductShelfLife";
899
+ PropertyType["Quantity"] = "Quantity";
900
+ PropertyType["Range"] = "Range";
901
+ PropertyType["Ratio"] = "Ratio";
902
+ PropertyType["Reference"] = "Reference";
903
+ PropertyType["RelatedArtifact"] = "RelatedArtifact";
904
+ PropertyType["Resource"] = "Resource";
905
+ PropertyType["SampledData"] = "SampledData";
906
+ PropertyType["Signature"] = "Signature";
907
+ PropertyType["SubstanceAmount"] = "SubstanceAmount";
908
+ PropertyType["SystemString"] = "http://hl7.org/fhirpath/System.String";
909
+ PropertyType["Timing"] = "Timing";
910
+ PropertyType["TriggerDefinition"] = "TriggerDefinition";
911
+ PropertyType["UsageContext"] = "UsageContext";
912
+ PropertyType["base64Binary"] = "base64Binary";
913
+ PropertyType["boolean"] = "boolean";
914
+ PropertyType["canonical"] = "canonical";
915
+ PropertyType["code"] = "code";
916
+ PropertyType["date"] = "date";
917
+ PropertyType["dateTime"] = "dateTime";
918
+ PropertyType["decimal"] = "decimal";
919
+ PropertyType["id"] = "id";
920
+ PropertyType["instant"] = "instant";
921
+ PropertyType["integer"] = "integer";
922
+ PropertyType["markdown"] = "markdown";
923
+ PropertyType["oid"] = "oid";
924
+ PropertyType["positiveInt"] = "positiveInt";
925
+ PropertyType["string"] = "string";
926
+ PropertyType["time"] = "time";
927
+ PropertyType["unsignedInt"] = "unsignedInt";
928
+ PropertyType["uri"] = "uri";
929
+ PropertyType["url"] = "url";
930
+ PropertyType["uuid"] = "uuid";
931
+ })(PropertyType || (PropertyType = {}));
932
+ /**
933
+ * Creates a new empty IndexedStructureDefinition.
934
+ * @returns The empty IndexedStructureDefinition.
935
+ */
936
+ function createSchema() {
937
+ return { types: {} };
938
+ }
939
+ /**
940
+ * Indexes a StructureDefinition for fast lookup.
941
+ * See comments on IndexedStructureDefinition for more details.
942
+ * @param schema The output IndexedStructureDefinition.
943
+ * @param structureDefinition The original StructureDefinition.
944
+ */
945
+ function indexStructureDefinition(schema, structureDefinition) {
946
+ var _a;
947
+ const typeName = structureDefinition.name;
948
+ if (!typeName) {
949
+ return;
950
+ }
951
+ schema.types[typeName] = {
952
+ display: typeName,
953
+ description: structureDefinition.description,
954
+ properties: {},
955
+ };
956
+ const elements = (_a = structureDefinition.snapshot) === null || _a === void 0 ? void 0 : _a.element;
957
+ if (elements) {
958
+ // Filter out any elements missing path or type
959
+ const filtered = elements.filter((e) => e.path !== typeName && e.path);
960
+ // First pass, build types
961
+ filtered.forEach((element) => indexType(schema, element));
962
+ // Second pass, build properties
963
+ filtered.forEach((element) => indexProperty(schema, element));
964
+ }
965
+ }
966
+ /**
967
+ * Indexes TypeSchema from an ElementDefinition.
968
+ * In the common case, there will be many ElementDefinition instances per TypeSchema.
969
+ * Only the first occurrence is saved.
970
+ * @param schema The output IndexedStructureDefinition.
971
+ * @param element The input ElementDefinition.
972
+ */
973
+ function indexType(schema, element) {
974
+ var _a, _b;
975
+ const path = element.path;
976
+ const typeCode = (_b = (_a = element.type) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.code;
977
+ if (typeCode !== 'Element' && typeCode !== 'BackboneElement') {
978
+ return;
979
+ }
980
+ const parts = path.split('.');
981
+ const typeName = buildTypeName(parts);
982
+ if (!(typeName in schema.types)) {
983
+ schema.types[typeName] = {
984
+ display: typeName,
985
+ description: element.definition,
986
+ parentType: buildTypeName(parts.slice(0, parts.length - 1)),
987
+ properties: {},
988
+ };
989
+ }
990
+ }
991
+ /**
992
+ * Indexes PropertySchema from an ElementDefinition.
993
+ * @param schema The output IndexedStructureDefinition.
994
+ * @param element The input ElementDefinition.
995
+ */
996
+ function indexProperty(schema, element) {
997
+ const path = element.path;
998
+ const parts = path.split('.');
999
+ if (parts.length === 1) {
1000
+ return;
1001
+ }
1002
+ const typeName = buildTypeName(parts.slice(0, parts.length - 1));
1003
+ const typeSchema = schema.types[typeName];
1004
+ const key = parts[parts.length - 1];
1005
+ typeSchema.properties[key] = element;
1006
+ }
1007
+ /**
1008
+ * Indexes a SearchParameter resource for fast lookup.
1009
+ * Indexes by SearchParameter.code, which is the query string parameter name.
1010
+ * @param schema The output IndexedStructureDefinition.
1011
+ * @param searchParam The SearchParameter resource.
1012
+ */
1013
+ function indexSearchParameter(schema, searchParam) {
1014
+ if (!searchParam.base) {
1015
+ return;
1016
+ }
1017
+ for (const resourceType of searchParam.base) {
1018
+ const typeSchema = schema.types[resourceType];
1019
+ if (!typeSchema) {
1020
+ continue;
1021
+ }
1022
+ if (!typeSchema.searchParams) {
1023
+ typeSchema.searchParams = {};
1024
+ }
1025
+ typeSchema.searchParams[searchParam.code] = searchParam;
1026
+ }
1027
+ }
1028
+ function buildTypeName(components) {
1029
+ return components.map(capitalize).join('');
1030
+ }
1031
+ function getPropertyDisplayName(property) {
1032
+ // Get the property name, which is the remainder after the last period
1033
+ // For example, for path "Patient.birthDate"
1034
+ // the property name is "birthDate"
1035
+ const propertyName = property.path.replaceAll('[x]', '').split('.').pop();
1036
+ // Split by capital letters
1037
+ // Capitalize the first letter of each word
1038
+ // Join together with spaces in between
1039
+ // Then normalize whitespace to single space character
1040
+ // For example, for property name "birthDate",
1041
+ // the display name is "Birth Date".
1042
+ return propertyName
1043
+ .split(/(?=[A-Z])/)
1044
+ .map(capitalize)
1045
+ .join(' ')
1046
+ .replace('_', ' ')
1047
+ .replace(/\s+/g, ' ');
1048
+ }
1049
+
1050
+ // PKCE auth ased on:
1051
+ // https://aws.amazon.com/blogs/security/how-to-add-authentication-single-page-web-application-with-amazon-cognito-oauth2-implementation/
1052
+ var _MedplumClient_instances, _MedplumClient_fetch, _MedplumClient_storage, _MedplumClient_schema, _MedplumClient_resourceCache, _MedplumClient_baseUrl, _MedplumClient_clientId, _MedplumClient_authorizeUrl, _MedplumClient_tokenUrl, _MedplumClient_logoutUrl, _MedplumClient_onUnauthenticated, _MedplumClient_accessToken, _MedplumClient_refreshToken, _MedplumClient_refreshPromise, _MedplumClient_profilePromise, _MedplumClient_profile, _MedplumClient_config, _MedplumClient_addLogin, _MedplumClient_refreshProfile, _MedplumClient_request, _MedplumClient_buildFetchOptions, _MedplumClient_handleUnauthenticated, _MedplumClient_startPkce, _MedplumClient_requestAuthorization, _MedplumClient_refresh, _MedplumClient_fetchTokens, _MedplumClient_verifyTokens, _MedplumClient_setupStorageListener;
1053
+ const DEFAULT_BASE_URL = 'https://api.medplum.com/';
1054
+ const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
1055
+ const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
1056
+ const JSON_CONTENT_TYPE = 'application/json';
1057
+ const FHIR_CONTENT_TYPE = 'application/fhir+json';
1058
+ const PATCH_CONTENT_TYPE = 'application/json-patch+json';
1059
+ class MedplumClient extends EventTarget {
1060
+ constructor(options) {
1061
+ var _a;
1062
+ super();
1063
+ _MedplumClient_instances.add(this);
1064
+ _MedplumClient_fetch.set(this, void 0);
1065
+ _MedplumClient_storage.set(this, void 0);
1066
+ _MedplumClient_schema.set(this, void 0);
1067
+ _MedplumClient_resourceCache.set(this, void 0);
1068
+ _MedplumClient_baseUrl.set(this, void 0);
1069
+ _MedplumClient_clientId.set(this, void 0);
1070
+ _MedplumClient_authorizeUrl.set(this, void 0);
1071
+ _MedplumClient_tokenUrl.set(this, void 0);
1072
+ _MedplumClient_logoutUrl.set(this, void 0);
1073
+ _MedplumClient_onUnauthenticated.set(this, void 0);
1074
+ _MedplumClient_accessToken.set(this, void 0);
1075
+ _MedplumClient_refreshToken.set(this, void 0);
1076
+ _MedplumClient_refreshPromise.set(this, void 0);
1077
+ _MedplumClient_profilePromise.set(this, void 0);
1078
+ _MedplumClient_profile.set(this, void 0);
1079
+ _MedplumClient_config.set(this, void 0);
1080
+ if (options === null || options === void 0 ? void 0 : options.baseUrl) {
1081
+ if (!options.baseUrl.startsWith('http')) {
1082
+ throw new Error('Base URL must start with http or https');
1083
+ }
1084
+ if (!options.baseUrl.endsWith('/')) {
1085
+ throw new Error('Base URL must end with a trailing slash');
1086
+ }
1087
+ }
1088
+ __classPrivateFieldSet(this, _MedplumClient_fetch, (options === null || options === void 0 ? void 0 : options.fetch) || window.fetch.bind(window), "f");
1089
+ __classPrivateFieldSet(this, _MedplumClient_storage, new ClientStorage(), "f");
1090
+ __classPrivateFieldSet(this, _MedplumClient_schema, createSchema(), "f");
1091
+ __classPrivateFieldSet(this, _MedplumClient_resourceCache, new LRUCache((_a = options === null || options === void 0 ? void 0 : options.resourceCacheSize) !== null && _a !== void 0 ? _a : DEFAULT_RESOURCE_CACHE_SIZE), "f");
1092
+ __classPrivateFieldSet(this, _MedplumClient_baseUrl, (options === null || options === void 0 ? void 0 : options.baseUrl) || DEFAULT_BASE_URL, "f");
1093
+ __classPrivateFieldSet(this, _MedplumClient_clientId, (options === null || options === void 0 ? void 0 : options.clientId) || '', "f");
1094
+ __classPrivateFieldSet(this, _MedplumClient_authorizeUrl, (options === null || options === void 0 ? void 0 : options.authorizeUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/authorize', "f");
1095
+ __classPrivateFieldSet(this, _MedplumClient_tokenUrl, (options === null || options === void 0 ? void 0 : options.tokenUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/token', "f");
1096
+ __classPrivateFieldSet(this, _MedplumClient_logoutUrl, (options === null || options === void 0 ? void 0 : options.logoutUrl) || __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + 'oauth2/logout', "f");
1097
+ __classPrivateFieldSet(this, _MedplumClient_onUnauthenticated, options === null || options === void 0 ? void 0 : options.onUnauthenticated, "f");
1098
+ const activeLogin = this.getActiveLogin();
1099
+ if (activeLogin) {
1100
+ __classPrivateFieldSet(this, _MedplumClient_accessToken, activeLogin.accessToken, "f");
1101
+ __classPrivateFieldSet(this, _MedplumClient_refreshToken, activeLogin.refreshToken, "f");
1102
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this).catch(console.log);
1103
+ }
1104
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_setupStorageListener).call(this);
1105
+ }
1106
+ /**
1107
+ * Clears all auth state including local storage and session storage.
1108
+ */
1109
+ clear() {
1110
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").clear();
1111
+ __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").clear();
1112
+ __classPrivateFieldSet(this, _MedplumClient_accessToken, undefined, "f");
1113
+ __classPrivateFieldSet(this, _MedplumClient_refreshToken, undefined, "f");
1114
+ __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
1115
+ __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
1116
+ this.dispatchEvent({ type: 'change' });
1117
+ }
1118
+ get(url) {
1119
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'GET', url);
1120
+ }
1121
+ post(url, body, contentType) {
1122
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'POST', url, contentType, body);
1123
+ }
1124
+ put(url, body, contentType) {
1125
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PUT', url, contentType, body);
1126
+ }
1127
+ delete(url) {
1128
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'DELETE', url);
1129
+ }
1130
+ /**
1131
+ * Tries to register a new user.
1132
+ * @param request The registration request.
1133
+ * @returns Promise to the authentication response.
1134
+ */
1135
+ register(request) {
1136
+ return __awaiter(this, void 0, void 0, function* () {
1137
+ const response = yield this.post('auth/register', request);
1138
+ yield this.setActiveLogin(response);
1139
+ });
1140
+ }
1141
+ /**
1142
+ * Initiates a user login flow.
1143
+ * @param email The email address of the user.
1144
+ * @param password The password of the user.
1145
+ * @param remember Optional flag to remember the user.
1146
+ * @returns Promise to the authentication response.
1147
+ */
1148
+ startLogin(email, password, remember) {
1149
+ return __awaiter(this, void 0, void 0, function* () {
1150
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1151
+ return this.post('auth/login', {
1152
+ clientId: __classPrivateFieldGet(this, _MedplumClient_clientId, "f"),
1153
+ scope: DEFAULT_SCOPE,
1154
+ codeChallengeMethod: 'S256',
1155
+ codeChallenge: __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge'),
1156
+ email,
1157
+ password,
1158
+ remember: !!remember,
1159
+ });
1160
+ });
1161
+ }
1162
+ /**
1163
+ * Tries to sign in with Google authentication.
1164
+ * The response parameter is the result of a Google authentication.
1165
+ * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
1166
+ * @param googleResponse The Google credential response.
1167
+ * @returns Promise to the authentication response.
1168
+ */
1169
+ startGoogleLogin(googleResponse) {
1170
+ return __awaiter(this, void 0, void 0, function* () {
1171
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1172
+ return this.post('auth/google', googleResponse);
1173
+ });
1174
+ }
1175
+ /**
1176
+ * Signs out locally.
1177
+ * Does not invalidate tokens with the server.
1178
+ */
1179
+ signOut() {
1180
+ this.clear();
1181
+ return Promise.resolve();
1182
+ }
1183
+ /**
1184
+ * Tries to sign in the user.
1185
+ * Returns true if the user is signed in.
1186
+ * This may result in navigating away to the sign in page.
1187
+ */
1188
+ signInWithRedirect() {
1189
+ const urlParams = new URLSearchParams(window.location.search);
1190
+ const code = urlParams.get('code');
1191
+ if (!code) {
1192
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_requestAuthorization).call(this);
1193
+ return undefined;
1194
+ }
1195
+ else {
1196
+ return this.processCode(code);
1197
+ }
1198
+ }
1199
+ /**
1200
+ * Tries to sign out the user.
1201
+ * See: https://docs.aws.amazon.com/cognito/latest/developerguide/logout-endpoint.html
1202
+ */
1203
+ signOutWithRedirect() {
1204
+ window.location.assign(__classPrivateFieldGet(this, _MedplumClient_logoutUrl, "f"));
1205
+ }
1206
+ /**
1207
+ * Builds a FHIR URL from a collection of URL path components.
1208
+ * For example, `buildUrl('/Patient', '123')` returns `fhir/R4/Patient/123`.
1209
+ * @param path The path component of the URL.
1210
+ * @returns The well-formed FHIR URL.
1211
+ */
1212
+ fhirUrl(...path) {
1213
+ const builder = [__classPrivateFieldGet(this, _MedplumClient_baseUrl, "f"), 'fhir/R4'];
1214
+ path.forEach((p) => builder.push('/', encodeURIComponent(p)));
1215
+ return builder.join('');
1216
+ }
1217
+ /**
1218
+ * Sends a FHIR search request.
1219
+ * @param search The search query.
1220
+ * @returns Promise to the search result bundle.
1221
+ */
1222
+ search(search) {
1223
+ return this.get(this.fhirUrl(search.resourceType) + formatSearchQuery(search));
1224
+ }
1225
+ /**
1226
+ * Searches a ValueSet resource using the "expand" operation.
1227
+ * See: https://www.hl7.org/fhir/operation-valueset-expand.html
1228
+ * @param system The ValueSet system url.
1229
+ * @param filter The search string.
1230
+ * @returns Promise to expanded ValueSet.
1231
+ */
1232
+ searchValueSet(system, filter) {
1233
+ return this.get(this.fhirUrl('ValueSet', '$expand') +
1234
+ `?url=${encodeURIComponent(system)}` +
1235
+ `&filter=${encodeURIComponent(filter)}`);
1236
+ }
1237
+ /**
1238
+ * Returns a cached resource if it is available.
1239
+ * @param resourceType The FHIR resource type.
1240
+ * @param id The FHIR resource ID.
1241
+ * @returns The resource if it is available in the cache; undefined otherwise.
1242
+ */
1243
+ getCached(resourceType, id) {
1244
+ const cached = __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").get(resourceType + '/' + id);
1245
+ if (cached && !('then' in cached)) {
1246
+ return cached;
1247
+ }
1248
+ return undefined;
1249
+ }
1250
+ /**
1251
+ * Returns a cached resource if it is available.
1252
+ * @param resourceType The FHIR resource type.
1253
+ * @param id The FHIR resource ID.
1254
+ * @returns The resource if it is available in the cache; undefined otherwise.
1255
+ */
1256
+ getCachedReference(reference) {
1257
+ const cached = __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").get(reference.reference);
1258
+ if (cached && !('then' in cached)) {
1259
+ return cached;
1260
+ }
1261
+ return undefined;
1262
+ }
1263
+ read(resourceType, id) {
1264
+ const cacheKey = resourceType + '/' + id;
1265
+ const promise = this.get(this.fhirUrl(resourceType, id)).then((resource) => {
1266
+ __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, resource);
1267
+ return resource;
1268
+ });
1269
+ __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").set(cacheKey, promise);
1270
+ return promise;
1271
+ }
1272
+ readCached(resourceType, id) {
1273
+ const cached = __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").get(resourceType + '/' + id);
1274
+ return cached ? Promise.resolve(cached) : this.read(resourceType, id);
1275
+ }
1276
+ readReference(reference) {
1277
+ const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
1278
+ if (!refString) {
1279
+ return Promise.reject('Missing reference');
1280
+ }
1281
+ const [resourceType, id] = refString.split('/');
1282
+ return this.read(resourceType, id);
1283
+ }
1284
+ readCachedReference(reference) {
1285
+ const refString = reference === null || reference === void 0 ? void 0 : reference.reference;
1286
+ if (!refString) {
1287
+ return Promise.reject('Missing reference');
1288
+ }
1289
+ const [resourceType, id] = refString.split('/');
1290
+ return this.readCached(resourceType, id);
1291
+ }
1292
+ /**
1293
+ * Returns a cached schema for a resource type.
1294
+ * If the schema is not cached, returns undefined.
1295
+ * It is assumed that a client will call requestSchema before using this method.
1296
+ * @param resourceType The FHIR resource type.
1297
+ * @returns The schema if immediately available, undefined otherwise.
1298
+ */
1299
+ getSchema() {
1300
+ return __classPrivateFieldGet(this, _MedplumClient_schema, "f");
1301
+ }
1302
+ /**
1303
+ * Requests the schema for a resource type.
1304
+ * If the schema is already cached, the promise is resolved immediately.
1305
+ * @param resourceType The FHIR resource type.
1306
+ * @returns Promise to a schema with the requested resource type.
1307
+ */
1308
+ requestSchema(resourceType) {
1309
+ return __awaiter(this, void 0, void 0, function* () {
1310
+ if (resourceType in __classPrivateFieldGet(this, _MedplumClient_schema, "f").types) {
1311
+ return Promise.resolve(__classPrivateFieldGet(this, _MedplumClient_schema, "f"));
1312
+ }
1313
+ const query = `{
1314
+ StructureDefinitionList(name: "${encodeURIComponent(resourceType)}") {
1315
+ name,
1316
+ description,
1317
+ snapshot {
1318
+ element {
1319
+ id,
1320
+ path,
1321
+ min,
1322
+ max,
1323
+ type {
1324
+ code,
1325
+ targetProfile
1326
+ },
1327
+ binding {
1328
+ valueSet
1329
+ },
1330
+ definition
1331
+ }
1332
+ }
1333
+ }
1334
+ SearchParameterList(base: "${encodeURIComponent(resourceType)}") {
1335
+ base,
1336
+ code,
1337
+ type
1338
+ }
1339
+ }`.replace(/\s+/g, ' ');
1340
+ const response = (yield this.graphql(query));
1341
+ for (const structureDefinition of response.data.StructureDefinitionList) {
1342
+ indexStructureDefinition(__classPrivateFieldGet(this, _MedplumClient_schema, "f"), structureDefinition);
1343
+ }
1344
+ for (const searchParameter of response.data.SearchParameterList) {
1345
+ indexSearchParameter(__classPrivateFieldGet(this, _MedplumClient_schema, "f"), searchParameter);
1346
+ }
1347
+ return __classPrivateFieldGet(this, _MedplumClient_schema, "f");
1348
+ });
1349
+ }
1350
+ readHistory(resourceType, id) {
1351
+ return this.get(this.fhirUrl(resourceType, id, '_history'));
1352
+ }
1353
+ readPatientEverything(id) {
1354
+ return this.get(this.fhirUrl('Patient', id, '$everything'));
1355
+ }
1356
+ create(resource) {
1357
+ if (!resource.resourceType) {
1358
+ throw new Error('Missing resourceType');
1359
+ }
1360
+ return this.post(this.fhirUrl(resource.resourceType), resource);
1361
+ }
1362
+ createBinary(data, filename, contentType) {
1363
+ return this.post(this.fhirUrl('Binary') + '?_filename=' + encodeURIComponent(filename), data, contentType);
1364
+ }
1365
+ update(resource) {
1366
+ if (!resource.resourceType) {
1367
+ throw new Error('Missing resourceType');
1368
+ }
1369
+ if (!resource.id) {
1370
+ throw new Error('Missing id');
1371
+ }
1372
+ return this.put(this.fhirUrl(resource.resourceType, resource.id), resource);
1373
+ }
1374
+ patch(resourceType, id, operations) {
1375
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, 'PATCH', this.fhirUrl(resourceType, id), PATCH_CONTENT_TYPE, operations);
1376
+ }
1377
+ deleteResource(resourceType, id) {
1378
+ return this.delete(this.fhirUrl(resourceType, id));
1379
+ }
1380
+ graphql(query) {
1381
+ return this.post(this.fhirUrl('$graphql'), { query }, JSON_CONTENT_TYPE);
1382
+ }
1383
+ getActiveLogin() {
1384
+ return __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('activeLogin');
1385
+ }
1386
+ setActiveLogin(login) {
1387
+ return __awaiter(this, void 0, void 0, function* () {
1388
+ __classPrivateFieldSet(this, _MedplumClient_accessToken, login.accessToken, "f");
1389
+ __classPrivateFieldSet(this, _MedplumClient_refreshToken, login.refreshToken, "f");
1390
+ __classPrivateFieldSet(this, _MedplumClient_profile, undefined, "f");
1391
+ __classPrivateFieldSet(this, _MedplumClient_config, undefined, "f");
1392
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('activeLogin', login);
1393
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_addLogin).call(this, login);
1394
+ __classPrivateFieldGet(this, _MedplumClient_resourceCache, "f").clear();
1395
+ __classPrivateFieldSet(this, _MedplumClient_refreshPromise, undefined, "f");
1396
+ yield __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refreshProfile).call(this);
1397
+ });
1398
+ }
1399
+ getLogins() {
1400
+ var _a;
1401
+ return (_a = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getObject('logins')) !== null && _a !== void 0 ? _a : [];
1402
+ }
1403
+ isLoading() {
1404
+ return !!__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
1405
+ }
1406
+ getProfile() {
1407
+ return __classPrivateFieldGet(this, _MedplumClient_profile, "f");
1408
+ }
1409
+ getProfileAsync() {
1410
+ return __awaiter(this, void 0, void 0, function* () {
1411
+ if (__classPrivateFieldGet(this, _MedplumClient_profilePromise, "f")) {
1412
+ yield __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
1413
+ }
1414
+ return this.getProfile();
1415
+ });
1416
+ }
1417
+ getUserConfiguration() {
1418
+ return __classPrivateFieldGet(this, _MedplumClient_config, "f");
1419
+ }
1420
+ /**
1421
+ * Downloads the URL as a blob.
1422
+ * @param url The URL to request.
1423
+ * @returns Promise to the response body as a blob.
1424
+ */
1425
+ download(url) {
1426
+ return __awaiter(this, void 0, void 0, function* () {
1427
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
1428
+ yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
1429
+ }
1430
+ const options = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_buildFetchOptions).call(this, 'GET');
1431
+ const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
1432
+ return response.blob();
1433
+ });
1434
+ }
1435
+ /**
1436
+ * Processes an OAuth authorization code.
1437
+ * See: https://openid.net/specs/openid-connect-core-1_0.html#TokenRequest
1438
+ * @param code The authorization code received by URL parameter.
1439
+ */
1440
+ processCode(code) {
1441
+ const pkceState = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState');
1442
+ if (!pkceState) {
1443
+ this.clear();
1444
+ throw new Error('Invalid PCKE state');
1445
+ }
1446
+ const codeVerifier = __classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeVerifier');
1447
+ if (!codeVerifier) {
1448
+ this.clear();
1449
+ throw new Error('Invalid PCKE code verifier');
1450
+ }
1451
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=authorization_code' +
1452
+ (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") ? '&client_id=' + encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) : '') +
1453
+ '&code_verifier=' +
1454
+ encodeURIComponent(codeVerifier) +
1455
+ '&redirect_uri=' +
1456
+ encodeURIComponent(getBaseUrl()) +
1457
+ '&code=' +
1458
+ encodeURIComponent(code));
1459
+ }
1460
+ }
1461
+ _MedplumClient_fetch = new WeakMap(), _MedplumClient_storage = new WeakMap(), _MedplumClient_schema = new WeakMap(), _MedplumClient_resourceCache = new WeakMap(), _MedplumClient_baseUrl = new WeakMap(), _MedplumClient_clientId = new WeakMap(), _MedplumClient_authorizeUrl = new WeakMap(), _MedplumClient_tokenUrl = new WeakMap(), _MedplumClient_logoutUrl = new WeakMap(), _MedplumClient_onUnauthenticated = new WeakMap(), _MedplumClient_accessToken = new WeakMap(), _MedplumClient_refreshToken = new WeakMap(), _MedplumClient_refreshPromise = new WeakMap(), _MedplumClient_profilePromise = new WeakMap(), _MedplumClient_profile = new WeakMap(), _MedplumClient_config = new WeakMap(), _MedplumClient_instances = new WeakSet(), _MedplumClient_addLogin = function _MedplumClient_addLogin(newLogin) {
1462
+ const logins = this.getLogins().filter((login) => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.reference) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.reference); });
1463
+ logins.push(newLogin);
1464
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setObject('logins', logins);
1465
+ }, _MedplumClient_refreshProfile = function _MedplumClient_refreshProfile() {
1466
+ return __awaiter(this, void 0, void 0, function* () {
1467
+ __classPrivateFieldSet(this, _MedplumClient_profilePromise, new Promise((resolve, reject) => {
1468
+ this.get('auth/me')
1469
+ .then((result) => {
1470
+ __classPrivateFieldSet(this, _MedplumClient_profilePromise, undefined, "f");
1471
+ __classPrivateFieldSet(this, _MedplumClient_profile, result.profile, "f");
1472
+ __classPrivateFieldSet(this, _MedplumClient_config, result.config, "f");
1473
+ this.dispatchEvent({ type: 'change' });
1474
+ resolve(__classPrivateFieldGet(this, _MedplumClient_profile, "f"));
1475
+ })
1476
+ .catch(reject);
1477
+ }), "f");
1478
+ return __classPrivateFieldGet(this, _MedplumClient_profilePromise, "f");
1479
+ });
1480
+ }, _MedplumClient_request = function _MedplumClient_request(method, url, contentType, body) {
1481
+ return __awaiter(this, void 0, void 0, function* () {
1482
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
1483
+ yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
1484
+ }
1485
+ if (!url.startsWith('http')) {
1486
+ url = __classPrivateFieldGet(this, _MedplumClient_baseUrl, "f") + url;
1487
+ }
1488
+ const options = __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_buildFetchOptions).call(this, method, contentType, body);
1489
+ const response = yield __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, url, options);
1490
+ if (response.status === 401) {
1491
+ // Refresh and try again
1492
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_handleUnauthenticated).call(this, method, url, contentType, body);
1493
+ }
1494
+ if (response.status === 204 || response.status === 304) {
1495
+ // No content or change
1496
+ return undefined;
1497
+ }
1498
+ const obj = yield response.json();
1499
+ if (obj.resourceType === 'OperationOutcome' && !isOk(obj)) {
1500
+ return Promise.reject(obj);
1501
+ }
1502
+ return obj;
1503
+ });
1504
+ }, _MedplumClient_buildFetchOptions = function _MedplumClient_buildFetchOptions(method, contentType, body) {
1505
+ const headers = {
1506
+ 'Content-Type': contentType || FHIR_CONTENT_TYPE,
1507
+ };
1508
+ if (__classPrivateFieldGet(this, _MedplumClient_accessToken, "f")) {
1509
+ headers['Authorization'] = 'Bearer ' + __classPrivateFieldGet(this, _MedplumClient_accessToken, "f");
1510
+ }
1511
+ const options = {
1512
+ method: method,
1513
+ cache: 'no-cache',
1514
+ credentials: 'include',
1515
+ headers,
1516
+ };
1517
+ if (body) {
1518
+ if (typeof body === 'string' || (typeof File !== 'undefined' && body instanceof File)) {
1519
+ options.body = body;
1520
+ }
1521
+ else {
1522
+ options.body = stringify(body);
1523
+ }
1524
+ }
1525
+ return options;
1526
+ }, _MedplumClient_handleUnauthenticated = function _MedplumClient_handleUnauthenticated(method, url, contentType, body) {
1527
+ return __awaiter(this, void 0, void 0, function* () {
1528
+ return __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_refresh).call(this)
1529
+ .then(() => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_request).call(this, method, url, contentType, body))
1530
+ .catch((error) => {
1531
+ this.clear();
1532
+ if (__classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f")) {
1533
+ __classPrivateFieldGet(this, _MedplumClient_onUnauthenticated, "f").call(this);
1534
+ }
1535
+ return Promise.reject(error);
1536
+ });
1537
+ });
1538
+ }, _MedplumClient_startPkce = function _MedplumClient_startPkce() {
1539
+ return __awaiter(this, void 0, void 0, function* () {
1540
+ const pkceState = getRandomString();
1541
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('pkceState', pkceState);
1542
+ const codeVerifier = getRandomString();
1543
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeVerifier', codeVerifier);
1544
+ const arrayHash = yield encryptSHA256(codeVerifier);
1545
+ const codeChallenge = arrayBufferToBase64(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1546
+ __classPrivateFieldGet(this, _MedplumClient_storage, "f").setString('codeChallenge', codeChallenge);
1547
+ });
1548
+ }, _MedplumClient_requestAuthorization = function _MedplumClient_requestAuthorization() {
1549
+ return __awaiter(this, void 0, void 0, function* () {
1550
+ if (!__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f")) {
1551
+ throw new Error('Missing authorize URL');
1552
+ }
1553
+ __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_startPkce).call(this);
1554
+ window.location.assign(__classPrivateFieldGet(this, _MedplumClient_authorizeUrl, "f") +
1555
+ '?response_type=code' +
1556
+ '&state=' +
1557
+ encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('pkceState')) +
1558
+ '&client_id=' +
1559
+ encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) +
1560
+ '&redirect_uri=' +
1561
+ encodeURIComponent(getBaseUrl()) +
1562
+ '&scope=' +
1563
+ encodeURIComponent(DEFAULT_SCOPE) +
1564
+ '&code_challenge_method=S256' +
1565
+ '&code_challenge=' +
1566
+ encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_storage, "f").getString('codeChallenge')));
1567
+ });
1568
+ }, _MedplumClient_refresh = function _MedplumClient_refresh() {
1569
+ return __awaiter(this, void 0, void 0, function* () {
1570
+ if (__classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f")) {
1571
+ return __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
1572
+ }
1573
+ if (!__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f")) {
1574
+ this.clear();
1575
+ return Promise.reject('Invalid refresh token');
1576
+ }
1577
+ __classPrivateFieldSet(this, _MedplumClient_refreshPromise, __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_fetchTokens).call(this, 'grant_type=refresh_token' +
1578
+ '&client_id=' +
1579
+ encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_clientId, "f")) +
1580
+ '&refresh_token=' +
1581
+ encodeURIComponent(__classPrivateFieldGet(this, _MedplumClient_refreshToken, "f"))), "f");
1582
+ yield __classPrivateFieldGet(this, _MedplumClient_refreshPromise, "f");
1583
+ });
1584
+ }, _MedplumClient_fetchTokens = function _MedplumClient_fetchTokens(formBody) {
1585
+ return __awaiter(this, void 0, void 0, function* () {
1586
+ if (!__classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f")) {
1587
+ return Promise.reject('Missing token URL');
1588
+ }
1589
+ return __classPrivateFieldGet(this, _MedplumClient_fetch, "f").call(this, __classPrivateFieldGet(this, _MedplumClient_tokenUrl, "f"), {
1590
+ method: 'POST',
1591
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1592
+ body: formBody,
1593
+ })
1594
+ .then((response) => {
1595
+ if (!response.ok) {
1596
+ return Promise.reject('Failed to fetch tokens');
1597
+ }
1598
+ return response.json();
1599
+ })
1600
+ .then((tokens) => __classPrivateFieldGet(this, _MedplumClient_instances, "m", _MedplumClient_verifyTokens).call(this, tokens))
1601
+ .then(() => this.getProfile());
1602
+ });
1603
+ }, _MedplumClient_verifyTokens = function _MedplumClient_verifyTokens(tokens) {
1604
+ return __awaiter(this, void 0, void 0, function* () {
1605
+ const token = tokens.access_token;
1606
+ // Verify token has not expired
1607
+ const tokenPayload = parseJWTPayload(token);
1608
+ if (Date.now() >= tokenPayload.exp * 1000) {
1609
+ this.clear();
1610
+ return Promise.reject('Token expired');
1611
+ }
1612
+ // Verify app_client_id
1613
+ if (__classPrivateFieldGet(this, _MedplumClient_clientId, "f") && tokenPayload.client_id !== __classPrivateFieldGet(this, _MedplumClient_clientId, "f")) {
1614
+ this.clear();
1615
+ return Promise.reject('Token was not issued for this audience');
1616
+ }
1617
+ yield this.setActiveLogin({
1618
+ accessToken: token,
1619
+ refreshToken: tokens.refresh_token,
1620
+ project: tokens.project,
1621
+ profile: tokens.profile,
1622
+ });
1623
+ });
1624
+ }, _MedplumClient_setupStorageListener = function _MedplumClient_setupStorageListener() {
1625
+ try {
1626
+ window.addEventListener('storage', (e) => {
1627
+ if (e.key === null || e.key === 'activeLogin') {
1628
+ // Storage events fire when different tabs make changes.
1629
+ // On storage clear (key === null) or activeLogin change (key === 'activeLogin')
1630
+ // Refresh the page to ensure the active login is up to date.
1631
+ window.location.reload();
1632
+ }
1633
+ });
1634
+ }
1635
+ catch (err) {
1636
+ // Silently ignore if this environment does not support storage events
1637
+ }
1638
+ };
1639
+ /**
1640
+ * Returns the base URL for the current page.
1641
+ */
1642
+ function getBaseUrl() {
1643
+ return window.location.protocol + '//' + window.location.host + '/';
1644
+ }
1645
+
1646
+ var SearchParameterType;
1647
+ (function (SearchParameterType) {
1648
+ SearchParameterType["BOOLEAN"] = "BOOLEAN";
1649
+ SearchParameterType["NUMBER"] = "NUMBER";
1650
+ SearchParameterType["QUANTITY"] = "QUANTITY";
1651
+ SearchParameterType["TEXT"] = "TEXT";
1652
+ SearchParameterType["REFERENCE"] = "REFERENCE";
1653
+ SearchParameterType["DATE"] = "DATE";
1654
+ SearchParameterType["DATETIME"] = "DATETIME";
1655
+ SearchParameterType["PERIOD"] = "PERIOD";
1656
+ })(SearchParameterType || (SearchParameterType = {}));
1657
+ /**
1658
+ * Returns the type details of a SearchParameter.
1659
+ *
1660
+ * The SearchParameter resource has a "type" parameter, but that is missing some critical information.
1661
+ *
1662
+ * For example:
1663
+ * 1) The "date" type includes "date", "datetime", and "period".
1664
+ * 2) The "token" type includes enums and booleans.
1665
+ * 3) Arrays/multiple values are not reflected at all.
1666
+ *
1667
+ * @param structureDefinitions Collection of StructureDefinition resources indexed by name.
1668
+ * @param resourceType The root resource type.
1669
+ * @param searchParam The search parameter.
1670
+ * @returns The search parameter type details.
1671
+ */
1672
+ function getSearchParameterDetails(structureDefinitions, resourceType, searchParam) {
1673
+ var _a, _b, _c, _d;
1674
+ const columnName = convertCodeToColumnName(searchParam.code);
1675
+ const expression = (_a = getExpressionForResourceType(resourceType, searchParam.expression)) === null || _a === void 0 ? void 0 : _a.split('.');
1676
+ if (!expression) {
1677
+ // This happens on compound types
1678
+ // In the future, explore returning multiple column definitions
1679
+ return { columnName, type: SearchParameterType.TEXT };
1680
+ }
1681
+ let baseType = resourceType;
1682
+ let propertyType = undefined;
1683
+ let array = false;
1684
+ for (let i = 1; i < expression.length; i++) {
1685
+ const propertyName = expression[i];
1686
+ const propertyDef = (_c = (_b = structureDefinitions.types[baseType]) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c[propertyName];
1687
+ if (!propertyDef) {
1688
+ // This happens on complex properties such as "collected[x]"/"collectedDateTime"/"collectedPeriod"
1689
+ // In the future, explore returning multiple column definitions
1690
+ return { columnName, type: SearchParameterType.TEXT, array };
1691
+ }
1692
+ if (propertyDef.max === '*') {
1693
+ array = true;
1694
+ }
1695
+ propertyType = (_d = propertyDef.type) === null || _d === void 0 ? void 0 : _d[0].code;
1696
+ if (!propertyType) {
1697
+ // This happens when one of parent properties uses contentReference
1698
+ // In the future, explore following the reference
1699
+ return { columnName, type: SearchParameterType.TEXT, array };
1700
+ }
1701
+ if (i < expression.length - 1) {
1702
+ if (propertyType === 'Element' || propertyType === 'BackboneElement') {
1703
+ baseType = baseType + capitalize(propertyName);
1704
+ }
1705
+ else {
1706
+ baseType = propertyType;
1707
+ }
1708
+ }
1709
+ }
1710
+ const type = getSearchParameterType(searchParam, propertyType);
1711
+ return { columnName, type, array };
1712
+ }
1713
+ /**
1714
+ * Converts a hyphen-delimited code to camelCase string.
1715
+ * @param code The search parameter code.
1716
+ * @returns The SQL column name.
1717
+ */
1718
+ function convertCodeToColumnName(code) {
1719
+ return code.split('-').reduce((result, word, index) => result + (index ? capitalize(word) : word), '');
1720
+ }
1721
+ function getSearchParameterType(searchParam, propertyType) {
1722
+ let type = SearchParameterType.TEXT;
1723
+ switch (searchParam.type) {
1724
+ case 'date':
1725
+ type = SearchParameterType.DATE;
1726
+ break;
1727
+ case 'number':
1728
+ type = SearchParameterType.NUMBER;
1729
+ break;
1730
+ case 'quantity':
1731
+ type = SearchParameterType.QUANTITY;
1732
+ break;
1733
+ case 'reference':
1734
+ type = SearchParameterType.REFERENCE;
1735
+ break;
1736
+ case 'token':
1737
+ if (propertyType === 'boolean') {
1738
+ type = SearchParameterType.BOOLEAN;
1739
+ }
1740
+ break;
1741
+ }
1742
+ return type;
1743
+ }
1744
+ function getExpressionForResourceType(resourceType, expression) {
1745
+ const expressions = expression.split(' | ');
1746
+ for (const e of expressions) {
1747
+ const simplified = simplifyExpression(e);
1748
+ if (simplified.startsWith(resourceType + '.')) {
1749
+ return simplified;
1750
+ }
1751
+ }
1752
+ return undefined;
1753
+ }
1754
+ function simplifyExpression(input) {
1755
+ let result = input.trim();
1756
+ if (result.startsWith('(') && result.endsWith(')')) {
1757
+ result = result.substring(1, result.length - 1);
1758
+ }
1759
+ if (result.includes(' as ')) {
1760
+ result = result.substring(0, result.indexOf(' as '));
1761
+ }
1762
+ if (result.includes('.where(')) {
1763
+ result = result.substring(0, result.indexOf('.where('));
1764
+ }
1765
+ return result;
1766
+ }
1767
+
1768
+ export { MedplumClient, OperationOutcomeError, Operator, PropertyType, SearchParameterType, accessDenied, allOk, arrayBufferToBase64, arrayBufferToHex, assertOk, badRequest, buildTypeName, capitalize, createReference, createSchema, created, deepEquals, formatAddress, formatFamilyName, formatGivenName, formatHumanName, formatSearchQuery, getDateProperty, getDisplayString, getExpressionForResourceType, getImageSrc, getPropertyDisplayName, getReferenceString, getSearchParameterDetails, getStatus, gone, indexSearchParameter, indexStructureDefinition, isGone, isLowerCase, isNotFound, isOk, isProfileResource, notFound, notModified, parseSearchDefinition, resolveId, stringify };
1769
+ //# sourceMappingURL=index.js.map