find method

Future<List<Resource>> find({
  1. Resource? resource,
  2. R5ResourceType? resourceType,
  3. String? id,
  4. List<Object>? field,
  5. String? value,
  6. String? pw,
})

searches for a specific Resource. That resource can be defined by passing a full Resource object, you may pass a resourceType and id or you can pass a search field - since we are dealing with maps, this should be a list of strings or integers, and this function will walk through them:

field = 'name', 'given', 2 newValue = resource'name'; newValue = newValue'given'; newValue = newValue2;

Implementation

Future<List<Resource>> find({
  Resource? resource,
  R5ResourceType? resourceType,
  String? id,
  List<Object>? field,
  String? value,
  String? pw,
}) async {
  /// if we're just trying to match a resource
  if (resource != null &&
      resource.resourceType != null &&
      (resource.fhirId != null || id != null)) {
    final Resource? result = await get(
      resourceType: resource.resourceType!,
      id: resource.fhirId!.value!,
      pw: pw,
    );
    return result == null ? <Resource>[] : <Resource>[result];
  } else if (resourceType != null && id != null) {
    final Resource? result = await get(
      resourceType: resourceType,
      id: id,
      pw: pw,
    );
    return result == null ? <Resource>[] : <Resource>[result];
  } else if (resourceType != null && field != null && value != null) {
    bool finder(Map<String, dynamic> finderResource) {
      dynamic result = finderResource;
      for (final Object key in field) {
        result = result[key];
      }
      return result.toString() == value;
    }

    return (await search(resourceType: resourceType, finder: finder, pw: pw))
        .toList();
  } else {
    throw const FormatException('Must have either: '
        '\n1) a resource with a resourceType'
        '\n2) a resourceType and an Id'
        '\n3) a resourceType, a specific field, and the value of interest');
  }
}