parseBundle function
Extracts all Resources that were returned by the Bundle, as long as they aren't OperationOutcomes, and includes all entries as informational OperationOutcomes that don't contain a Resource
Implementation
ReturnResults<Resource> parseBundle(Bundle bundle) {
final ReturnResults<Resource> returnResults = ReturnResults<Resource>();
if (bundle.type == BundleType.transaction_response) {
for (final BundleEntry entry in bundle.entry ?? <BundleEntry>[]) {
if (entry.resource != null) {
if (entry.resource is OperationOutcome) {
if (isInformational(entry.resource! as OperationOutcome)) {
returnResults.informationOperationOutcomes
.add(entry.resource! as OperationOutcome);
} else {
returnResults.errorOperationOutcomes
.add(entry.resource! as OperationOutcome);
}
} else {
returnResults.resources.add(entry.resource!);
}
} else {
returnResults.informationOperationOutcomes.add(
OperationOutcome(
issue: <OperationOutcomeIssue>[
OperationOutcomeIssue(
severity: IssueSeverity.error,
code: FhirCode('informational'),
diagnostics: 'Status: ${entry.response?.status ?? "none"}'
'\nLocation: ${entry.response?.location ?? "none"}',
),
],
),
);
}
}
}
return returnResults;
}