Skip to content

Refactor resource routing to use fhirType() and improve tests#1035

Open
jkiddo wants to merge 3 commits into
cqframework:mainfrom
trifork:fix/canonical
Open

Refactor resource routing to use fhirType() and improve tests#1035
jkiddo wants to merge 3 commits into
cqframework:mainfrom
trifork:fix/canonical

Conversation

@jkiddo
Copy link
Copy Markdown
Contributor

@jkiddo jkiddo commented May 18, 2026

This pull request refactors and enhances the ProcessDefinition class in the PlanDefinition apply logic, focusing on more robust resource resolution, improved error handling, and simplifying code paths for applying definitions. The changes also update the associated unit tests to cover new behaviors and edge cases.

Resource resolution improvements:

  • Introduced a new method resolveCanonicalByType that searches for a canonical reference across all supported definition types (PlanDefinition, ActivityDefinition, Questionnaire) in parallel, using a transaction bundle. This removes the need to infer resource type from the canonical URL and ensures more reliable and unambiguous resolution.
  • Removed the resolveResourceName method, replacing type inference with actual resource inspection and search. [1] [2]
  • Added a static list SUPPORTED_DEFINITION_TYPES to define which resource types are considered for canonical resolution.

Error handling and code simplification:

  • Refactored applyActivityDefinition and applyNestedPlanDefinition to separate resource resolution from application logic, improving clarity and error reporting. The error messages now reference the actual resource ID. [1] [2] [3] [4]
  • Improved error handling when multiple resources match a canonical reference, providing hints to specify a version to resolve ambiguity.

Testing enhancements:

  • Updated and expanded unit tests in ProcessDefinitionTests to cover new resolution logic, exception handling, and edge cases, including the use of Mockito to simulate exceptions and resource returns. [1] [2] [3] [4]

These changes make the PlanDefinition apply logic more robust, maintainable, and easier to extend for additional definition types or FHIR versions.

References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

jkiddo added 3 commits May 18, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant