search<T> method
Future<Result<T> >
search<T>(
- String baseUri, {
- required ResourceType resourceType,
- String version = 'baseR4',
- String? queryString,
Search for resources of type T
. Prefer the other functions starting with
search
for specific resources.
Implementation
Future<Result<T>> search<T>(
String baseUri, {
required ResourceType resourceType,
String version = 'baseR4',
String? queryString,
}) async =>
switch (await getResource<T>(
baseUri,
'$version/${resourceType.code}${queryString != null ? '?$queryString' : ''}',
)) {
//Error
(final OperationOutcome<T> o) => o,
(final Bundle b)
//Check all items are the correct type
when b.entry != null &&
b.entry!.every((entry) => entry.resource is T) =>
BundleEntries<T>(
FixedList(
b.entry!.map(
(entry) =>
//This is not very nice but we already checked
//for null and type above
entry.resource! as T,
),
),
b,
),
//Unexpected Result
(final Resource r) => OperationOutcome.error(
status: NarrativeStatus.empty,
details: 'Expected a list of ${resourceType.code}s, but '
'got a ${r.runtimeType}',
),
};