| description | Produce an OperationOutcome for the FHIR $validate operation. |
|---|---|
| icon | file-circle-check |
FHIRValidationService::validateForOperation() runs validation and returns a
standards-compliant OperationOutcomeResource, suitable for implementing the $validate
operation on a FHIR server. Pass the target FHIR version ('R4', 'R4B', or 'R5') to
receive a version-typed resource.
$outcome = $service->validateForOperation($patient, fhirVersion: 'R4');
// $outcome is an Ardenexal\FHIRTools\Component\Models\R4\Resource\OperationOutcomeResource
$outcome = $service->validateForOperation($patient, mode: 'create', fhirVersion: 'R5');
// $outcome is an Ardenexal\FHIRTools\Component\Models\R5\Resource\OperationOutcomeResourceThe method signature is:
public function validateForOperation(
object $resource,
string $mode = '',
array $profileUrls = [],
string $fhirVersion = 'R4',
): objectAccepted mode values are '', create, update, profile, and delete; any other value
throws \InvalidArgumentException. Internally the service builds a FHIRValidationReport,
then hands it to FHIRValidationReportMapper::toOperationOutcome($report, $fhirVersion), which
produces the version-appropriate resource. An unsupported $fhirVersion throws
\InvalidArgumentException.
Each FHIRValidationViolation becomes one OperationOutcomeIssue. Severity maps directly;
OperationOutcomeIssue.code is derived from the violation's code and constraintClass.
The violation path is emitted as OperationOutcomeIssue.expression (omitted when empty),
and message becomes diagnostics.
FHIRValidationViolation::$severity |
OperationOutcomeIssue::$severity |
OperationOutcomeIssue::$code |
|---|---|---|
error |
error |
invariant (FHIRPath invariant), value (value-set binding), invalid (default) |
warning |
warning |
same mapping as above |
info (fhir:eval-error) |
information |
not-supported |
info (fhir:unchecked-binding) |
information |
not-supported |
info (fhir:info, general) |
information |
informational |
The code selection follows FHIRValidationReportMapper::mapIssueType():
FHIRViolationCode::EVAL_ERROR,FHIRViolationCode::UNCHECKED_BINDING, or any violation whoseconstraintClassisFHIRValidationService::class→not-supported.FHIRViolationCode::INFO→informational.- Otherwise, by
constraintClass:FHIRPathInvariant::class→invariant,FHIRValueSetBinding::class→value, default →invalid.
{% hint style="info" %}
Sub-codes such as invariant and value are not cases of the generated IssueTypeType enum
but are valid codes in the FHIR issue-type value set; the mapper passes them as raw strings.
{% endhint %}
When no violations are found, the outcome contains a single information-severity issue with
code informational and diagnostics "No issues found — resource is valid."
The $validate operation endpoint per spec:
POST [base]/[ResourceType]/$validate?profile=[profile-url]
The operation returns HTTP 200 OK whenever validation ran successfully, regardless of findings. Structural errors (unparseable JSON/XML) may produce 4xx responses before this library is reached.
{% hint style="warning" %}
mode=delete is not supported: referential integrity checks require a FHIR server context.
A call with mode: 'delete' returns an information-severity outcome explaining the
limitation rather than running resource validation.
{% endhint %}
See Validation Reports & Violation Codes for the underlying report structure.