forked from yaso_meth/mih-project
update Patient Profile nav pt1
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import 'dart:convert';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/patients.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/patient_profile/pat_profile/patient_add.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_packages/patient_profile/pat_profile/patient_profile.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_patient_services.dart';
|
||||
|
||||
class AddOrViewPatient extends StatefulWidget {
|
||||
//final AppUser signedInUser;
|
||||
@@ -28,39 +26,15 @@ class _AddOrViewPatientState extends State<AddOrViewPatient> {
|
||||
late Widget loading;
|
||||
late Future<Patient?> patient;
|
||||
|
||||
Future<Patient?> fetchPatient() async {
|
||||
//print("Patien manager page: $endpoint");
|
||||
final response = await http.get(Uri.parse(
|
||||
"${AppEnviroment.baseApiUrl}/patients/${widget.arguments.signedInUser.app_id}"));
|
||||
// print("Here");
|
||||
// print("Body: ${response.body}");
|
||||
// print("Code: ${response.statusCode}");
|
||||
// var errorCode = response.statusCode.toString();
|
||||
// var errorBody = response.body;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// print("Here1");
|
||||
var decodedData = jsonDecode(response.body);
|
||||
// print("Here2");
|
||||
Patient patients = Patient.fromJson(decodedData as Map<String, dynamic>);
|
||||
// print("Here3");
|
||||
// print(patients);
|
||||
return patients;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
Future<Patient?> fetchPatientData() async {
|
||||
return await MihPatientServices()
|
||||
.getPatientDetails(widget.arguments.signedInUser.app_id);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
patient = fetchPatient();
|
||||
patient = fetchPatientData();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tile.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
|
||||
@@ -24,10 +25,14 @@ class _PatientProfileTileState extends State<PatientProfileTile> {
|
||||
Widget build(BuildContext context) {
|
||||
return MihPackageTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
'/patient-profile',
|
||||
arguments: widget.arguments,
|
||||
context.goNamed(
|
||||
'patientProfile',
|
||||
extra: widget.arguments,
|
||||
);
|
||||
// Navigator.of(context).pushNamed(
|
||||
// '/patient-profile',
|
||||
// arguments: widget.arguments,
|
||||
// );
|
||||
},
|
||||
appName: "Patient Profile",
|
||||
appIcon: Icon(
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/main.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_alert.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_colors.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_alert_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_patient_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_services/mih_validation_services.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_action.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_body.dart';
|
||||
@@ -13,13 +14,11 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_toggle.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_success_message.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.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:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class AddPatient extends StatefulWidget {
|
||||
final AppUser signedInUser;
|
||||
@@ -89,40 +88,95 @@ class _AddPatientState extends State<AddPatient> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addPatientAPICall() async {
|
||||
var response = await http.post(
|
||||
Uri.parse("$baseAPI/patients/insert/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"id_no": idController.text,
|
||||
"first_name": fnameController.text,
|
||||
"last_name": lnameController.text,
|
||||
"email": emailController.text,
|
||||
"cell_no": cellController.text,
|
||||
"medical_aid": medAidController.text,
|
||||
"medical_aid_main_member": medMainMemController.text,
|
||||
"medical_aid_no": medNoController.text,
|
||||
"medical_aid_code": medAidCodeController.text,
|
||||
"medical_aid_name": medNameController.text,
|
||||
"medical_aid_scheme": medSchemeController.text,
|
||||
"address": addressController.text,
|
||||
"app_id": widget.signedInUser.app_id,
|
||||
}),
|
||||
Future<void> addPatientService() async {
|
||||
int statusCode = await MihPatientServices().addPatientService(
|
||||
idController.text,
|
||||
fnameController.text,
|
||||
lnameController.text,
|
||||
emailController.text,
|
||||
cellController.text,
|
||||
medAidController.text,
|
||||
medMainMemController.text,
|
||||
medNoController.text,
|
||||
medAidCodeController.text,
|
||||
medNameController.text,
|
||||
medSchemeController.text,
|
||||
addressController.text,
|
||||
widget.signedInUser,
|
||||
);
|
||||
if (response.statusCode == 201) {
|
||||
Navigator.of(context).popAndPushNamed('/patient-profile',
|
||||
arguments: PatientViewArguments(
|
||||
widget.signedInUser, null, null, null, "personal"));
|
||||
if (statusCode == 201) {
|
||||
String message =
|
||||
"${fnameController.text} ${lnameController.text} patient profile has been successfully added!\n";
|
||||
successPopUp(message);
|
||||
successPopUp("Successfully created Patient Profile", message);
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
}
|
||||
|
||||
void successPopUp(String title, String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MihPackageAlert(
|
||||
alertIcon: Icon(
|
||||
Icons.check_circle_outline_rounded,
|
||||
size: 150,
|
||||
color: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
),
|
||||
alertTitle: title,
|
||||
alertBody: Column(
|
||||
children: [
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
color: MihColors.getSecondaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
Center(
|
||||
child: MihButton(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
context.goNamed(
|
||||
'patientProfile',
|
||||
extra: PatientViewArguments(
|
||||
widget.signedInUser,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"personal",
|
||||
),
|
||||
);
|
||||
},
|
||||
buttonColor: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
elevation: 10,
|
||||
width: 300,
|
||||
child: Text(
|
||||
"Dismiss",
|
||||
style: TextStyle(
|
||||
color: MihColors.getPrimaryColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode ==
|
||||
"Dark"),
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
alertColour: MihColors.getGreenColor(
|
||||
MzansiInnovationHub.of(context)!.theme.mode == "Dark"),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void internetConnectionPopUp() {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -143,18 +197,6 @@ class _AddPatientState extends State<AddPatient> {
|
||||
);
|
||||
}
|
||||
|
||||
void successPopUp(String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MIHSuccessMessage(
|
||||
successType: "Success",
|
||||
successMessage: message,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void isRequired() {
|
||||
//print("listerner triggered");
|
||||
if (medAidController.text == "Yes") {
|
||||
@@ -217,6 +259,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
controller: fnameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "First Name",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
@@ -231,6 +274,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
controller: lnameController,
|
||||
multiLineInput: false,
|
||||
requiredText: true,
|
||||
readOnly: true,
|
||||
hintText: "Surname",
|
||||
validator: (value) {
|
||||
return MihValidationServices().isEmpty(value);
|
||||
@@ -471,7 +515,7 @@ class _AddPatientState extends State<AddPatient> {
|
||||
}
|
||||
|
||||
void submitForm() {
|
||||
addPatientAPICall();
|
||||
addPatientService();
|
||||
}
|
||||
|
||||
MIHAction getActionButton() {
|
||||
@@ -479,7 +523,14 @@ class _AddPatientState extends State<AddPatient> {
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
iconSize: 35,
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
context.goNamed(
|
||||
'mihHome',
|
||||
extra: AuthArguments(
|
||||
true,
|
||||
false,
|
||||
),
|
||||
);
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.dart';
|
||||
@@ -42,7 +43,13 @@ class _PatientProfileState extends State<PatientProfile> {
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
iconSize: 35,
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
context.goNamed(
|
||||
'mihHome',
|
||||
extra: AuthArguments(
|
||||
true,
|
||||
false,
|
||||
),
|
||||
);
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/patients.dart';
|
||||
import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
@@ -11,7 +12,7 @@ class MihPatientServices {
|
||||
String appId,
|
||||
) async {
|
||||
var response = await http.get(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/patient/app_id/$appId"),
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/patients/$appId"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
@@ -24,4 +25,43 @@ class MihPatientServices {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> addPatientService(
|
||||
String id_no,
|
||||
String fname,
|
||||
String lname,
|
||||
String email,
|
||||
String cell,
|
||||
String medAid,
|
||||
String medMainMem,
|
||||
String medNo,
|
||||
String medAidCode,
|
||||
String medName,
|
||||
String medScheme,
|
||||
String address,
|
||||
AppUser signedInUser,
|
||||
) async {
|
||||
var response = await http.post(
|
||||
Uri.parse("$baseAPI/patients/insert/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"id_no": id_no,
|
||||
"first_name": fname,
|
||||
"last_name": lname,
|
||||
"email": email,
|
||||
"cell_no": cell,
|
||||
"medical_aid": medAid,
|
||||
"medical_aid_main_member": medMainMem,
|
||||
"medical_aid_no": medNo,
|
||||
"medical_aid_code": medAidCode,
|
||||
"medical_aid_name": medName,
|
||||
"medical_aid_scheme": medScheme,
|
||||
"address": address,
|
||||
"app_id": signedInUser.app_id,
|
||||
}),
|
||||
);
|
||||
return response.statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user