| description | Populate and extract FHIR resources for SDC Questionnaires. |
|---|---|
| icon | file-export |
The SDC component implements Structured Data Capture
operations for FHIR PHP model objects. Today it delivers two operations:
QuestionnaireResponse/$extract — turning a completed QuestionnaireResponse into FHIR
resources per the SDC extraction operation —
and Questionnaire/$populate — pre-filling a QuestionnaireResponse from launch context per the
SDC populate operation.
It supports R4, R4B, and R5.
use Ardenexal\FHIRTools\Component\Sdc\ExtractContext;
use Ardenexal\FHIRTools\Component\Sdc\FHIRQuestionnaireResponseExtractService;
use Ardenexal\FHIRTools\Component\Serialization\FhirVersion;
$service = new FHIRQuestionnaireResponseExtractService();
$result = $service->extract($questionnaireResponse, new ExtractContext(
fhirVersion: FhirVersion::R4, // output model namespace (R4 / R4B / R5)
questionnaire: $questionnaire, // the source Questionnaire carrying the extract directives
emitProvenance: false, // opt-in Provenance entry
));
$bundle = $result->getResource(); // a transaction Bundle (always)
$issues = $result->getIssues(); // an OperationOutcome, or null when nothing to reportuse Ardenexal\FHIRTools\Component\Sdc\BundlePopulationDataProvider;
use Ardenexal\FHIRTools\Component\Sdc\FHIRQuestionnairePopulateService;
use Ardenexal\FHIRTools\Component\Sdc\PopulateContext;
use Ardenexal\FHIRTools\Component\Serialization\FhirVersion;
$service = new FHIRQuestionnairePopulateService();
$result = $service->populate($questionnaire, new PopulateContext(
fhirVersion: FhirVersion::R4, // output model namespace (R4 / R4B / R5)
launchContextResources: ['patient' => $patient], // bound as FHIRPath %patient, …
subject: 'Patient/123', // sets QuestionnaireResponse.subject (optional)
dataProvider: new BundlePopulationDataProvider($dataBundle), // observation-based (optional)
));
$response = $result->getResponse(); // a QuestionnaireResponse (status: in-progress)
$issues = $result->getIssues(); // an OperationOutcome, or null when nothing to report- Three extraction methods — observation-based (R4 only), definition-based
(
definitionExtract/definitionExtractValue), and template-based (#containedtemplates). A single Questionnaire may mix all three; results merge into one Bundle. - Transaction-Bundle output — the payload is always a
transactionBundle. Eachentry.requestisPOST Type(no logical id) orPUT Type/id(id present) — extraction is create/update only, never delete. - Graceful degradation — an empty extraction yields an empty Bundle plus an
informationOperationOutcome; a malformed expression warns and skips that entry rather than failing the run. - Opt-in
Provenance— passemitProvenance: trueto add aProvenanceentry linking the extracted resources back to the sourceQuestionnaireResponse.
Questionnaire/$populate pre-fills a QuestionnaireResponse from a Questionnaire's SDC
population directives — expression-based (launchContext + initialExpression, variable
chains, itemPopulationContext) and observation-based (observationLinkPeriod). Call
FHIRQuestionnairePopulateService::populate($questionnaire, new PopulateContext(...)); the
returned PopulateResult carries the generated QuestionnaireResponse (status
in-progress) plus an optional OperationOutcome. Population is offline-first and
FHIRPath-only — the component README is canonical for the supported-mechanisms table and
exclusions.
The component README is canonical for the full supported-methods table, output contract,
and current exclusions (StructureMap-based extraction, templateExtractBundle, live
persistence, and access control): see src/Component/Sdc/README.md.