build method

  1. @override
Future<Filter<Patient>> build()
override

Implementation

@override
Future<Filter<Patient>> build() async {
  if (_dataOwnerId == null) {
    throw FormatException("Hcp must be set for patient filter.");
  }
  final String dataOwnerId = _dataOwnerId!;

  List<Filter<Patient>> filters = [
    _byIds?.let((v) => PatientByIdsFilter(ids: v.toList())),
    _byIdentifiers?.let((v) => PatientByHcPartyAndIdentifiersFilter(healthcarePartyId: dataOwnerId, identifiers: v.toList())),
    _withSsins?.let((v) => PatientByHcPartyAndSsinsFilter(healthcarePartyId: dataOwnerId, ssins: v.toList())),
    _dateOfBirthBetween?.let((v) => PatientByHcPartyDateOfBirthBetweenFilter(
        healthcarePartyId: dataOwnerId, minDateOfBirth: v.item1?.toFuzzy(), maxDateOfBirth: v.item2?.toFuzzy())),
    _byGenderEducationProfession?.let((v) =>
        PatientByHcPartyGenderEducationProfessionFilter(healthcarePartyId: dataOwnerId, gender: v.item1, education: v.item2, profession: v.item3)),
    _containsFuzzy?.let((v) => PatientByHcPartyNameContainsFuzzyFilter(healthcarePartyId: dataOwnerId, searchString: v)),
    await _union
        ?.let((v) async => UnionFilter<Patient>(filters: await Future.wait(v.map((f) async => await f.forDataOwner(f.dataOwnerId ?? dataOwnerId).build()).toList()))),
    await _intersection?.let(
        (v) async => IntersectionFilter<Patient>(filters: await Future.wait(v.map((f) async => await f.forDataOwner(f.dataOwnerId ?? dataOwnerId).build()).toList())))
  ].whereType<Filter<Patient>>().toList();

  if (filters.isEmpty) {
    return PatientByHcPartyFilter(healthcarePartyId: dataOwnerId);
  } else if (filters.length == 1) {
    return filters[0];
  } else {
    return IntersectionFilter(filters: filters);
  }
}