build method
Implementation
@override
Future<Filter<HealthcareElement>> build() async {
if (_dataOwnerId == null) {
throw FormatException("Data Owner must be set for patient filter.");
}
List<Filter<HealthcareElement>> filters = [
_byIds?.let((v) => HealthcareElementByIdsFilter(ids: v)),
_byIdentifiers?.let((v) => HealthcareElementByHcPartyIdentifiersFilter(hcPartyId: _dataOwnerId!, identifiers: v.toList())),
_byTagCodeFilter?.let((v) {
v.healthcarePartyId = _dataOwnerId!;
return v;
}),
await _forPatients?.let((v) async => HealthcareElementByHcPartyPatientFilter(
healthcarePartyId: _dataOwnerId!,
patientSecretForeignKeys: (await Future.wait(v.item2.map((p) => v.item1.decryptEncryptionKeys(
_dataOwnerId!, (p.systemMetaData?.delegations ?? {}).map((k, v) => MapEntry(k, v.map((d) => d.toDelegationDto()).toSet()))))))
.toSet()
.flatten())),
await _union?.let(
(v) async => UnionFilter<HealthcareElement>(filters: await Future.wait(v.map((f) async => await f.forDataOwner(f.dataOwnerId ?? _dataOwnerId!).build()).toList()))),
await _intersection?.let((v) async =>
IntersectionFilter<HealthcareElement>(filters: await Future.wait(v.map((f) async => await f.forDataOwner(f.dataOwnerId ?? _dataOwnerId!).build()).toList())))
].whereType<Filter<HealthcareElement>>().toList();
if (filters.isEmpty) {
return HealthcareElementByHcPartyFilter(hcpId: _dataOwnerId!);
} else if (filters.length == 1) {
return filters[0];
} else {
return IntersectionFilter(filters: filters);
}
}