NEW: Patient Manager Provider Setup pt4
This commit is contained in:
@@ -2,10 +2,13 @@ import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/patient_access.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_providers/mih_access_controlls_provider.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_notification_services.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class MihAccessControlsServices {
|
||||
@@ -32,6 +35,98 @@ class MihAccessControlsServices {
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to create patient access and trigger notification to patient
|
||||
///
|
||||
/// Patameters:-
|
||||
/// String business_id,
|
||||
/// String app_id,
|
||||
/// String type,
|
||||
/// String requested_by,
|
||||
/// BuildContext context,
|
||||
///
|
||||
/// Returns void (triggers notification of success 201).
|
||||
static Future<void> addPatientAccessAPICall(
|
||||
String business_id,
|
||||
String app_id,
|
||||
String type,
|
||||
String requested_by,
|
||||
bool personalSelected,
|
||||
BusinessArguments args,
|
||||
BuildContext context,
|
||||
) async {
|
||||
var response = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/access-requests/insert/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
// business_id: str
|
||||
// app_id: str
|
||||
// type: str
|
||||
// requested_by: str
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": business_id,
|
||||
"app_id": app_id,
|
||||
"type": type,
|
||||
"requested_by": requested_by,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 201) {
|
||||
await MihNotificationApis.addAccessRequestNotificationAPICall(
|
||||
app_id, requested_by, personalSelected, args, context);
|
||||
} else {
|
||||
internetConnectionPopUp(context);
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is used to reapply for access to patient.
|
||||
///
|
||||
/// Patameters:-
|
||||
/// String business_id,
|
||||
/// String app_id,
|
||||
/// BuildContext context,
|
||||
///
|
||||
/// Returns void (on success 200 navigate to /mih-access ).
|
||||
static Future<void> reapplyPatientAccessAPICall(
|
||||
String business_id,
|
||||
String app_id,
|
||||
bool personalSelected,
|
||||
BusinessArguments args,
|
||||
BuildContext context,
|
||||
) async {
|
||||
var response = await http.put(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/access-requests/re-apply/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
// business_id: str
|
||||
// app_id: str
|
||||
// status: str
|
||||
// approved_by: str
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": business_id,
|
||||
"app_id": app_id,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
await MihNotificationApis.reapplyAccessRequestNotificationAPICall(
|
||||
app_id, personalSelected, args, context);
|
||||
//notification here
|
||||
} else {
|
||||
internetConnectionPopUp(context);
|
||||
}
|
||||
}
|
||||
|
||||
static void internetConnectionPopUp(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHErrorMessage(
|
||||
errorType: "Internet Connection",
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// This function is used to UPDATE access the business has.
|
||||
///
|
||||
/// Patameters:-
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:ken_logger/ken_logger.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/files.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/notes.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/patient_access.dart';
|
||||
@@ -26,7 +25,6 @@ class MihPatientServices {
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
KenLogger.success(response.body);
|
||||
var jsonBody = jsonDecode(body);
|
||||
Patient patient = Patient.fromJson(jsonBody);
|
||||
patientManagerProvider.setSelectedPatient(selectedPatient: patient);
|
||||
@@ -36,6 +34,24 @@ class MihPatientServices {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<List<Patient>> searchPatients(
|
||||
PatientManagerProvider patientManagerProvider,
|
||||
String search,
|
||||
) async {
|
||||
final response = await http
|
||||
.get(Uri.parse("${AppEnviroment.baseApiUrl}/patients/search/$search"));
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<Patient> patients =
|
||||
List<Patient>.from(l.map((model) => Patient.fromJson(model)));
|
||||
patientManagerProvider.setPatientSearchResults(
|
||||
patientSearchResults: patients);
|
||||
return patients;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> addPatientService(
|
||||
String id_no,
|
||||
String fname,
|
||||
|
||||
@@ -274,12 +274,10 @@ class MIHApiCalls {
|
||||
/// Patameters: String dsearch.
|
||||
///
|
||||
/// Returns List<Patient>.
|
||||
|
||||
static Future<List<Patient>> fetchPatients(String search) async {
|
||||
final response = await http
|
||||
.get(Uri.parse("${AppEnviroment.baseApiUrl}/patients/search/$search"));
|
||||
// errorCode = response.statusCode.toString();
|
||||
// errorBody = response.body;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<Patient> patients =
|
||||
|
||||
Reference in New Issue
Block a user