@medplum/core 0.2.2 → 0.3.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 (640) hide show
  1. package/README.md +29 -25
  2. package/dist/cache.d.ts +1 -0
  3. package/dist/cache.js +3 -0
  4. package/dist/cache.js.map +1 -1
  5. package/dist/client.d.ts +66 -54
  6. package/dist/client.js +153 -122
  7. package/dist/client.js.map +1 -1
  8. package/dist/eventtarget.js +1 -1
  9. package/dist/eventtarget.js.map +1 -1
  10. package/dist/format.d.ts +1 -1
  11. package/dist/format.js.map +1 -1
  12. package/dist/index.d.ts +0 -2
  13. package/dist/index.js +0 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/jwt.js.map +1 -1
  16. package/dist/outcomes.d.ts +1 -1
  17. package/dist/outcomes.js +42 -28
  18. package/dist/outcomes.js.map +1 -1
  19. package/dist/search.js +4 -4
  20. package/dist/search.js.map +1 -1
  21. package/dist/searchparams.d.ts +1 -1
  22. package/dist/searchparams.js +1 -2
  23. package/dist/searchparams.js.map +1 -1
  24. package/dist/storage.js.map +1 -1
  25. package/dist/types.d.ts +1 -1
  26. package/dist/types.js +6 -6
  27. package/dist/types.js.map +1 -1
  28. package/dist/utils.d.ts +1 -1
  29. package/dist/utils.js +11 -6
  30. package/dist/utils.js.map +1 -1
  31. package/package.json +5 -6
  32. package/dist/fhir/AccessPolicy.d.ts +0 -75
  33. package/dist/fhir/AccessPolicy.js +0 -7
  34. package/dist/fhir/AccessPolicy.js.map +0 -1
  35. package/dist/fhir/Account.d.ts +0 -247
  36. package/dist/fhir/Account.js +0 -7
  37. package/dist/fhir/Account.js.map +0 -1
  38. package/dist/fhir/ActivityDefinition.d.ts +0 -500
  39. package/dist/fhir/ActivityDefinition.js +0 -7
  40. package/dist/fhir/ActivityDefinition.js.map +0 -1
  41. package/dist/fhir/Address.d.ts +0 -75
  42. package/dist/fhir/Address.js +0 -7
  43. package/dist/fhir/Address.js.map +0 -1
  44. package/dist/fhir/AdverseEvent.d.ts +0 -303
  45. package/dist/fhir/AdverseEvent.js +0 -7
  46. package/dist/fhir/AdverseEvent.js.map +0 -1
  47. package/dist/fhir/Age.d.ts +0 -47
  48. package/dist/fhir/Age.js +0 -7
  49. package/dist/fhir/Age.js.map +0 -1
  50. package/dist/fhir/AllergyIntolerance.d.ts +0 -283
  51. package/dist/fhir/AllergyIntolerance.js +0 -7
  52. package/dist/fhir/AllergyIntolerance.js.map +0 -1
  53. package/dist/fhir/Annotation.d.ts +0 -42
  54. package/dist/fhir/Annotation.js +0 -7
  55. package/dist/fhir/Annotation.js.map +0 -1
  56. package/dist/fhir/Appointment.d.ts +0 -284
  57. package/dist/fhir/Appointment.js +0 -7
  58. package/dist/fhir/Appointment.js.map +0 -1
  59. package/dist/fhir/AppointmentResponse.d.ts +0 -131
  60. package/dist/fhir/AppointmentResponse.js +0 -7
  61. package/dist/fhir/AppointmentResponse.js.map +0 -1
  62. package/dist/fhir/Attachment.d.ts +0 -58
  63. package/dist/fhir/Attachment.js +0 -7
  64. package/dist/fhir/Attachment.js.map +0 -1
  65. package/dist/fhir/AuditEvent.d.ts +0 -458
  66. package/dist/fhir/AuditEvent.js +0 -7
  67. package/dist/fhir/AuditEvent.js.map +0 -1
  68. package/dist/fhir/Basic.d.ts +0 -110
  69. package/dist/fhir/Basic.js +0 -7
  70. package/dist/fhir/Basic.js.map +0 -1
  71. package/dist/fhir/Binary.d.ts +0 -59
  72. package/dist/fhir/Binary.js +0 -7
  73. package/dist/fhir/Binary.js.map +0 -1
  74. package/dist/fhir/BiologicallyDerivedProduct.d.ts +0 -358
  75. package/dist/fhir/BiologicallyDerivedProduct.js +0 -7
  76. package/dist/fhir/BiologicallyDerivedProduct.js.map +0 -1
  77. package/dist/fhir/BodyStructure.d.ts +0 -119
  78. package/dist/fhir/BodyStructure.js +0 -7
  79. package/dist/fhir/BodyStructure.js.map +0 -1
  80. package/dist/fhir/Bot.d.ts +0 -49
  81. package/dist/fhir/Bot.js +0 -7
  82. package/dist/fhir/Bot.js.map +0 -1
  83. package/dist/fhir/Bundle.d.ts +0 -379
  84. package/dist/fhir/Bundle.js +0 -7
  85. package/dist/fhir/Bundle.js.map +0 -1
  86. package/dist/fhir/CapabilityStatement.d.ts +0 -1044
  87. package/dist/fhir/CapabilityStatement.js +0 -7
  88. package/dist/fhir/CapabilityStatement.js.map +0 -1
  89. package/dist/fhir/CarePlan.d.ts +0 -446
  90. package/dist/fhir/CarePlan.js +0 -7
  91. package/dist/fhir/CarePlan.js.map +0 -1
  92. package/dist/fhir/CareTeam.d.ts +0 -211
  93. package/dist/fhir/CareTeam.js +0 -7
  94. package/dist/fhir/CareTeam.js.map +0 -1
  95. package/dist/fhir/CatalogEntry.d.ts +0 -195
  96. package/dist/fhir/CatalogEntry.js +0 -7
  97. package/dist/fhir/CatalogEntry.js.map +0 -1
  98. package/dist/fhir/ChargeItem.d.ts +0 -287
  99. package/dist/fhir/ChargeItem.js +0 -7
  100. package/dist/fhir/ChargeItem.js.map +0 -1
  101. package/dist/fhir/ChargeItemDefinition.d.ts +0 -401
  102. package/dist/fhir/ChargeItemDefinition.js +0 -7
  103. package/dist/fhir/ChargeItemDefinition.js.map +0 -1
  104. package/dist/fhir/Claim.d.ts +0 -1092
  105. package/dist/fhir/Claim.js +0 -7
  106. package/dist/fhir/Claim.js.map +0 -1
  107. package/dist/fhir/ClaimResponse.d.ts +0 -1040
  108. package/dist/fhir/ClaimResponse.js +0 -7
  109. package/dist/fhir/ClaimResponse.js.map +0 -1
  110. package/dist/fhir/ClientApplication.d.ts +0 -46
  111. package/dist/fhir/ClientApplication.js +0 -7
  112. package/dist/fhir/ClientApplication.js.map +0 -1
  113. package/dist/fhir/ClinicalImpression.d.ts +0 -306
  114. package/dist/fhir/ClinicalImpression.js +0 -7
  115. package/dist/fhir/ClinicalImpression.js.map +0 -1
  116. package/dist/fhir/CodeSystem.d.ts +0 -541
  117. package/dist/fhir/CodeSystem.js +0 -7
  118. package/dist/fhir/CodeSystem.js.map +0 -1
  119. package/dist/fhir/CodeableConcept.d.ts +0 -33
  120. package/dist/fhir/CodeableConcept.js +0 -7
  121. package/dist/fhir/CodeableConcept.js.map +0 -1
  122. package/dist/fhir/Coding.d.ts +0 -50
  123. package/dist/fhir/Coding.js +0 -7
  124. package/dist/fhir/Coding.js.map +0 -1
  125. package/dist/fhir/Communication.d.ts +0 -264
  126. package/dist/fhir/Communication.js +0 -7
  127. package/dist/fhir/Communication.js.map +0 -1
  128. package/dist/fhir/CommunicationRequest.d.ts +0 -261
  129. package/dist/fhir/CommunicationRequest.js +0 -7
  130. package/dist/fhir/CommunicationRequest.js.map +0 -1
  131. package/dist/fhir/CompartmentDefinition.d.ts +0 -217
  132. package/dist/fhir/CompartmentDefinition.js +0 -7
  133. package/dist/fhir/CompartmentDefinition.js.map +0 -1
  134. package/dist/fhir/Composition.d.ts +0 -429
  135. package/dist/fhir/Composition.js +0 -7
  136. package/dist/fhir/Composition.js.map +0 -1
  137. package/dist/fhir/ConceptMap.d.ts +0 -518
  138. package/dist/fhir/ConceptMap.js +0 -7
  139. package/dist/fhir/ConceptMap.js.map +0 -1
  140. package/dist/fhir/Condition.d.ts +0 -326
  141. package/dist/fhir/Condition.js +0 -7
  142. package/dist/fhir/Condition.js.map +0 -1
  143. package/dist/fhir/Consent.d.ts +0 -460
  144. package/dist/fhir/Consent.js +0 -7
  145. package/dist/fhir/Consent.js.map +0 -1
  146. package/dist/fhir/ContactDetail.d.ts +0 -31
  147. package/dist/fhir/ContactDetail.js +0 -7
  148. package/dist/fhir/ContactDetail.js.map +0 -1
  149. package/dist/fhir/ContactPoint.d.ts +0 -47
  150. package/dist/fhir/ContactPoint.js +0 -7
  151. package/dist/fhir/ContactPoint.js.map +0 -1
  152. package/dist/fhir/Contract.d.ts +0 -1452
  153. package/dist/fhir/Contract.js +0 -7
  154. package/dist/fhir/Contract.js.map +0 -1
  155. package/dist/fhir/Contributor.d.ts +0 -37
  156. package/dist/fhir/Contributor.js +0 -7
  157. package/dist/fhir/Contributor.js.map +0 -1
  158. package/dist/fhir/Count.d.ts +0 -49
  159. package/dist/fhir/Count.js +0 -7
  160. package/dist/fhir/Count.js.map +0 -1
  161. package/dist/fhir/Coverage.d.ts +0 -327
  162. package/dist/fhir/Coverage.js +0 -7
  163. package/dist/fhir/Coverage.js.map +0 -1
  164. package/dist/fhir/CoverageEligibilityRequest.d.ts +0 -404
  165. package/dist/fhir/CoverageEligibilityRequest.js +0 -7
  166. package/dist/fhir/CoverageEligibilityRequest.js.map +0 -1
  167. package/dist/fhir/CoverageEligibilityResponse.d.ts +0 -434
  168. package/dist/fhir/CoverageEligibilityResponse.js +0 -7
  169. package/dist/fhir/CoverageEligibilityResponse.js.map +0 -1
  170. package/dist/fhir/DataRequirement.d.ts +0 -239
  171. package/dist/fhir/DataRequirement.js +0 -7
  172. package/dist/fhir/DataRequirement.js.map +0 -1
  173. package/dist/fhir/DetectedIssue.d.ts +0 -252
  174. package/dist/fhir/DetectedIssue.js +0 -7
  175. package/dist/fhir/DetectedIssue.js.map +0 -1
  176. package/dist/fhir/Device.d.ts +0 -493
  177. package/dist/fhir/Device.js +0 -7
  178. package/dist/fhir/Device.js.map +0 -1
  179. package/dist/fhir/DeviceDefinition.d.ts +0 -486
  180. package/dist/fhir/DeviceDefinition.js +0 -7
  181. package/dist/fhir/DeviceDefinition.js.map +0 -1
  182. package/dist/fhir/DeviceMetric.d.ts +0 -199
  183. package/dist/fhir/DeviceMetric.js +0 -7
  184. package/dist/fhir/DeviceMetric.js.map +0 -1
  185. package/dist/fhir/DeviceRequest.d.ts +0 -296
  186. package/dist/fhir/DeviceRequest.js +0 -7
  187. package/dist/fhir/DeviceRequest.js.map +0 -1
  188. package/dist/fhir/DeviceUseStatement.d.ts +0 -168
  189. package/dist/fhir/DeviceUseStatement.js +0 -7
  190. package/dist/fhir/DeviceUseStatement.js.map +0 -1
  191. package/dist/fhir/DiagnosticReport.d.ts +0 -254
  192. package/dist/fhir/DiagnosticReport.js +0 -7
  193. package/dist/fhir/DiagnosticReport.js.map +0 -1
  194. package/dist/fhir/Distance.d.ts +0 -47
  195. package/dist/fhir/Distance.js +0 -7
  196. package/dist/fhir/Distance.js.map +0 -1
  197. package/dist/fhir/DocumentManifest.d.ts +0 -196
  198. package/dist/fhir/DocumentManifest.js +0 -7
  199. package/dist/fhir/DocumentManifest.js.map +0 -1
  200. package/dist/fhir/DocumentReference.d.ts +0 -349
  201. package/dist/fhir/DocumentReference.js +0 -7
  202. package/dist/fhir/DocumentReference.js.map +0 -1
  203. package/dist/fhir/Dosage.d.ts +0 -152
  204. package/dist/fhir/Dosage.js +0 -7
  205. package/dist/fhir/Dosage.js.map +0 -1
  206. package/dist/fhir/Duration.d.ts +0 -46
  207. package/dist/fhir/Duration.js +0 -7
  208. package/dist/fhir/Duration.js.map +0 -1
  209. package/dist/fhir/EffectEvidenceSynthesis.d.ts +0 -591
  210. package/dist/fhir/EffectEvidenceSynthesis.js +0 -7
  211. package/dist/fhir/EffectEvidenceSynthesis.js.map +0 -1
  212. package/dist/fhir/Element.d.ts +0 -21
  213. package/dist/fhir/Element.js +0 -7
  214. package/dist/fhir/Element.js.map +0 -1
  215. package/dist/fhir/ElementDefinition.d.ts +0 -2701
  216. package/dist/fhir/ElementDefinition.js +0 -7
  217. package/dist/fhir/ElementDefinition.js.map +0 -1
  218. package/dist/fhir/Encounter.d.ts +0 -558
  219. package/dist/fhir/Encounter.js +0 -7
  220. package/dist/fhir/Encounter.js.map +0 -1
  221. package/dist/fhir/Endpoint.d.ts +0 -140
  222. package/dist/fhir/Endpoint.js +0 -7
  223. package/dist/fhir/Endpoint.js.map +0 -1
  224. package/dist/fhir/EnrollmentRequest.d.ts +0 -113
  225. package/dist/fhir/EnrollmentRequest.js +0 -7
  226. package/dist/fhir/EnrollmentRequest.js.map +0 -1
  227. package/dist/fhir/EnrollmentResponse.d.ts +0 -117
  228. package/dist/fhir/EnrollmentResponse.js +0 -7
  229. package/dist/fhir/EnrollmentResponse.js.map +0 -1
  230. package/dist/fhir/EpisodeOfCare.d.ts +0 -246
  231. package/dist/fhir/EpisodeOfCare.js +0 -7
  232. package/dist/fhir/EpisodeOfCare.js.map +0 -1
  233. package/dist/fhir/EventDefinition.d.ts +0 -253
  234. package/dist/fhir/EventDefinition.js +0 -7
  235. package/dist/fhir/EventDefinition.js.map +0 -1
  236. package/dist/fhir/Evidence.d.ts +0 -252
  237. package/dist/fhir/Evidence.js +0 -7
  238. package/dist/fhir/Evidence.js.map +0 -1
  239. package/dist/fhir/EvidenceVariable.d.ts +0 -370
  240. package/dist/fhir/EvidenceVariable.js +0 -7
  241. package/dist/fhir/EvidenceVariable.js.map +0 -1
  242. package/dist/fhir/ExampleScenario.d.ts +0 -628
  243. package/dist/fhir/ExampleScenario.js +0 -7
  244. package/dist/fhir/ExampleScenario.js.map +0 -1
  245. package/dist/fhir/ExplanationOfBenefit.d.ts +0 -1841
  246. package/dist/fhir/ExplanationOfBenefit.js +0 -7
  247. package/dist/fhir/ExplanationOfBenefit.js.map +0 -1
  248. package/dist/fhir/Expression.d.ts +0 -45
  249. package/dist/fhir/Expression.js +0 -7
  250. package/dist/fhir/Expression.js.map +0 -1
  251. package/dist/fhir/Extension.d.ts +0 -306
  252. package/dist/fhir/Extension.js +0 -7
  253. package/dist/fhir/Extension.js.map +0 -1
  254. package/dist/fhir/FamilyMemberHistory.d.ts +0 -306
  255. package/dist/fhir/FamilyMemberHistory.js +0 -7
  256. package/dist/fhir/FamilyMemberHistory.js.map +0 -1
  257. package/dist/fhir/Flag.d.ts +0 -132
  258. package/dist/fhir/Flag.js +0 -7
  259. package/dist/fhir/Flag.js.map +0 -1
  260. package/dist/fhir/Goal.d.ts +0 -299
  261. package/dist/fhir/Goal.js +0 -7
  262. package/dist/fhir/Goal.js.map +0 -1
  263. package/dist/fhir/GraphDefinition.d.ts +0 -350
  264. package/dist/fhir/GraphDefinition.js +0 -7
  265. package/dist/fhir/GraphDefinition.js.map +0 -1
  266. package/dist/fhir/Group.d.ts +0 -271
  267. package/dist/fhir/Group.js +0 -7
  268. package/dist/fhir/Group.js.map +0 -1
  269. package/dist/fhir/GuidanceResponse.d.ts +0 -196
  270. package/dist/fhir/GuidanceResponse.js +0 -7
  271. package/dist/fhir/GuidanceResponse.js.map +0 -1
  272. package/dist/fhir/HealthcareService.d.ts +0 -356
  273. package/dist/fhir/HealthcareService.js +0 -7
  274. package/dist/fhir/HealthcareService.js.map +0 -1
  275. package/dist/fhir/HumanName.d.ts +0 -58
  276. package/dist/fhir/HumanName.js +0 -7
  277. package/dist/fhir/HumanName.js.map +0 -1
  278. package/dist/fhir/Identifier.d.ts +0 -53
  279. package/dist/fhir/Identifier.js +0 -7
  280. package/dist/fhir/Identifier.js.map +0 -1
  281. package/dist/fhir/ImagingStudy.d.ts +0 -407
  282. package/dist/fhir/ImagingStudy.js +0 -7
  283. package/dist/fhir/ImagingStudy.js.map +0 -1
  284. package/dist/fhir/Immunization.d.ts +0 -444
  285. package/dist/fhir/Immunization.js +0 -7
  286. package/dist/fhir/Immunization.js.map +0 -1
  287. package/dist/fhir/ImmunizationEvaluation.d.ts +0 -149
  288. package/dist/fhir/ImmunizationEvaluation.js +0 -7
  289. package/dist/fhir/ImmunizationEvaluation.js.map +0 -1
  290. package/dist/fhir/ImmunizationRecommendation.d.ts +0 -254
  291. package/dist/fhir/ImmunizationRecommendation.js +0 -7
  292. package/dist/fhir/ImmunizationRecommendation.js.map +0 -1
  293. package/dist/fhir/ImplementationGuide.d.ts +0 -824
  294. package/dist/fhir/ImplementationGuide.js +0 -7
  295. package/dist/fhir/ImplementationGuide.js.map +0 -1
  296. package/dist/fhir/InsurancePlan.d.ts +0 -624
  297. package/dist/fhir/InsurancePlan.js +0 -7
  298. package/dist/fhir/InsurancePlan.js.map +0 -1
  299. package/dist/fhir/Invoice.d.ts +0 -346
  300. package/dist/fhir/Invoice.js +0 -7
  301. package/dist/fhir/Invoice.js.map +0 -1
  302. package/dist/fhir/JsonWebKey.d.ts +0 -99
  303. package/dist/fhir/JsonWebKey.js +0 -7
  304. package/dist/fhir/JsonWebKey.js.map +0 -1
  305. package/dist/fhir/Library.d.ts +0 -277
  306. package/dist/fhir/Library.js +0 -7
  307. package/dist/fhir/Library.js.map +0 -1
  308. package/dist/fhir/Linkage.d.ts +0 -146
  309. package/dist/fhir/Linkage.js +0 -7
  310. package/dist/fhir/Linkage.js.map +0 -1
  311. package/dist/fhir/List.d.ts +0 -200
  312. package/dist/fhir/List.js +0 -7
  313. package/dist/fhir/List.js.map +0 -1
  314. package/dist/fhir/Location.d.ts +0 -277
  315. package/dist/fhir/Location.js +0 -7
  316. package/dist/fhir/Location.js.map +0 -1
  317. package/dist/fhir/Login.d.ts +0 -119
  318. package/dist/fhir/Login.js +0 -7
  319. package/dist/fhir/Login.js.map +0 -1
  320. package/dist/fhir/MarketingStatus.d.ts +0 -82
  321. package/dist/fhir/MarketingStatus.js +0 -7
  322. package/dist/fhir/MarketingStatus.js.map +0 -1
  323. package/dist/fhir/Measure.d.ts +0 -620
  324. package/dist/fhir/Measure.js +0 -7
  325. package/dist/fhir/Measure.js.map +0 -1
  326. package/dist/fhir/MeasureReport.d.ts +0 -463
  327. package/dist/fhir/MeasureReport.js +0 -7
  328. package/dist/fhir/MeasureReport.js.map +0 -1
  329. package/dist/fhir/Media.d.ts +0 -205
  330. package/dist/fhir/Media.js +0 -7
  331. package/dist/fhir/Media.js.map +0 -1
  332. package/dist/fhir/Medication.d.ts +0 -230
  333. package/dist/fhir/Medication.js +0 -7
  334. package/dist/fhir/Medication.js.map +0 -1
  335. package/dist/fhir/MedicationAdministration.d.ts +0 -352
  336. package/dist/fhir/MedicationAdministration.js +0 -7
  337. package/dist/fhir/MedicationAdministration.js.map +0 -1
  338. package/dist/fhir/MedicationDispense.d.ts +0 -343
  339. package/dist/fhir/MedicationDispense.js +0 -7
  340. package/dist/fhir/MedicationDispense.js.map +0 -1
  341. package/dist/fhir/MedicationKnowledge.d.ts +0 -992
  342. package/dist/fhir/MedicationKnowledge.js +0 -7
  343. package/dist/fhir/MedicationKnowledge.js.map +0 -1
  344. package/dist/fhir/MedicationRequest.d.ts +0 -481
  345. package/dist/fhir/MedicationRequest.js +0 -7
  346. package/dist/fhir/MedicationRequest.js.map +0 -1
  347. package/dist/fhir/MedicationStatement.d.ts +0 -228
  348. package/dist/fhir/MedicationStatement.js +0 -7
  349. package/dist/fhir/MedicationStatement.js.map +0 -1
  350. package/dist/fhir/MedicinalProduct.d.ts +0 -453
  351. package/dist/fhir/MedicinalProduct.js +0 -7
  352. package/dist/fhir/MedicinalProduct.js.map +0 -1
  353. package/dist/fhir/MedicinalProductAuthorization.d.ts +0 -271
  354. package/dist/fhir/MedicinalProductAuthorization.js +0 -7
  355. package/dist/fhir/MedicinalProductAuthorization.js.map +0 -1
  356. package/dist/fhir/MedicinalProductContraindication.d.ts +0 -170
  357. package/dist/fhir/MedicinalProductContraindication.js +0 -7
  358. package/dist/fhir/MedicinalProductContraindication.js.map +0 -1
  359. package/dist/fhir/MedicinalProductIndication.d.ts +0 -179
  360. package/dist/fhir/MedicinalProductIndication.js +0 -7
  361. package/dist/fhir/MedicinalProductIndication.js.map +0 -1
  362. package/dist/fhir/MedicinalProductIngredient.d.ts +0 -336
  363. package/dist/fhir/MedicinalProductIngredient.js +0 -7
  364. package/dist/fhir/MedicinalProductIngredient.js.map +0 -1
  365. package/dist/fhir/MedicinalProductInteraction.d.ts +0 -158
  366. package/dist/fhir/MedicinalProductInteraction.js +0 -7
  367. package/dist/fhir/MedicinalProductInteraction.js.map +0 -1
  368. package/dist/fhir/MedicinalProductManufactured.d.ts +0 -113
  369. package/dist/fhir/MedicinalProductManufactured.js +0 -7
  370. package/dist/fhir/MedicinalProductManufactured.js.map +0 -1
  371. package/dist/fhir/MedicinalProductPackaged.d.ts +0 -259
  372. package/dist/fhir/MedicinalProductPackaged.js +0 -7
  373. package/dist/fhir/MedicinalProductPackaged.js.map +0 -1
  374. package/dist/fhir/MedicinalProductPharmaceutical.d.ts +0 -331
  375. package/dist/fhir/MedicinalProductPharmaceutical.js +0 -7
  376. package/dist/fhir/MedicinalProductPharmaceutical.js.map +0 -1
  377. package/dist/fhir/MedicinalProductUndesirableEffect.d.ts +0 -101
  378. package/dist/fhir/MedicinalProductUndesirableEffect.js +0 -7
  379. package/dist/fhir/MedicinalProductUndesirableEffect.js.map +0 -1
  380. package/dist/fhir/MessageDefinition.d.ts +0 -330
  381. package/dist/fhir/MessageDefinition.js +0 -7
  382. package/dist/fhir/MessageDefinition.js.map +0 -1
  383. package/dist/fhir/MessageHeader.d.ts +0 -323
  384. package/dist/fhir/MessageHeader.js +0 -7
  385. package/dist/fhir/MessageHeader.js.map +0 -1
  386. package/dist/fhir/Meta.d.ts +0 -75
  387. package/dist/fhir/Meta.js +0 -7
  388. package/dist/fhir/Meta.js.map +0 -1
  389. package/dist/fhir/MolecularSequence.d.ts +0 -760
  390. package/dist/fhir/MolecularSequence.js +0 -7
  391. package/dist/fhir/MolecularSequence.js.map +0 -1
  392. package/dist/fhir/Money.d.ts +0 -29
  393. package/dist/fhir/Money.js +0 -7
  394. package/dist/fhir/Money.js.map +0 -1
  395. package/dist/fhir/NamingSystem.d.ts +0 -218
  396. package/dist/fhir/NamingSystem.js +0 -7
  397. package/dist/fhir/NamingSystem.js.map +0 -1
  398. package/dist/fhir/Narrative.d.ts +0 -32
  399. package/dist/fhir/Narrative.js +0 -7
  400. package/dist/fhir/Narrative.js.map +0 -1
  401. package/dist/fhir/NutritionOrder.d.ts +0 -566
  402. package/dist/fhir/NutritionOrder.js +0 -7
  403. package/dist/fhir/NutritionOrder.js.map +0 -1
  404. package/dist/fhir/Observation.d.ts +0 -520
  405. package/dist/fhir/Observation.js +0 -7
  406. package/dist/fhir/Observation.js.map +0 -1
  407. package/dist/fhir/ObservationDefinition.d.ts +0 -278
  408. package/dist/fhir/ObservationDefinition.js +0 -7
  409. package/dist/fhir/ObservationDefinition.js.map +0 -1
  410. package/dist/fhir/OperationDefinition.d.ts +0 -468
  411. package/dist/fhir/OperationDefinition.js +0 -7
  412. package/dist/fhir/OperationDefinition.js.map +0 -1
  413. package/dist/fhir/OperationOutcome.d.ts +0 -160
  414. package/dist/fhir/OperationOutcome.js +0 -7
  415. package/dist/fhir/OperationOutcome.js.map +0 -1
  416. package/dist/fhir/Organization.d.ts +0 -184
  417. package/dist/fhir/Organization.js +0 -7
  418. package/dist/fhir/Organization.js.map +0 -1
  419. package/dist/fhir/OrganizationAffiliation.d.ts +0 -145
  420. package/dist/fhir/OrganizationAffiliation.js +0 -7
  421. package/dist/fhir/OrganizationAffiliation.js.map +0 -1
  422. package/dist/fhir/ParameterDefinition.d.ts +0 -57
  423. package/dist/fhir/ParameterDefinition.js +0 -7
  424. package/dist/fhir/ParameterDefinition.js.map +0 -1
  425. package/dist/fhir/Parameters.d.ts +0 -319
  426. package/dist/fhir/Parameters.js +0 -7
  427. package/dist/fhir/Parameters.js.map +0 -1
  428. package/dist/fhir/PasswordChangeRequest.d.ts +0 -51
  429. package/dist/fhir/PasswordChangeRequest.js +0 -7
  430. package/dist/fhir/PasswordChangeRequest.js.map +0 -1
  431. package/dist/fhir/Patient.d.ts +0 -342
  432. package/dist/fhir/Patient.js +0 -7
  433. package/dist/fhir/Patient.js.map +0 -1
  434. package/dist/fhir/PaymentNotice.d.ts +0 -135
  435. package/dist/fhir/PaymentNotice.js +0 -7
  436. package/dist/fhir/PaymentNotice.js.map +0 -1
  437. package/dist/fhir/PaymentReconciliation.d.ts +0 -280
  438. package/dist/fhir/PaymentReconciliation.js +0 -7
  439. package/dist/fhir/PaymentReconciliation.js.map +0 -1
  440. package/dist/fhir/Period.d.ts +0 -32
  441. package/dist/fhir/Period.js +0 -7
  442. package/dist/fhir/Period.js.map +0 -1
  443. package/dist/fhir/Person.d.ts +0 -175
  444. package/dist/fhir/Person.js +0 -7
  445. package/dist/fhir/Person.js.map +0 -1
  446. package/dist/fhir/PlanDefinition.d.ts +0 -837
  447. package/dist/fhir/PlanDefinition.js +0 -7
  448. package/dist/fhir/PlanDefinition.js.map +0 -1
  449. package/dist/fhir/Population.d.ts +0 -62
  450. package/dist/fhir/Population.js +0 -7
  451. package/dist/fhir/Population.js.map +0 -1
  452. package/dist/fhir/Practitioner.d.ts +0 -191
  453. package/dist/fhir/Practitioner.js +0 -7
  454. package/dist/fhir/Practitioner.js.map +0 -1
  455. package/dist/fhir/PractitionerRole.d.ts +0 -259
  456. package/dist/fhir/PractitionerRole.js +0 -7
  457. package/dist/fhir/PractitionerRole.js.map +0 -1
  458. package/dist/fhir/Procedure.d.ts +0 -372
  459. package/dist/fhir/Procedure.js +0 -7
  460. package/dist/fhir/Procedure.js.map +0 -1
  461. package/dist/fhir/ProdCharacteristic.d.ts +0 -112
  462. package/dist/fhir/ProdCharacteristic.js +0 -7
  463. package/dist/fhir/ProdCharacteristic.js.map +0 -1
  464. package/dist/fhir/ProductShelfLife.d.ts +0 -70
  465. package/dist/fhir/ProductShelfLife.js +0 -7
  466. package/dist/fhir/ProductShelfLife.js.map +0 -1
  467. package/dist/fhir/Project.d.ts +0 -43
  468. package/dist/fhir/Project.js +0 -7
  469. package/dist/fhir/Project.js.map +0 -1
  470. package/dist/fhir/ProjectMembership.d.ts +0 -66
  471. package/dist/fhir/ProjectMembership.js +0 -7
  472. package/dist/fhir/ProjectMembership.js.map +0 -1
  473. package/dist/fhir/Provenance.d.ts +0 -258
  474. package/dist/fhir/Provenance.js +0 -7
  475. package/dist/fhir/Provenance.js.map +0 -1
  476. package/dist/fhir/Quantity.d.ts +0 -46
  477. package/dist/fhir/Quantity.js +0 -7
  478. package/dist/fhir/Quantity.js.map +0 -1
  479. package/dist/fhir/Questionnaire.d.ts +0 -603
  480. package/dist/fhir/Questionnaire.js +0 -7
  481. package/dist/fhir/Questionnaire.js.map +0 -1
  482. package/dist/fhir/QuestionnaireResponse.d.ts +0 -313
  483. package/dist/fhir/QuestionnaireResponse.js +0 -7
  484. package/dist/fhir/QuestionnaireResponse.js.map +0 -1
  485. package/dist/fhir/Range.d.ts +0 -30
  486. package/dist/fhir/Range.js +0 -7
  487. package/dist/fhir/Range.js.map +0 -1
  488. package/dist/fhir/Ratio.d.ts +0 -30
  489. package/dist/fhir/Ratio.js +0 -7
  490. package/dist/fhir/Ratio.js.map +0 -1
  491. package/dist/fhir/Reference.d.ts +0 -67
  492. package/dist/fhir/Reference.js +0 -7
  493. package/dist/fhir/Reference.js.map +0 -1
  494. package/dist/fhir/RefreshToken.d.ts +0 -45
  495. package/dist/fhir/RefreshToken.js +0 -7
  496. package/dist/fhir/RefreshToken.js.map +0 -1
  497. package/dist/fhir/RelatedArtifact.d.ts +0 -57
  498. package/dist/fhir/RelatedArtifact.js +0 -7
  499. package/dist/fhir/RelatedArtifact.js.map +0 -1
  500. package/dist/fhir/RelatedPerson.d.ts +0 -190
  501. package/dist/fhir/RelatedPerson.js +0 -7
  502. package/dist/fhir/RelatedPerson.js.map +0 -1
  503. package/dist/fhir/RequestGroup.d.ts +0 -434
  504. package/dist/fhir/RequestGroup.js +0 -7
  505. package/dist/fhir/RequestGroup.js.map +0 -1
  506. package/dist/fhir/ResearchDefinition.d.ts +0 -291
  507. package/dist/fhir/ResearchDefinition.js +0 -7
  508. package/dist/fhir/ResearchDefinition.js.map +0 -1
  509. package/dist/fhir/ResearchElementDefinition.d.ts +0 -431
  510. package/dist/fhir/ResearchElementDefinition.js +0 -7
  511. package/dist/fhir/ResearchElementDefinition.js.map +0 -1
  512. package/dist/fhir/ResearchStudy.d.ts +0 -318
  513. package/dist/fhir/ResearchStudy.js +0 -7
  514. package/dist/fhir/ResearchStudy.js.map +0 -1
  515. package/dist/fhir/ResearchSubject.d.ts +0 -119
  516. package/dist/fhir/ResearchSubject.js +0 -7
  517. package/dist/fhir/ResearchSubject.js.map +0 -1
  518. package/dist/fhir/Resource.d.ts +0 -156
  519. package/dist/fhir/Resource.js +0 -7
  520. package/dist/fhir/Resource.js.map +0 -1
  521. package/dist/fhir/RiskAssessment.d.ts +0 -246
  522. package/dist/fhir/RiskAssessment.js +0 -7
  523. package/dist/fhir/RiskAssessment.js.map +0 -1
  524. package/dist/fhir/RiskEvidenceSynthesis.d.ts +0 -530
  525. package/dist/fhir/RiskEvidenceSynthesis.js +0 -7
  526. package/dist/fhir/RiskEvidenceSynthesis.js.map +0 -1
  527. package/dist/fhir/SampledData.d.ts +0 -62
  528. package/dist/fhir/SampledData.js +0 -7
  529. package/dist/fhir/SampledData.js.map +0 -1
  530. package/dist/fhir/Schedule.d.ts +0 -129
  531. package/dist/fhir/Schedule.js +0 -7
  532. package/dist/fhir/Schedule.js.map +0 -1
  533. package/dist/fhir/SearchParameter.d.ts +0 -277
  534. package/dist/fhir/SearchParameter.js +0 -7
  535. package/dist/fhir/SearchParameter.js.map +0 -1
  536. package/dist/fhir/ServiceRequest.d.ts +0 -309
  537. package/dist/fhir/ServiceRequest.js +0 -7
  538. package/dist/fhir/ServiceRequest.js.map +0 -1
  539. package/dist/fhir/Signature.d.ts +0 -71
  540. package/dist/fhir/Signature.js +0 -7
  541. package/dist/fhir/Signature.js.map +0 -1
  542. package/dist/fhir/Slot.d.ts +0 -134
  543. package/dist/fhir/Slot.js +0 -7
  544. package/dist/fhir/Slot.js.map +0 -1
  545. package/dist/fhir/Specimen.d.ts +0 -366
  546. package/dist/fhir/Specimen.js +0 -7
  547. package/dist/fhir/Specimen.js.map +0 -1
  548. package/dist/fhir/SpecimenDefinition.d.ts +0 -363
  549. package/dist/fhir/SpecimenDefinition.js +0 -7
  550. package/dist/fhir/SpecimenDefinition.js.map +0 -1
  551. package/dist/fhir/StructureDefinition.d.ts +0 -438
  552. package/dist/fhir/StructureDefinition.js +0 -7
  553. package/dist/fhir/StructureDefinition.js.map +0 -1
  554. package/dist/fhir/StructureMap.d.ts +0 -904
  555. package/dist/fhir/StructureMap.js +0 -7
  556. package/dist/fhir/StructureMap.js.map +0 -1
  557. package/dist/fhir/Subscription.d.ts +0 -172
  558. package/dist/fhir/Subscription.js +0 -7
  559. package/dist/fhir/Subscription.js.map +0 -1
  560. package/dist/fhir/Substance.d.ts +0 -213
  561. package/dist/fhir/Substance.js +0 -7
  562. package/dist/fhir/Substance.js.map +0 -1
  563. package/dist/fhir/SubstanceAmount.d.ts +0 -115
  564. package/dist/fhir/SubstanceAmount.js +0 -7
  565. package/dist/fhir/SubstanceAmount.js.map +0 -1
  566. package/dist/fhir/SubstanceNucleicAcid.d.ts +0 -309
  567. package/dist/fhir/SubstanceNucleicAcid.js +0 -7
  568. package/dist/fhir/SubstanceNucleicAcid.js.map +0 -1
  569. package/dist/fhir/SubstancePolymer.d.ts +0 -405
  570. package/dist/fhir/SubstancePolymer.js +0 -7
  571. package/dist/fhir/SubstancePolymer.js.map +0 -1
  572. package/dist/fhir/SubstanceProtein.d.ts +0 -218
  573. package/dist/fhir/SubstanceProtein.js +0 -7
  574. package/dist/fhir/SubstanceProtein.js.map +0 -1
  575. package/dist/fhir/SubstanceReferenceInformation.d.ts +0 -330
  576. package/dist/fhir/SubstanceReferenceInformation.js +0 -7
  577. package/dist/fhir/SubstanceReferenceInformation.js.map +0 -1
  578. package/dist/fhir/SubstanceSourceMaterial.d.ts +0 -521
  579. package/dist/fhir/SubstanceSourceMaterial.js +0 -7
  580. package/dist/fhir/SubstanceSourceMaterial.js.map +0 -1
  581. package/dist/fhir/SubstanceSpecification.d.ts +0 -827
  582. package/dist/fhir/SubstanceSpecification.js +0 -7
  583. package/dist/fhir/SubstanceSpecification.js.map +0 -1
  584. package/dist/fhir/SupplyDelivery.d.ts +0 -205
  585. package/dist/fhir/SupplyDelivery.js +0 -7
  586. package/dist/fhir/SupplyDelivery.js.map +0 -1
  587. package/dist/fhir/SupplyRequest.d.ts +0 -237
  588. package/dist/fhir/SupplyRequest.js +0 -7
  589. package/dist/fhir/SupplyRequest.js.map +0 -1
  590. package/dist/fhir/Task.d.ts +0 -807
  591. package/dist/fhir/Task.js +0 -7
  592. package/dist/fhir/Task.js.map +0 -1
  593. package/dist/fhir/TerminologyCapabilities.d.ts +0 -716
  594. package/dist/fhir/TerminologyCapabilities.js +0 -7
  595. package/dist/fhir/TerminologyCapabilities.js.map +0 -1
  596. package/dist/fhir/TestReport.d.ts +0 -549
  597. package/dist/fhir/TestReport.js +0 -7
  598. package/dist/fhir/TestReport.js.map +0 -1
  599. package/dist/fhir/TestScript.d.ts +0 -1184
  600. package/dist/fhir/TestScript.js +0 -7
  601. package/dist/fhir/TestScript.js.map +0 -1
  602. package/dist/fhir/Timing.d.ts +0 -178
  603. package/dist/fhir/Timing.js +0 -7
  604. package/dist/fhir/Timing.js.map +0 -1
  605. package/dist/fhir/TriggerDefinition.d.ts +0 -65
  606. package/dist/fhir/TriggerDefinition.js +0 -7
  607. package/dist/fhir/TriggerDefinition.js.map +0 -1
  608. package/dist/fhir/UsageContext.d.ts +0 -61
  609. package/dist/fhir/UsageContext.js +0 -7
  610. package/dist/fhir/UsageContext.js.map +0 -1
  611. package/dist/fhir/User.d.ts +0 -45
  612. package/dist/fhir/User.js +0 -7
  613. package/dist/fhir/User.js.map +0 -1
  614. package/dist/fhir/ValueSet.d.ts +0 -725
  615. package/dist/fhir/ValueSet.js +0 -7
  616. package/dist/fhir/ValueSet.js.map +0 -1
  617. package/dist/fhir/VerificationResult.d.ts +0 -340
  618. package/dist/fhir/VerificationResult.js +0 -7
  619. package/dist/fhir/VerificationResult.js.map +0 -1
  620. package/dist/fhir/VisionPrescription.d.ts +0 -264
  621. package/dist/fhir/VisionPrescription.js +0 -7
  622. package/dist/fhir/VisionPrescription.js.map +0 -1
  623. package/dist/fhir/index.d.ts +0 -196
  624. package/dist/fhir/index.js +0 -213
  625. package/dist/fhir/index.js.map +0 -1
  626. package/dist/fhirpath/functions.d.ts +0 -6
  627. package/dist/fhirpath/functions.js +0 -349
  628. package/dist/fhirpath/functions.js.map +0 -1
  629. package/dist/fhirpath/index.d.ts +0 -2
  630. package/dist/fhirpath/index.js +0 -15
  631. package/dist/fhirpath/index.js.map +0 -1
  632. package/dist/fhirpath/parse.d.ts +0 -10
  633. package/dist/fhirpath/parse.js +0 -266
  634. package/dist/fhirpath/parse.js.map +0 -1
  635. package/dist/fhirpath/tokenize.d.ts +0 -13
  636. package/dist/fhirpath/tokenize.js +0 -39
  637. package/dist/fhirpath/tokenize.js.map +0 -1
  638. package/dist/fhirpath/utils.d.ts +0 -13
  639. package/dist/fhirpath/utils.js +0 -34
  640. package/dist/fhirpath/utils.js.map +0 -1
package/dist/client.js CHANGED
@@ -22,14 +22,14 @@ const storage_1 = require("./storage");
22
22
  const types_1 = require("./types");
23
23
  const utils_1 = require("./utils");
24
24
  const DEFAULT_BASE_URL = 'https://api.medplum.com/';
25
+ const DEFAULT_SCOPE = 'launch/patient openid fhirUser offline_access user/*.*';
25
26
  const DEFAULT_RESOURCE_CACHE_SIZE = 1000;
26
- const DEFAULT_BLOB_CACHE_SIZE = 100;
27
27
  const JSON_CONTENT_TYPE = 'application/json';
28
28
  const FHIR_CONTENT_TYPE = 'application/fhir+json';
29
29
  const PATCH_CONTENT_TYPE = 'application/json-patch+json';
30
30
  class MedplumClient extends eventtarget_1.EventTarget {
31
31
  constructor(options) {
32
- var _a, _b;
32
+ var _a, _b, _c;
33
33
  super();
34
34
  if (options.baseUrl) {
35
35
  if (!options.baseUrl.startsWith('http')) {
@@ -39,31 +39,36 @@ class MedplumClient extends eventtarget_1.EventTarget {
39
39
  throw new Error('Base URL must end with a trailing slash');
40
40
  }
41
41
  }
42
- if (!options.clientId) {
43
- throw new Error('Client ID cannot be empty');
44
- }
45
42
  this.fetch = options.fetch || window.fetch.bind(window);
46
43
  this.storage = new storage_1.ClientStorage();
47
44
  this.schema = new Map();
48
45
  this.resourceCache = new cache_1.LRUCache((_a = options.resourceCacheSize) !== null && _a !== void 0 ? _a : DEFAULT_RESOURCE_CACHE_SIZE);
49
- this.blobUrlCache = new cache_1.LRUCache((_b = options.blobCacheSize) !== null && _b !== void 0 ? _b : DEFAULT_BLOB_CACHE_SIZE);
50
46
  this.baseUrl = options.baseUrl || DEFAULT_BASE_URL;
51
- this.clientId = options.clientId;
47
+ this.clientId = options.clientId || '';
52
48
  this.authorizeUrl = options.authorizeUrl || this.baseUrl + 'oauth2/authorize';
53
49
  this.tokenUrl = options.tokenUrl || this.baseUrl + 'oauth2/token';
54
50
  this.logoutUrl = options.logoutUrl || this.baseUrl + 'oauth2/logout';
55
51
  this.onUnauthenticated = options.onUnauthenticated;
52
+ this.activeLogin = this.storage.getObject('activeLogin');
53
+ if (!((_c = (_b = this.activeLogin) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.reference)) {
54
+ this.clear();
55
+ }
56
+ this.loading = false;
57
+ this.refreshProfile().catch(console.log);
56
58
  }
57
59
  /**
58
60
  * Clears all auth state including local storage and session storage.
59
61
  */
60
62
  clear() {
61
63
  this.storage.clear();
64
+ this.schema.clear();
65
+ this.resourceCache.clear();
62
66
  this.activeLogin = undefined;
67
+ this.profile = undefined;
63
68
  this.dispatchEvent({ type: 'change' });
64
69
  }
65
- get(url, blob) {
66
- return this.request('GET', url, undefined, undefined, blob);
70
+ get(url) {
71
+ return this.request('GET', url);
67
72
  }
68
73
  post(url, body, contentType) {
69
74
  return this.request('POST', url, contentType, body);
@@ -71,54 +76,53 @@ class MedplumClient extends eventtarget_1.EventTarget {
71
76
  put(url, body, contentType) {
72
77
  return this.request('PUT', url, contentType, body);
73
78
  }
79
+ delete(url) {
80
+ return this.request('DELETE', url);
81
+ }
74
82
  /**
75
83
  * Tries to register a new user.
76
84
  * @param request The registration request.
77
- * @returns Promise to the user profile resource.
85
+ * @returns Promise to the authentication response.
78
86
  */
79
87
  register(request) {
80
- return this.post('auth/register', request)
81
- .then((response) => this.handleLoginResponse(response));
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const response = yield this.post('auth/register', request);
90
+ yield this.setActiveLogin(response);
91
+ });
82
92
  }
83
93
  /**
84
- * Tries to sign in with email and password.
85
- * @param email The user email address.
86
- * @param password The user password.
87
- * @param role The login role.
88
- * @param scope The OAuth2 login scope.
89
- * @param remember Optional flag to "remember" to generate a refresh token and persist in local storage.
90
- * @returns Promise to the user profile resource.
94
+ * Initiates a user login flow.
95
+ * @param email The email address of the user.
96
+ * @param password The password of the user.
97
+ * @param remember Optional flag to remember the user.
98
+ * @returns Promise to the authentication response.
91
99
  */
92
- signIn(email, password, role, scope, remember) {
93
- return this.post('auth/login', {
94
- clientId: this.clientId,
95
- email,
96
- password,
97
- role,
98
- scope,
99
- remember: !!remember
100
- }).then((response) => this.handleLoginResponse(response));
100
+ startLogin(email, password, remember) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ yield this.startPkce();
103
+ return this.post('auth/login', {
104
+ clientId: this.clientId,
105
+ scope: DEFAULT_SCOPE,
106
+ codeChallengeMethod: 'S256',
107
+ codeChallenge: this.storage.getString('codeChallenge'),
108
+ email,
109
+ password,
110
+ remember: !!remember,
111
+ });
112
+ });
101
113
  }
102
114
  /**
103
115
  * Tries to sign in with Google authentication.
104
116
  * The response parameter is the result of a Google authentication.
105
117
  * See: https://developers.google.com/identity/gsi/web/guides/handle-credential-responses-js-functions
106
118
  * @param googleResponse The Google credential response.
107
- * @returns Promise to the user profile resource.
119
+ * @returns Promise to the authentication response.
108
120
  */
109
- signInWithGoogle(googleResponse) {
110
- return this.post('auth/google', googleResponse)
111
- .then((loginResponse) => this.handleLoginResponse(loginResponse));
112
- }
113
- /**
114
- * Handles a login response.
115
- * This can be used for both "register" and "signIn".
116
- * @param response The login response.
117
- * @returns The user profile.
118
- */
119
- handleLoginResponse(response) {
120
- this.setActiveLogin(response);
121
- return response.profile;
121
+ startGoogleLogin(googleResponse) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ yield this.startPkce();
124
+ return this.post('auth/google', googleResponse);
125
+ });
122
126
  }
123
127
  /**
124
128
  * Signs out locally.
@@ -153,7 +157,7 @@ class MedplumClient extends eventtarget_1.EventTarget {
153
157
  }
154
158
  fhirUrl(...path) {
155
159
  const builder = [this.baseUrl, 'fhir/R4'];
156
- path.forEach(p => builder.push('/', encodeURIComponent(p)));
160
+ path.forEach((p) => builder.push('/', encodeURIComponent(p)));
157
161
  return builder.join('');
158
162
  }
159
163
  search(search) {
@@ -178,8 +182,7 @@ class MedplumClient extends eventtarget_1.EventTarget {
178
182
  }
179
183
  read(resourceType, id) {
180
184
  const cacheKey = resourceType + '/' + id;
181
- const promise = this.get(this.fhirUrl(resourceType, id))
182
- .then((resource) => {
185
+ const promise = this.get(this.fhirUrl(resourceType, id)).then((resource) => {
183
186
  this.resourceCache.set(cacheKey, resource);
184
187
  return resource;
185
188
  });
@@ -230,17 +233,19 @@ class MedplumClient extends eventtarget_1.EventTarget {
230
233
  .then(() => this.search({
231
234
  resourceType: 'SearchParameter',
232
235
  count: 100,
233
- filters: [{
236
+ filters: [
237
+ {
234
238
  code: 'base',
235
239
  operator: search_1.Operator.EQUALS,
236
- value: resourceType
237
- }]
240
+ value: resourceType,
241
+ },
242
+ ],
238
243
  }))
239
244
  .then((result) => {
240
245
  const entries = result.entry;
241
246
  if (entries) {
242
247
  typeDef.types[resourceType].searchParams = entries
243
- .map(e => e.resource)
248
+ .map((e) => e.resource)
244
249
  .sort((a, b) => { var _a, _b; return (_b = (_a = a.name) === null || _a === void 0 ? void 0 : _a.localeCompare(b.name)) !== null && _b !== void 0 ? _b : 0; });
245
250
  }
246
251
  this.schema.set(resourceType, typeDef);
@@ -253,26 +258,6 @@ class MedplumClient extends eventtarget_1.EventTarget {
253
258
  readPatientEverything(id) {
254
259
  return this.get(this.fhirUrl('Patient', id, '$everything'));
255
260
  }
256
- readBlob(url) {
257
- return this.get(url, true);
258
- }
259
- readBlobAsObjectUrl(url) {
260
- const promise = this.readBlob(url)
261
- .then(imageBlob => {
262
- const imageUrl = URL.createObjectURL(imageBlob);
263
- this.blobUrlCache.set(url, imageUrl);
264
- return imageUrl;
265
- });
266
- this.blobUrlCache.set(url, promise);
267
- return promise;
268
- }
269
- readCachedBlobAsObjectUrl(url) {
270
- const cached = this.blobUrlCache.get(url);
271
- return cached ? Promise.resolve(cached) : this.readBlobAsObjectUrl(url);
272
- }
273
- readBinary(id) {
274
- return this.readBlob(this.fhirUrl('Binary', id));
275
- }
276
261
  create(resource) {
277
262
  if (!resource.resourceType) {
278
263
  throw new Error('Missing resourceType');
@@ -294,6 +279,9 @@ class MedplumClient extends eventtarget_1.EventTarget {
294
279
  patch(resourceType, id, operations) {
295
280
  return this.request('PATCH', this.fhirUrl(resourceType, id), PATCH_CONTENT_TYPE, operations);
296
281
  }
282
+ deleteResource(resourceType, id) {
283
+ return this.delete(this.fhirUrl(resourceType, id));
284
+ }
297
285
  graphql(gql) {
298
286
  return this.post(this.fhirUrl('$graphql'), gql, JSON_CONTENT_TYPE);
299
287
  }
@@ -303,11 +291,11 @@ class MedplumClient extends eventtarget_1.EventTarget {
303
291
  status: 'active',
304
292
  criteria: criteria,
305
293
  channel: {
306
- type: 'sse'
307
- }
294
+ type: 'sse',
295
+ },
308
296
  }).then((sub) => {
309
297
  const eventSource = new EventSource(this.baseUrl + 'sse?subscription=' + encodeURIComponent(sub.id), {
310
- withCredentials: true
298
+ withCredentials: true,
311
299
  });
312
300
  eventSource.onmessage = (e) => {
313
301
  handler(JSON.parse(e.data));
@@ -316,29 +304,45 @@ class MedplumClient extends eventtarget_1.EventTarget {
316
304
  });
317
305
  }
318
306
  getActiveLogin() {
319
- if (!this.activeLogin) {
320
- this.activeLogin = this.storage.getObject('activeLogin');
321
- }
322
307
  return this.activeLogin;
323
308
  }
324
309
  setActiveLogin(login) {
325
- this.activeLogin = login;
326
- this.storage.setObject('activeLogin', login);
327
- this.addLogin(login);
328
- this.dispatchEvent({ type: 'change' });
310
+ return __awaiter(this, void 0, void 0, function* () {
311
+ this.activeLogin = login;
312
+ this.storage.setObject('activeLogin', login);
313
+ this.addLogin(login);
314
+ this.resourceCache.clear();
315
+ this.refreshPromise = undefined;
316
+ yield this.refreshProfile();
317
+ });
329
318
  }
330
319
  getLogins() {
331
320
  var _a;
332
321
  return (_a = this.storage.getObject('logins')) !== null && _a !== void 0 ? _a : [];
333
322
  }
334
323
  addLogin(newLogin) {
335
- const logins = this.getLogins().filter(login => { var _a, _b; return ((_a = login.profile) === null || _a === void 0 ? void 0 : _a.id) !== ((_b = newLogin.profile) === null || _b === void 0 ? void 0 : _b.id); });
324
+ 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); });
336
325
  logins.push(newLogin);
337
326
  this.storage.setObject('logins', logins);
338
327
  }
339
- getProfile() {
328
+ refreshProfile() {
340
329
  var _a;
341
- return (_a = this.getActiveLogin()) === null || _a === void 0 ? void 0 : _a.profile;
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ const reference = (_a = this.getActiveLogin()) === null || _a === void 0 ? void 0 : _a.profile;
332
+ if (reference === null || reference === void 0 ? void 0 : reference.reference) {
333
+ this.loading = true;
334
+ this.profile = yield this.readCachedReference(reference);
335
+ this.loading = false;
336
+ this.dispatchEvent({ type: 'change' });
337
+ }
338
+ return this.profile;
339
+ });
340
+ }
341
+ getProfile() {
342
+ return this.profile;
343
+ }
344
+ isLoading() {
345
+ return this.loading;
342
346
  }
343
347
  /**
344
348
  * Makes an HTTP request.
@@ -346,16 +350,18 @@ class MedplumClient extends eventtarget_1.EventTarget {
346
350
  * @param {string} url
347
351
  * @param {string=} contentType
348
352
  * @param {Object=} body
349
- * @param {boolean=} blob
350
353
  */
351
- request(method, url, contentType, body, blob) {
354
+ request(method, url, contentType, body) {
352
355
  var _a;
353
356
  return __awaiter(this, void 0, void 0, function* () {
357
+ if (this.refreshPromise) {
358
+ yield this.refreshPromise;
359
+ }
354
360
  if (!url.startsWith('http')) {
355
361
  url = this.baseUrl + url;
356
362
  }
357
363
  const headers = {
358
- 'Content-Type': contentType || FHIR_CONTENT_TYPE
364
+ 'Content-Type': contentType || FHIR_CONTENT_TYPE,
359
365
  };
360
366
  const accessToken = (_a = this.getActiveLogin()) === null || _a === void 0 ? void 0 : _a.accessToken;
361
367
  if (accessToken) {
@@ -365,7 +371,7 @@ class MedplumClient extends eventtarget_1.EventTarget {
365
371
  method: method,
366
372
  cache: 'no-cache',
367
373
  credentials: 'include',
368
- headers
374
+ headers,
369
375
  };
370
376
  if (body) {
371
377
  if (typeof body === 'string' || (typeof File !== 'undefined' && body instanceof File)) {
@@ -378,13 +384,13 @@ class MedplumClient extends eventtarget_1.EventTarget {
378
384
  const response = yield this.fetch(url, options);
379
385
  if (response.status === 401) {
380
386
  // Refresh and try again
381
- return this.handleUnauthenticated(method, url, contentType, body, blob);
387
+ return this.handleUnauthenticated(method, url, contentType, body);
382
388
  }
383
- if (response.status === 304) {
384
- // No change
389
+ if (response.status === 204 || response.status === 304) {
390
+ // No content or change
385
391
  return undefined;
386
392
  }
387
- const obj = blob ? yield response.blob() : yield response.json();
393
+ const obj = yield response.json();
388
394
  if (obj.resourceType === 'OperationOutcome' && !(0, outcomes_1.isOk)(obj)) {
389
395
  return Promise.reject(new outcomes_1.OperationOutcomeError(obj));
390
396
  }
@@ -399,13 +405,12 @@ class MedplumClient extends eventtarget_1.EventTarget {
399
405
  * @param url The URL of the original request.
400
406
  * @param contentType The content type of the original request.
401
407
  * @param body The body of the original request.
402
- * @param blob Optional blob flag of the original request.
403
408
  */
404
- handleUnauthenticated(method, url, contentType, body, blob) {
409
+ handleUnauthenticated(method, url, contentType, body) {
405
410
  return __awaiter(this, void 0, void 0, function* () {
406
411
  return this.refresh()
407
- .then(() => this.request(method, url, contentType, body, blob))
408
- .catch(error => {
412
+ .then(() => this.request(method, url, contentType, body))
413
+ .catch((error) => {
409
414
  this.clear();
410
415
  if (this.onUnauthenticated) {
411
416
  this.onUnauthenticated();
@@ -414,6 +419,21 @@ class MedplumClient extends eventtarget_1.EventTarget {
414
419
  });
415
420
  });
416
421
  }
422
+ /**
423
+ * Starts a new PKCE flow.
424
+ * These PKCE values are stateful, and must survive redirects and page refreshes.
425
+ */
426
+ startPkce() {
427
+ return __awaiter(this, void 0, void 0, function* () {
428
+ const pkceState = (0, crypto_1.getRandomString)();
429
+ this.storage.setString('pkceState', pkceState);
430
+ const codeVerifier = (0, crypto_1.getRandomString)();
431
+ this.storage.setString('codeVerifier', codeVerifier);
432
+ const arrayHash = yield (0, crypto_1.encryptSHA256)(codeVerifier);
433
+ const codeChallenge = (0, utils_1.arrayBufferToBase64)(arrayHash).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
434
+ this.storage.setString('codeChallenge', codeChallenge);
435
+ });
436
+ }
417
437
  /**
418
438
  * Redirects the user to the login screen for authorization.
419
439
  * Clears all auth state including local storage and session storage.
@@ -424,23 +444,20 @@ class MedplumClient extends eventtarget_1.EventTarget {
424
444
  if (!this.authorizeUrl) {
425
445
  throw new Error('Missing authorize URL');
426
446
  }
427
- this.clear();
428
- const pkceState = (0, crypto_1.getRandomString)();
429
- this.storage.setString('pkceState', pkceState);
430
- const codeVerifier = (0, crypto_1.getRandomString)();
431
- this.storage.setString('codeVerifier', codeVerifier);
432
- const arrayHash = yield (0, crypto_1.encryptSHA256)(codeVerifier);
433
- const codeChallenge = (0, utils_1.arrayBufferToBase64)(arrayHash);
434
- this.storage.setString('codeChallenge', codeChallenge);
435
- const scope = 'launch/patient openid fhirUser offline_access user/*.*';
447
+ this.startPkce();
436
448
  window.location.assign(this.authorizeUrl +
437
449
  '?response_type=code' +
438
- '&state=' + encodeURIComponent(pkceState) +
439
- '&client_id=' + encodeURIComponent(this.clientId) +
440
- '&redirect_uri=' + encodeURIComponent(getBaseUrl()) +
441
- '&scope=' + encodeURIComponent(scope) +
450
+ '&state=' +
451
+ encodeURIComponent(this.storage.getString('pkceState')) +
452
+ '&client_id=' +
453
+ encodeURIComponent(this.clientId) +
454
+ '&redirect_uri=' +
455
+ encodeURIComponent(getBaseUrl()) +
456
+ '&scope=' +
457
+ encodeURIComponent(DEFAULT_SCOPE) +
442
458
  '&code_challenge_method=S256' +
443
- '&code_challenge=' + encodeURIComponent(codeChallenge));
459
+ '&code_challenge=' +
460
+ encodeURIComponent(this.storage.getString('codeChallenge')));
444
461
  });
445
462
  }
446
463
  /**
@@ -460,10 +477,13 @@ class MedplumClient extends eventtarget_1.EventTarget {
460
477
  throw new Error('Invalid PCKE code verifier');
461
478
  }
462
479
  return this.fetchTokens('grant_type=authorization_code' +
463
- '&client_id=' + encodeURIComponent(this.clientId) +
464
- '&code_verifier=' + encodeURIComponent(codeVerifier) +
465
- '&redirect_uri=' + encodeURIComponent(getBaseUrl()) +
466
- '&code=' + encodeURIComponent(code));
480
+ (this.clientId ? '&client_id=' + encodeURIComponent(this.clientId) : '') +
481
+ '&code_verifier=' +
482
+ encodeURIComponent(codeVerifier) +
483
+ '&redirect_uri=' +
484
+ encodeURIComponent(getBaseUrl()) +
485
+ '&code=' +
486
+ encodeURIComponent(code));
467
487
  }
468
488
  /**
469
489
  * Tries to refresh the auth tokens.
@@ -472,14 +492,20 @@ class MedplumClient extends eventtarget_1.EventTarget {
472
492
  refresh() {
473
493
  var _a;
474
494
  return __awaiter(this, void 0, void 0, function* () {
495
+ if (this.refreshPromise) {
496
+ return this.refreshPromise;
497
+ }
475
498
  const refreshToken = (_a = this.getActiveLogin()) === null || _a === void 0 ? void 0 : _a.refreshToken;
476
499
  if (!refreshToken) {
477
500
  this.clear();
478
501
  return Promise.reject('Invalid refresh token');
479
502
  }
480
- yield this.fetchTokens('grant_type=refresh_token' +
481
- '&client_id=' + encodeURIComponent(this.clientId) +
482
- '&refresh_token=' + encodeURIComponent(refreshToken));
503
+ this.refreshPromise = this.fetchTokens('grant_type=refresh_token' +
504
+ '&client_id=' +
505
+ encodeURIComponent(this.clientId) +
506
+ '&refresh_token=' +
507
+ encodeURIComponent(refreshToken));
508
+ yield this.refreshPromise;
483
509
  });
484
510
  }
485
511
  /**
@@ -490,21 +516,21 @@ class MedplumClient extends eventtarget_1.EventTarget {
490
516
  fetchTokens(formBody) {
491
517
  return __awaiter(this, void 0, void 0, function* () {
492
518
  if (!this.tokenUrl) {
493
- throw new Error('Missing token URL');
519
+ return Promise.reject('Missing token URL');
494
520
  }
495
521
  return this.fetch(this.tokenUrl, {
496
522
  method: 'POST',
497
523
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
498
- body: formBody
524
+ body: formBody,
499
525
  })
500
- .then(response => {
526
+ .then((response) => {
501
527
  if (!response.ok) {
502
528
  return Promise.reject('Failed to fetch tokens');
503
529
  }
504
530
  return response.json();
505
531
  })
506
- .then(tokens => this.verifyTokens(tokens))
507
- .then(() => { var _a; return (_a = this.getActiveLogin()) === null || _a === void 0 ? void 0 : _a.profile; });
532
+ .then((tokens) => this.verifyTokens(tokens))
533
+ .then(() => this.profile);
508
534
  });
509
535
  }
510
536
  /**
@@ -523,11 +549,16 @@ class MedplumClient extends eventtarget_1.EventTarget {
523
549
  return Promise.reject('Token expired');
524
550
  }
525
551
  // Verify app_client_id
526
- if (tokenPayload.client_id !== this.clientId) {
552
+ if (this.clientId && tokenPayload.client_id !== this.clientId) {
527
553
  this.clear();
528
554
  return Promise.reject('Token was not issued for this audience');
529
555
  }
530
- this.setActiveLogin(Object.assign(Object.assign({}, this.getActiveLogin()), { accessToken: token, refreshToken: tokens.refresh_token }));
556
+ yield this.setActiveLogin({
557
+ accessToken: token,
558
+ refreshToken: tokens.refresh_token,
559
+ project: tokens.project,
560
+ profile: tokens.profile,
561
+ });
531
562
  });
532
563
  }
533
564
  }