Skip to main content

LegitimateInterest

This validator checks if the client has a legitimate interest to the resource that it is requesting. The checks for this depend on the client's role.

If the client is a patient, the validator essentially behaves like the PatientCompartment validator with a few additions:

  • The Organization entity assigned via Patient.managingOrganization is allowed.
  • Every Practitioner entity which has an active role in Patient.managingOrganization is allowed.
  • Every PractitionerRole entity which belongs to Patient.managingOrganization is allowed.

If the client is a practitioner, the validator builds something like an "organization compartment". The organization compartment consists of all entities that are linked to the organization. This includes all patients that have set the Patient.managingOrganization property to the corresponding organization, as well as all records in the corresponding patient compartments.

A practitioner has access to all organization compartments in which they have an active role. The configuration can optionally specify a mandatory role code and system that needs to be present. This way, it is possible to model scenarios where only someone with an "ict" role can create new practitioners for an organization but can not read any patient data, while someone with a "doctor" role can read and write patient data but not create practitioners or change other organizational entities.

When specifying practitioner role codes, both system and code must be specified. Specifying only one value will produce unexpected results.

The validator is powerful but also quite expensive to run. To speed it up, it caches internal requests to the data it needs, such as practitioner roles, organizations and patient entities. The cache has a default, short-lived timeout of 2 minutes but this also means that updates to permissions (such as when changing a practitioner role) will not be effective immediately.

If you route read operations through this validator, it makes sense to also route write operations concerning the same role and the same entity through this validator. That way, the validator has the possibility to clear its cache whenever entities are changed. (automated cache invalidations are not implemented yet)

It is important to note that this validator is not intended to replace the PatientCompartment or PractitionerCompartment validators. It is intended to give implementers the ability to express different ways to validate access. It is preferable to use the compartment validators if they achieve the same thing.

NOTE: For resource creation requests, where a legitimate interest cannot be established for the client that is making that request an unauthorized response is returned. For resource creation, explicitly define a rule that allows that.

Validation Strategy Per Entity

The table below lists the validation strategies per entity and per role. The following definitions apply:

  • ActiveOrganizations = PractitionerRole.where(practitioner == Practitioner.id && active == true).organization
  • Practitioner clients need to have an affiliation with an organization that owns or manages the requested record.
  • Where a compartment specifies multiple potential relationships, only one is supported in the code at the moment.
  • Compartment validations noted with !! are currently non-functional due to how look-ups are implemented. (related ticket)
EntityPractitioner RolePatient Role
Accountsubject.managingOrganization in ActiveOrganizationsPatientCompartment
AdverseEventsubject.managingOrganization in ActiveOrganizationsPatientCompartment
AllergyIntolerancesubject.managingOrganization in ActiveOrganizationsPatientCompartment
AppointmentResponseactor.managingOrganization in ActiveOrganizationsPatientCompartment
Appointment!! PatientCompartment
AuditEvent!! PatientCompartment
BasicPatientCompartment
BodyStructurePatientCompartment
CarePlansubject.managingOrganization in ActiveOrganizationsPatientCompartment
CareTeamPatientCompartment
ChargeItemPatientCompartment
ClaimResponsepatient.managingOrganization in ActiveOrganizationsPatientCompartment
Claimpatient.managingOrganization in ActiveOrganizationsPatientCompartment
ClinicalImpressionsubject.managingOrganization in ActiveOrganizationsPatientCompartment
CommunicationRequestsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Communicationsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Compositionsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Conditionsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Consentpatient.managingOrganization in ActiveOrganizationsPatientCompartment
Contractsubject.managingOrganization in ActiveOrganizationsOrganizationCompartment
CoverageEligibilityRequestpatient.managingOrganization in ActiveOrganizationsPatientCompartment
Coveragebeneficiary.managingOrganization in ActiveOrganizationsPatientCompartment
DetectedIssuepatient.managingOrganization in ActiveOrganizationsPatientCompartment
DeviceDefinitionowner in ActiveOrganizationsowner = managingOrganization
DeviceRequestPatientCompartment
DeviceUseStatementPatientCompartment
Deviceowner in ActiveOrganizationsowner = managingOrganization
DiagnosticReportsubject.managingOrganization in ActiveOrganizationsPatientCompartment
DocumentManifestPatientCompartment
DocumentReferencesubject.managingOrganization in ActiveOrganizationsPatientCompartment
Encountersubject.managingOrganization in ActiveOrganizationsPatientCompartment
EnrollmentRequestcandidate.managingOrganization in ActiveOrganizationsPatientCompartment
EnrollmentResponseOrganizationCompartment
EpisodeOfCarepatient.managingOrganization in ActiveOrganizationsPatientCompartment
ExplanationOfBenefitpatient.managingOrganization in ActiveOrganizationsPatientCompartment
FamilyMemberHistorypatient.managingOrganization in ActiveOrganizationsPatientCompartment
FhirGroup!! PatientCompartment
Flagsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Goalsubject..managingOrganization in ActiveOrganizationsPatientCompartment
GuidanceResponsesubject.managingOrganization in ActiveOrganizationsOrganizationCompartment
HealthcareServiceprovidedBy in ActiveOrganizationsprovidedBy = managingOrganization
ImagingStudysubject.managingOrganization in ActiveOrganizationsPatientCompartment
ImmunizationEvaluationpatient.managingOrganization in ActiveOrganizationsPatientCompartment
ImmunizationRecommendationpatient.managingOrganization in ActiveOrganizationsPatientCompartment
Immunizationpatient.managingOrganization in ActiveOrganizationsPatientCompartment
InsurancePlanownedBy in ActiveOrganizationsownedBy = managingOrganization
Invoicesubject.managingOrganization in ActiveOrganizationsPatientCompartment
LocationmanagingOrganization in ActiveOrganizationsmanagingOrganization = managingOrganization
MeasureReportsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Mediasubject.managingOrganization in ActiveOrganizationsPatientCompartment
MedicationAdministrationsubject.managingOrganization in ActiveOrganizationsPatientCompartment
MedicationDispensesubject.managingOrganization in ActiveOrganizationsPatientCompartment
MedicationRequestsubject.managingOrganization in ActiveOrganizationsPatientCompartment
MedicationStatementsubject.managingOrganization in ActiveOrganizationsPatientCompartment
MolecularSequencePatientCompartment
NutritionOrderpatient.managingOrganization in ActiveOrganizationsPatientCompartment
Observationsubject.managingOrganization in ActiveOrganizationsPatientCompartment
OrganizationAffiliationorganization in ActiveOrganizationsorganization = managingOrganization
Organizationid in ActiveOrganizationsOrganization = Patient.generalPractitioner or Organization = Patient.managingOrganization
PatientmanagingOrganization in ActiveOrganizationsidentity resource
PaymentNoticeprovider in ActiveOrganizationsprovider = managingOrganization
PaymentReconciliationrequestor in ActiveOrganizationsrequestor = managingOrganization
PersonmanagingOrganization in ActiveOrganizations!! PatientCompartment
PractitionerRoleorganization in ActiveOrganizationsPractitionerRole = Patient.generalPractitioner or PractitionerRole.organization = Patient.managingOrganization
Practitionerrole.organization in ActiveOrganizations OR id == selfPractitioner = Patient.generalPractitioner or OrganizationCompartment
Proceduresubject.managingOrganization in ActiveOrganizationsPatientCompartment
Provenance!! PatientCompartment
QuestionnaireResponsesubject.managingOrganization in ActiveOrganizationsPatientCompartment
RegulatedAuthorizationholder in ActiveOrganizationsholder = managingOrganization
RelatedPersonpatient.managingOrganization in ActiveOrganizationsPatientCompartment
RequestGroupsubject.managingOrganization in ActiveOrganizationsPatientCompartment
ResearchStudysponsor in ActiveOrganizationssponsor = managingOrganization
ResearchSubjectindividual.managingOrganization in ActiveOrganizationsPatientCompartment
RiskAssessmentsubject.managingOrganization in ActiveOrganizationsPatientCompartment
SchedulePatientCompartment
ServiceRequestsubject.managingOrganization in ActiveOrganizationsPatientCompartment
Specimensubject.managingOrganization in ActiveOrganizationsPatientCompartment
SupplyDeliverypatient.managingOrganization in ActiveOrganizationsPatientCompartment
SupplyRequestsupplier in ActiveOrganizationsPatientCompartment
VisionPrescriptionpatient.managingOrganization in ActiveOrganizationsPatientCompartment

Role Inheritance

The setting legitimateInterestRoleInheritanceLevels in the configuration file controls if roles in an organization should be inherited to child organizations. This supports the following use cases:

  • A hospital can be broken down into multiple independent units where general staff and admin staff at the parent unit can see all data, whereas staff located in a department of the hospital can only see data belonging to that specific department.
  • SaaS solutions looking to provide admin support for their customers can create a virtual "root" organization. All customers looking for support can make themselves a member of this root organization, which will immediately allow admins of the root organization to see all customer data. Visibility can be turned on and off at will.

Role inheritance requires one additional network request per org level per validated request, so its impact on response time is considerable and should only be used when and where necessary.