find method

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

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 - which can be nested, and the value you're looking for in that field From the sembast documentation: https://github.com/tekartik/sembast.dart/blob/master/sembast/doc/queries.md Assuming you have the following record: { "resourceType": "Immunization", "patient": { "reference": "Patient/12345" } } You can search for the nested value using a Finder Finder(filter: Filter.equals('patient.reference', 'Patient/12345'));

Implementation

Future<List<Resource>> find(
  String? password, {
  Resource? resource,
  Dstu2ResourceType? resourceType,
  Id? id,
  String? field,
  String? value,
}) async {
  if ((resource != null && resource.resourceType != null) ||
      (resourceType != null && id != null) ||
      (resourceType != null && field != null && value != null)) {
    Finder finder;
    if (resource != null) {
      finder = Finder(filter: Filter.equals('id', '${resource.id}'));
    } else if (resourceType != null && id != null) {
      finder = Finder(filter: Filter.equals('id', '$id'));
    } else {
      finder = Finder(filter: Filter.equals(field!, value));
    }

    _setStoreType(ResourceUtils
        .resourceTypeToStringMap[resource?.resourceType ?? resourceType]!);
    return await _search(password, finder);
  } 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');
  }
}