secondaryBannerCommonFetchFunction static method
Future<void>
secondaryBannerCommonFetchFunction({
- required StreamController streamController,
- required String queryString,
- required BuildContext context,
Implementation
static Future<void> secondaryBannerCommonFetchFunction({
required StreamController<dynamic> streamController,
required String queryString,
required BuildContext context,
}) async {
final SecondaryBannerInfoObject secondaryBannerInfoObject =
SecondaryBannerInfoObject();
final IGraphQlClient _client = AppWrapperBase.of(context)!.graphQLClient;
final Map<String, dynamic> _variables = <String, dynamic>{
'params': <String, dynamic>{
'patient': getPatientInfo().patientId,
}
};
// toggle loading indicator
streamController.add(<String, dynamic>{'loading': true});
final http.Response result = await _client.query(queryString, _variables);
final Map<String, dynamic> payLoad = _client.toMap(result);
//check first for errors
if (_client.parseError(payLoad) != null) {
streamController
.addError(<String, dynamic>{'error': _client.parseError(payLoad)});
return;
}
if (payLoad['data'] != null) {
if (queryString == findPatientsExistingConditionsQuery) {
// the payload as a data object
final ConditionRelayConnection conditionRelayConnection =
ConditionRelayConnection.fromJson(
payLoad['data']['searchFHIRCondition'] as Map<String, dynamic>);
final List<ConditionEdgeRelay?>? conditionEdgesRelays =
conditionRelayConnection.edges;
secondaryBannerInfoObject.problemsList.add(conditionEdgesRelays);
} else if (queryString == findPatientExistingAllergiesQuery) {
// the payload as data class object
final AllergyIntoleranceRelayConnection
allergyIntoleranceRelayConnection =
AllergyIntoleranceRelayConnection.fromJson(payLoad['data']
['searchFHIRAllergyIntolerance'] as Map<String, dynamic>);
final List<AllergyIntoleranceRelayEdge?>? allergyIntoleranceRelayEdges =
allergyIntoleranceRelayConnection.edges;
secondaryBannerInfoObject.allergiesList
.add(allergyIntoleranceRelayEdges);
} else if (queryString == findPatientExistingMedicationQuery) {
// the payload as data class object
final MedicationRelayConnection medicationRelayConnection =
MedicationRelayConnection.fromJson(payLoad['data']
['searchFHIRMedicationRequest'] as Map<String, dynamic>);
final List<MedicationEdgeRelay?>? medicationrelayEdges =
medicationRelayConnection.edges;
secondaryBannerInfoObject.medicationsList.add(medicationrelayEdges);
}
return streamController.add(payLoad['data']);
}
return streamController.add(null);
}