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