The is operator, as operator, and ofType() function currently only perform exact type matching and do not recognize FHIR type inheritance. According to the FHIRPath specification, these should return true for "the type specified in the second operand, or a subclass thereof."
Failing test cases:
Observation is DomainResource → Expected: true, Got: false
Observation is Resource → Expected: true, Got: false
Observation.value is Element → Expected: true, Got: false
Patient.contact is Element → Expected: true, Got: false
Root Cause:
The current implementation in Collection.filterByType() uses exact type matching via equals():
case FHIR_NAMESPACE -> getFhirType().filter(type.toFhirType()::equals).map(t -> this);
Implementation Note:
Use HAPI FHIR implementation classes to check for subtypes. FHIR type names follow a consistent naming convention to their implementing classes in the R4 model (e.g., "Element" → org.hl7.fhir.r4.model.Element). Use Class.isAssignableFrom() to check inheritance relationships.
Affected Components:
Collection.filterByType()
ResourceCollection.filterByType()
is operator
as operator
ofType() function
The
isoperator,asoperator, andofType()function currently only perform exact type matching and do not recognize FHIR type inheritance. According to the FHIRPath specification, these should return true for "the type specified in the second operand, or a subclass thereof."Failing test cases:
Observation is DomainResource→ Expected: true, Got: falseObservation is Resource→ Expected: true, Got: falseObservation.value is Element→ Expected: true, Got: falsePatient.contact is Element→ Expected: true, Got: falseRoot Cause:
The current implementation in
Collection.filterByType()uses exact type matching viaequals():Implementation Note:
Use HAPI FHIR implementation classes to check for subtypes. FHIR type names follow a consistent naming convention to their implementing classes in the R4 model (e.g., "Element" →
org.hl7.fhir.r4.model.Element). UseClass.isAssignableFrom()to check inheritance relationships.Affected Components:
Collection.filterByType()ResourceCollection.filterByType()isoperatorasoperatorofType()function