Each resource may belong to one or more compartments. A compartment is a logical grouping of resources which share a common property. Compartments have two principal roles:
Function as an access mechanism for finding a set of related resources quickly (described here)
Provide a definitional basis for applying access control to resources quickly
Read more about compartments in the FHIR documentation. All examples in this tutorial are executable in Aidbox REST console.
In order to use compartments, you will need to create CompartmentDefinition resources on your server. Visit FHIR documentation for official CompartmentDefinition examples or use the following REST console snippets to create the resources.
Which CompartmentDefinitionis used is determined by its code or id:
The compartment withid = target resourceTypeis used
Else if not found compartment withcode = target resourceTypeis used
If multiple compartments with the code = traget resourceType are found then it is not determined which one will be used since FHIR spec doesn't specify this case
PUT /fhir/CompartmentDefinition/PatientresourceType:CompartmentDefinitionid:Patienturl:http://hl7.org/fhir/CompartmentDefinition/patientexperimental:truename:Base FHIR compartment definition for Patientstatus:draftpublisher:FHIR Project Teamversion:4.0.1date:'2019-11-01T09:29:23+11:00'search:truecode:Patientcontact:- telecom: - {system:url,value:'http://hl7.org/fhir'}description:...# array that enumerates resources included in the compartmentresource:...
PUT /fhir/CompartmentDefinition/PatientresourceType:CompartmentDefinitionid:Patienturl:http://hl7.org/fhir/CompartmentDefinition/patientexperimental:truename:Base FHIR compartment definition for Patientstatus:draftpublisher:FHIR Project Teamversion:4.0.1date:'2019-11-01T09:29:23+11:00'search:truecode:Patientcontact:- telecom: - {system:url,value:'http://hl7.org/fhir'}description:There is an instance of the patient compartment for each patient resource, and the identity of the compartment is the same as the patient. When a patient is linked to another patient, all the records associated with the linked patient are in the compartment associated with the target of the link.. The set of resources associated with a particular patientresource:- code:Accountparam: [subject]- {code:ActivityDefinition}- code:AdverseEventparam: [subject]- code:AllergyIntoleranceparam: [patient,recorder,asserter]- code:Appointmentparam: [actor]- code:AppointmentResponseparam: [actor]- code:AuditEventparam: [patient]- code:Basicparam: [patient,author]- {code:Binary}- {code:BiologicallyDerivedProduct}- code:BodyStructureparam: [patient]- {code:Bundle}- {code:CapabilityStatement}- code:CarePlanparam: [patient,performer]- code:CareTeamparam: [patient,participant]- {code:CatalogEntry}- code:ChargeItemparam: [subject]- {code:ChargeItemDefinition}- code:Claimparam: [patient,payee]- code:ClaimResponseparam: [patient]- code:ClinicalImpressionparam: [subject]- {code:CodeSystem}- code:Communicationparam: [subject,sender,recipient]- code:CommunicationRequestparam: [subject,sender,recipient,requester]- {code:CompartmentDefinition}- code:Compositionparam: [subject,author,attester]- {code:ConceptMap}- code:Conditionparam: [patient,asserter]- code:Consentparam: [patient]- {code:Contract}- code:Coverageparam: [policy-holder,subscriber,beneficiary,payor]- code:CoverageEligibilityRequestparam: [patient]- code:CoverageEligibilityResponseparam: [patient]- code:DetectedIssueparam: [patient]- {code:Device}- {code:DeviceDefinition}- {code:DeviceMetric}- code:DeviceRequestparam: [subject,performer]- code:DeviceUseStatementparam: [subject]- code:DiagnosticReportparam: [subject]- code:DocumentManifestparam: [subject,author,recipient]- code:DocumentReferenceparam: [subject,author]- {code:EffectEvidenceSynthesis}- code:Encounterparam: [patient]- {code:Endpoint}- code:EnrollmentRequestparam: [subject]- {code:EnrollmentResponse}- code:EpisodeOfCareparam: [patient]- {code:EventDefinition}- {code:Evidence}- {code:EvidenceVariable}- {code:ExampleScenario}- code:ExplanationOfBenefitparam: [patient,payee]- code:FamilyMemberHistoryparam: [patient]- code:Flagparam: [patient]- code:Goalparam: [patient]- {code:GraphDefinition}- code:Groupparam: [member]- {code:GuidanceResponse}- {code:HealthcareService}- code:ImagingStudyparam: [patient]- code:Immunizationparam: [patient]- code:ImmunizationEvaluationparam: [patient]- code:ImmunizationRecommendationparam: [patient]- {code:ImplementationGuide}- {code:InsurancePlan}- code:Invoiceparam: [subject,patient,recipient]- {code:Library}- {code:Linkage}- code:Listparam: [subject,source]- {code:Location}- {code:Measure}- code:MeasureReportparam: [patient]- code:Mediaparam: [subject]- {code:Medication}- code:MedicationAdministrationparam: [patient,performer,subject]- code:MedicationDispenseparam: [subject,patient,receiver]- {code:MedicationKnowledge}- code:MedicationRequestparam: [subject]- code:MedicationStatementparam: [subject]- {code:MedicinalProduct}- {code:MedicinalProductAuthorization}- {code:MedicinalProductContraindication}- {code:MedicinalProductIndication}- {code:MedicinalProductIngredient}- {code:MedicinalProductInteraction}- {code:MedicinalProductManufactured}- {code:MedicinalProductPackaged}- {code:MedicinalProductPharmaceutical}- {code:MedicinalProductUndesirableEffect}- {code:MessageDefinition}- {code:MessageHeader}- code:MolecularSequenceparam: [patient]- {code:NamingSystem}- code:NutritionOrderparam: [patient]- code:Observationparam: [subject,performer]- {code:ObservationDefinition}- {code:OperationDefinition}- {code:OperationOutcome}- {code:Organization}- {code:OrganizationAffiliation}- code:Patientparam: [link]- {code:PaymentNotice}- {code:PaymentReconciliation}- code:Personparam: [patient]- {code:PlanDefinition}- {code:Practitioner}- {code:PractitionerRole}- code:Procedureparam: [patient,performer]- code:Provenanceparam: [patient]- {code:Questionnaire}- code:QuestionnaireResponseparam: [subject,author]- code:RelatedPersonparam: [patient]- code:RequestGroupparam: [subject,participant]- {code:ResearchDefinition}- {code:ResearchElementDefinition}- {code:ResearchStudy}- code:ResearchSubjectparam: [individual]- code:RiskAssessmentparam: [subject]- {code:RiskEvidenceSynthesis}- code:Scheduleparam: [actor]- {code:SearchParameter}- code:ServiceRequestparam: [subject,performer]- {code:Slot}- code:Specimenparam: [subject]- {code:SpecimenDefinition}- {code:StructureDefinition}- {code:StructureMap}- {code:Subscription}- {code:Substance}- {code:SubstanceNucleicAcid}- {code:SubstancePolymer}- {code:SubstanceProtein}- {code:SubstanceReferenceInformation}- {code:SubstanceSourceMaterial}- {code:SubstanceSpecification}- code:SupplyDeliveryparam: [patient]- code:SupplyRequestparam: [subject]- {code:Task}- {code:TerminologyCapabilities}- {code:TestReport}- {code:TestScript}- {code:ValueSet}- {code:VerificationResult}- code:VisionPrescriptionparam: [patient]
PUT /fhir/CompartmentDefinition/EncounterresourceType:CompartmentDefinitionid:Encounterurl:http://hl7.org/fhir/CompartmentDefinition/encounterexperimental:truename:Base FHIR compartment definition for Encounterstatus:draftpublisher:FHIR Project Teamversion:4.0.1date:'2019-11-01T09:29:23+11:00'search:truecode:Encountercontact:- telecom: - {system:url,value:'http://hl7.org/fhir'}description:There is an instance of the encounter compartment for each encounter resource, and the identity of the compartment is the same as the encounter. The set of resources associated with a particular encounterresource:- {code:Account}- {code:ActivityDefinition}- {code:AdverseEvent}- {code:AllergyIntolerance}- {code:Appointment}- {code:AppointmentResponse}- {code:AuditEvent}- {code:Basic}- {code:Binary}- {code:BiologicallyDerivedProduct}- {code:BodyStructure}- {code:Bundle}- {code:CapabilityStatement}- code:CarePlanparam: [encounter]- code:CareTeamparam: [encounter]- {code:CatalogEntry}- code:ChargeItemparam: [context]- {code:ChargeItemDefinition}- code:Claimparam: [encounter]- {code:ClaimResponse}- code:ClinicalImpressionparam: [encounter]- {code:CodeSystem}- code:Communicationparam: [encounter]- code:CommunicationRequestparam: [encounter]- {code:CompartmentDefinition}- code:Compositionparam: [encounter]- {code:ConceptMap}- code:Conditionparam: [encounter]- {code:Consent}- {code:Contract}- {code:Coverage}- {code:CoverageEligibilityRequest}- {code:CoverageEligibilityResponse}- {code:DetectedIssue}- {code:Device}- {code:DeviceDefinition}- {code:DeviceMetric}- code:DeviceRequestparam: [encounter]- {code:DeviceUseStatement}- code:DiagnosticReportparam: [encounter]- code:DocumentManifestparam: [related-ref]- code:DocumentReferenceparam: [encounter]- {code:EffectEvidenceSynthesis}- code:Encounterparam: ['{def}']- {code:Endpoint}- {code:EnrollmentRequest}- {code:EnrollmentResponse}- {code:EpisodeOfCare}- {code:EventDefinition}- {code:Evidence}- {code:EvidenceVariable}- {code:ExampleScenario}- code:ExplanationOfBenefitparam: [encounter]- {code:FamilyMemberHistory}- {code:Flag}- {code:Goal}- {code:GraphDefinition}- {code:Group}- {code:GuidanceResponse}- {code:HealthcareService}- {code:ImagingStudy}- {code:Immunization}- {code:ImmunizationEvaluation}- {code:ImmunizationRecommendation}- {code:ImplementationGuide}- {code:InsurancePlan}- {code:Invoice}- {code:Library}- {code:Linkage}- {code:List}- {code:Location}- {code:Measure}- {code:MeasureReport}- code:Mediaparam: [encounter]- {code:Medication}- code:MedicationAdministrationparam: [context]- {code:MedicationDispense}- {code:MedicationKnowledge}- code:MedicationRequestparam: [encounter]- {code:MedicationStatement}- {code:MedicinalProduct}- {code:MedicinalProductAuthorization}- {code:MedicinalProductContraindication}- {code:MedicinalProductIndication}- {code:MedicinalProductIngredient}- {code:MedicinalProductInteraction}- {code:MedicinalProductManufactured}- {code:MedicinalProductPackaged}- {code:MedicinalProductPharmaceutical}- {code:MedicinalProductUndesirableEffect}- {code:MessageDefinition}- {code:MessageHeader}- {code:MolecularSequence}- {code:NamingSystem}- code:NutritionOrderparam: [encounter]- code:Observationparam: [encounter]- {code:ObservationDefinition}- {code:OperationDefinition}- {code:OperationOutcome}- {code:Organization}- {code:OrganizationAffiliation}- {code:Patient}- {code:PaymentNotice}- {code:PaymentReconciliation}- {code:Person}- {code:PlanDefinition}- {code:Practitioner}- {code:PractitionerRole}- code:Procedureparam: [encounter]- {code:Provenance}- {code:Questionnaire}- code:QuestionnaireResponseparam: [encounter]- {code:RelatedPerson}- code:RequestGroupparam: [encounter]- {code:ResearchDefinition}- {code:ResearchElementDefinition}- {code:ResearchStudy}- {code:ResearchSubject}- {code:RiskAssessment}- {code:RiskEvidenceSynthesis}- {code:Schedule}- {code:SearchParameter}- code:ServiceRequestparam: [encounter]- {code:Slot}- {code:Specimen}- {code:SpecimenDefinition}- {code:StructureDefinition}- {code:StructureMap}- {code:Subscription}- {code:Substance}- {code:SubstanceNucleicAcid}- {code:SubstancePolymer}- {code:SubstanceProtein}- {code:SubstanceReferenceInformation}- {code:SubstanceSourceMaterial}- {code:SubstanceSpecification}- {code:SupplyDelivery}- {code:SupplyRequest}- {code:Task}- {code:TerminologyCapabilities}- {code:TestReport}- {code:TestScript}- {code:ValueSet}- {code:VerificationResult}- code:VisionPrescriptionparam: [encounter]
Although FHIR specification states that compartment definitions can only be defined by HL7 International, this restriction does not apply to Aidbox. You can define any compartments in your box so long as they are valid.
Compartment Search
To search a compartment for either all possible resources or for a particular resource, type respectively:
GET [base]/[Compartment]/[id]/{*?[parameters]{&_format=[mime-type]}}
GET [base]/[Compartment]/[id]/[type]{?[parameters]{&_format=[mime-type]}}
For example, to retrieve all the observation resources for a particular LOINC code associated with a specific encounter:
GET [base]/Encounter/23423445/Observation?code=2951-2 {&_format=[mime-type]}
Example Requests
As an example of compartment usage, to retrieve a list of a patient's conditions, use the URL:
GET [base]/Patient/[id]/Condition
Additional search parameters can be defined, such as this hypothetical search for acute conditions:
GET [base]/Patient/[id]/Condition?code:in=http://hspc.org/ValueSet/acute-concerns
Our example compartment search is basically equivalent to these standard FHIR search requests:
GET [base]/Condition?patient=[id]
GET [base]/Condition?patient=[id]&code:in=http://hspc.org/ValueSet/acute-concerns
The outcome of a compartment search is the same as the equivalent FHIR search. For example, both these searches return the same outcome if there is no patient 333:
GET [base]/Patient/333/Condition
GET [base]/Condition?patient=333
If the patient doesn't exist or the user has no access to the patient, both these searches return an empty bundle with no matches.
However, there is a key difference in functionality between compartment-based searches and direct searches with parameters. Consider this search:
GET [base]/Patient/[id]/Communication
Because the definition of the patient compartment for Communication says that a Communication resource is in the patient compartment if the subject, sender, or recipient is the patient, the compartment search is actually the same as the union of these 3 searches:
GET [base]/Communication?subject=[id]
GET [base]/Communication?sender=[id]
GET [base]/Communication?recipient=[id]