Stream: shorthand
Topic: Stack overflow question
Lloyd McKenzie (Oct 02 2021 at 01:45):
Anyone willing to answer this one: https://stackoverflow.com/questions/69412586/how-to-make-a-field-required-based-on-another-field-in-fsh-fhir-shorthand-lang
Chris Moesel (Oct 02 2021 at 13:55):
Done. Since this is a question others may have, I'll post the answer here as well. The question is basically How can I profile DetectedIssue so that mitigation is required if the status is final?
Answer: Any constraints that depend on relationships between elements (like status
and mitigation
) can only be constrained using an invariant. Invariants are set on ElementDefinition.constraint in FHIR, but FSH has a special mechanism for invariants documented here. The most difficult thing about invariants is that they use another language, called FHIRPath, to express the constraint. You should look at the core FHIRPath documentation as well as the FHIR-specific FHIRPath documentation.
For your specific example, you would first define your invariant. The special FHIRPath expression is in the Expression field:
Invariant: final-mitigation
Description: "If DetectedIssue.status is final, then DetectedIssue.mitigation must be present"
Expression: "status = 'final' implies mitigation.exists()"
Severity: #error
Then, since it talks about two elements, relative to the root of the resource, you add a top-level obeys rule to your profile that brings in the invariant you just created:
* obeys final-mitigation
Last updated: Apr 12 2022 at 19:14 UTC