forked from yaso_meth/mih-project
Update AppUser Objecct to cater for all fields.
enable file generation of med cert
This commit is contained in:
54
Frontend/patient_manager/lib/components/medCertInput.dart
Normal file
54
Frontend/patient_manager/lib/components/medCertInput.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/myDateInput.dart';
|
||||
|
||||
class Medcertinput extends StatefulWidget {
|
||||
final startDateController;
|
||||
final endDateTextController;
|
||||
final retDateTextController;
|
||||
const Medcertinput({
|
||||
super.key,
|
||||
required this.startDateController,
|
||||
required this.endDateTextController,
|
||||
required this.retDateTextController,
|
||||
});
|
||||
|
||||
@override
|
||||
State<Medcertinput> createState() => _MedcertinputState();
|
||||
}
|
||||
|
||||
class _MedcertinputState extends State<Medcertinput> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 250,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 50.0),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyDateField(
|
||||
controller: widget.startDateController,
|
||||
LableText: "From",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25.0),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyDateField(
|
||||
controller: widget.endDateTextController,
|
||||
LableText: "Up to Including",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25.0),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyDateField(
|
||||
controller: widget.retDateTextController,
|
||||
LableText: "Return",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,62 +3,122 @@ import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/buildFilesList.dart';
|
||||
import 'package:patient_manager/components/medCertInput.dart';
|
||||
import 'package:patient_manager/components/myDateInput.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/AppUser.dart';
|
||||
import 'package:patient_manager/objects/Patient2.dart';
|
||||
import 'package:patient_manager/objects/files.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
Future<List<PFile>> fetchNotes(String endpoint) async {
|
||||
final response = await http.get(Uri.parse(endpoint));
|
||||
print(response.statusCode);
|
||||
//print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<PFile> files =
|
||||
List<PFile>.from(l.map((model) => PFile.fromJson(model)));
|
||||
return files;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
import '../objects/patients.dart';
|
||||
|
||||
class PatientFiles extends StatefulWidget {
|
||||
final int patientIndex;
|
||||
const PatientFiles({super.key, required this.patientIndex});
|
||||
final Patient selectedPatient;
|
||||
const PatientFiles({
|
||||
super.key,
|
||||
required this.patientIndex,
|
||||
required this.selectedPatient,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PatientFiles> createState() => _PatientFilesState();
|
||||
}
|
||||
|
||||
class _PatientFilesState extends State<PatientFiles> {
|
||||
String endpoint = "http://localhost:80/files/patients/";
|
||||
String apiUrlAddNote = "http://localhost:80/notes/insert/";
|
||||
String endpointFiles = "http://localhost:80/files/patients/";
|
||||
String endpointUser = "http://localhost:80/docOffices/user/";
|
||||
String endpointGenFiles = "http://localhost:80/files/generate/";
|
||||
String endpointInsertFiles = "http://localhost:80/files/insert/";
|
||||
|
||||
final startDateController = TextEditingController();
|
||||
final endDateTextController = TextEditingController();
|
||||
final retDateTextController = TextEditingController();
|
||||
late Future<List<PFile>> futueFiles;
|
||||
late String userEmail = "";
|
||||
late AppUser appUser;
|
||||
|
||||
Future<void> addPatientNoteAPICall() async {
|
||||
var response = await http.post(
|
||||
Uri.parse(apiUrlAddNote),
|
||||
Future<void> generateMedCert() async {
|
||||
var response1 = await http.post(
|
||||
Uri.parse(endpointGenFiles),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"note_name": startDateController.text,
|
||||
"note_text": endDateTextController.text,
|
||||
"patient_id": widget.patientIndex,
|
||||
"fullName":
|
||||
"${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}",
|
||||
"docfname": "${appUser.title} ${appUser.fname} ${appUser.lname}",
|
||||
"startDate": startDateController.text,
|
||||
"endDate": endDateTextController.text,
|
||||
"returnDate": retDateTextController.text,
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 201) {
|
||||
setState(() {
|
||||
futueFiles = fetchNotes(endpoint + widget.patientIndex.toString());
|
||||
});
|
||||
// Navigator.of(context)
|
||||
// .pushNamed('/patient-manager', arguments: widget.userEmail);
|
||||
String message = "Successfully added Files";
|
||||
messagePopUp(message);
|
||||
print(response1.statusCode);
|
||||
String fileName =
|
||||
"Med-Cert-${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}-${startDateController.text}";
|
||||
if (response1.statusCode == 200) {
|
||||
var response2 = await http.post(
|
||||
Uri.parse(endpointInsertFiles),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"file_path": fileName,
|
||||
"file_name": fileName,
|
||||
"patient_id": widget.patientIndex
|
||||
}),
|
||||
);
|
||||
print(response2.statusCode);
|
||||
if (response2.statusCode == 201) {
|
||||
setState(() {
|
||||
futueFiles =
|
||||
fetchFiles(endpointFiles + widget.patientIndex.toString());
|
||||
});
|
||||
String message = "Successfully added file";
|
||||
messagePopUp(message);
|
||||
} else {
|
||||
messagePopUp("error response 2");
|
||||
}
|
||||
} else {
|
||||
messagePopUp("error");
|
||||
messagePopUp("error respose 1");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUserDetails() async {
|
||||
await getUserEmail();
|
||||
var response = await http.get(Uri.parse(endpointUser + userEmail));
|
||||
//print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
appUser =
|
||||
AppUser.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
|
||||
} else {
|
||||
throw Exception('Failed to load user');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getUserEmail() async {
|
||||
final res = await client.auth.getUser();
|
||||
if (res.user!.email != null) {
|
||||
//print("emai not null");
|
||||
userEmail = res.user!.email!;
|
||||
//print(userEmail);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PFile>> fetchFiles(String endpoint) async {
|
||||
final response = await http.get(Uri.parse(endpoint));
|
||||
|
||||
//print(response.statusCode);
|
||||
//print(response.body);
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<PFile> files =
|
||||
List<PFile>.from(l.map((model) => PFile.fromJson(model)));
|
||||
return files;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +135,9 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
futueFiles = fetchNotes(endpoint + widget.patientIndex.toString());
|
||||
|
||||
futueFiles = fetchFiles(endpointFiles + widget.patientIndex.toString());
|
||||
//patientDetails = getPatientDetails() as Patient;
|
||||
getUserDetails();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -128,33 +189,18 @@ class _PatientFilesState extends State<PatientFiles> {
|
||||
Text("Create Medical Certificate"),
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
height: 250,
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 50.0),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyDateField(
|
||||
controller: startDateController,
|
||||
LableText: "From",
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 25.0),
|
||||
SizedBox(
|
||||
width: 700,
|
||||
child: MyDateField(
|
||||
controller: endDateTextController,
|
||||
LableText: "Up to Including",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
content: Medcertinput(
|
||||
startDateController: startDateController,
|
||||
endDateTextController:
|
||||
endDateTextController,
|
||||
retDateTextController:
|
||||
retDateTextController,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
//addPatientNoteAPICall();
|
||||
//getPatientDetails();
|
||||
generateMedCert();
|
||||
Navigator.pop(context);
|
||||
//print(widget.patientIndex);
|
||||
},
|
||||
|
||||
@@ -12,7 +12,7 @@ Future<List<Note>> fetchNotes(String endpoint) async {
|
||||
if (response.statusCode == 200) {
|
||||
Iterable l = jsonDecode(response.body);
|
||||
List<Note> notes = List<Note>.from(l.map((model) => Note.fromJson(model)));
|
||||
print("Here notes");
|
||||
//print("Here notes");
|
||||
return notes;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
|
||||
@@ -1,15 +1,39 @@
|
||||
class AppUser {
|
||||
final int idusers;
|
||||
final String email;
|
||||
final int idUser;
|
||||
final String UserName;
|
||||
final int docOffice_id;
|
||||
final String fname;
|
||||
final String lname;
|
||||
final String title;
|
||||
|
||||
const AppUser(
|
||||
this.idusers,
|
||||
this.email,
|
||||
this.docOffice_id,
|
||||
);
|
||||
const AppUser({
|
||||
required this.idUser,
|
||||
required this.UserName,
|
||||
required this.docOffice_id,
|
||||
required this.fname,
|
||||
required this.lname,
|
||||
required this.title,
|
||||
});
|
||||
|
||||
factory AppUser.fromJson(dynamic json) {
|
||||
return AppUser(json['idusers'], json['email'], json['docOffice_id']);
|
||||
factory AppUser.fromJson(Map<String, dynamic> json) {
|
||||
return switch (json) {
|
||||
{
|
||||
'idUser': int idUser,
|
||||
'UserName': String UserName,
|
||||
'docOffice_id': int docOffice_id,
|
||||
'fname': String fname,
|
||||
'lname': String lname,
|
||||
'title': String title,
|
||||
} =>
|
||||
AppUser(
|
||||
idUser: idUser,
|
||||
UserName: UserName,
|
||||
docOffice_id: docOffice_id,
|
||||
fname: fname,
|
||||
lname: lname,
|
||||
title: title,
|
||||
),
|
||||
_ => throw const FormatException('Failed to load album.'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
47
Frontend/patient_manager/lib/objects/Patient2.dart
Normal file
47
Frontend/patient_manager/lib/objects/Patient2.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
class Patient2 {
|
||||
final int idpatients;
|
||||
final String id_no;
|
||||
final String first_name;
|
||||
final String last_name;
|
||||
final String email;
|
||||
final String cell_no;
|
||||
final String medical_aid_name;
|
||||
final String medical_aid_no;
|
||||
final String medical_aid_scheme;
|
||||
final String address;
|
||||
final int doc_office_id;
|
||||
|
||||
const Patient2(
|
||||
this.idpatients,
|
||||
this.id_no,
|
||||
this.first_name,
|
||||
this.last_name,
|
||||
this.email,
|
||||
this.cell_no,
|
||||
this.medical_aid_name,
|
||||
this.medical_aid_no,
|
||||
this.medical_aid_scheme,
|
||||
this.address,
|
||||
this.doc_office_id,
|
||||
);
|
||||
|
||||
factory Patient2.fromJson(dynamic json) {
|
||||
return Patient2(
|
||||
json['idpatients'],
|
||||
json['id_no'],
|
||||
json['first_name'],
|
||||
json['last_name'],
|
||||
json['email'],
|
||||
json['cell_no'],
|
||||
json['medical_aid_name'],
|
||||
json['medical_aid_no'],
|
||||
json['medical_aid_scheme'],
|
||||
json['address'],
|
||||
json['docOffice_id'],
|
||||
);
|
||||
}
|
||||
|
||||
String getIDNum() {
|
||||
return id_no;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ class _PatientViewState extends State<PatientView> {
|
||||
),
|
||||
PatientFiles(
|
||||
patientIndex: widget.selectedPatient.idpatients,
|
||||
selectedPatient: widget.selectedPatient,
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user