@medplum/core 0.2.0 → 0.4.0

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