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 if (entry.response?.outcome != null) {
if (entry.response!.outcome is OperationOutcome) {
if (isInformational(entry.response!.outcome! as OperationOutcome)) {
returnResults.informationOperationOutcomes
.add(entry.response!.outcome! as OperationOutcome);
} else {
returnResults.errorOperationOutcomes
.add(entry.response!.outcome! as OperationOutcome);
}
} else {
returnResults.resources.add(entry.response!.outcome!);
}
} else {
returnResults.informationOperationOutcomes.add(
OperationOutcome(
issue: <OperationOutcomeIssue>[
OperationOutcomeIssue(
code: OperationOutcomeIssueCode.informational,
diagnostics: 'Status: ${entry.response?.status ?? "none"}'
'\nLocation: ${entry.response?.location ?? "none"}',
),
],
),
);
}
}
}
return returnResults;
}