parseBundleForType<T> function
Extracts all Resources that were returned by the Bundle as long as they are of type T
Implementation
ReturnResults<T> parseBundleForType<T>(Bundle bundle) {
final ReturnResults<T> returnResults = ReturnResults<T>();
if (bundle.type == FhirCode('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 if (entry.resource is T) {
returnResults.resources.add(entry.resource! as T);
} else {
returnResults.errorOperationOutcomes
.add(incorrectResultType<T>(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 if (entry.response!.outcome is T) {
returnResults.resources.add(entry.response!.outcome! as T);
} else {
returnResults.errorOperationOutcomes
.add(incorrectResultType<T>(entry.response!.outcome!));
}
} else {
returnResults.informationOperationOutcomes.add(
OperationOutcome(
issue: <OperationOutcomeIssue>[
OperationOutcomeIssue(
code: FhirCode('informational'),
diagnostics: 'Status: ${entry.response?.status ?? "none"}'
'\nLocation: ${entry.response?.location ?? "none"}',
),
],
),
);
}
}
}
return returnResults;
}