forked from yaso_meth/mih-project
File frontend added to app
This commit is contained in:
43
Frontend/patient_manager/lib/components/buildFilesList.dart
Normal file
43
Frontend/patient_manager/lib/components/buildFilesList.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/objects/files.dart';
|
||||
|
||||
class BuildFilesList extends StatefulWidget {
|
||||
final List<PFile> files;
|
||||
const BuildFilesList({
|
||||
super.key,
|
||||
required this.files,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BuildFilesList> createState() => _BuildFilesListState();
|
||||
}
|
||||
|
||||
int indexOn = 0;
|
||||
|
||||
class _BuildFilesListState extends State<BuildFilesList> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 290.0,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return const Divider();
|
||||
},
|
||||
itemCount: widget.files.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
widget.files[index].file_name,
|
||||
),
|
||||
subtitle: Text(widget.files[index].insert_date),
|
||||
trailing: const Icon(Icons.arrow_forward),
|
||||
onTap: () {
|
||||
//Insert Display function here
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -30,15 +30,22 @@ class _BuildNotesListState extends State<BuildNotesList> {
|
||||
title: Text(
|
||||
widget.notes[index].note_name,
|
||||
),
|
||||
subtitle: Text(widget.notes[index].note_text),
|
||||
subtitle: Text(
|
||||
"${widget.notes[index].insert_date}:\n${widget.notes[index].note_text}"), //Text(widget.notes[index].note_text),
|
||||
trailing: const Icon(Icons.arrow_forward),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(widget.notes[index].note_name),
|
||||
content: Text(
|
||||
"${widget.notes[index].insert_date}:\n${widget.notes[index].note_text}"),
|
||||
title: Center(child: Text(widget.notes[index].note_name)),
|
||||
content: SizedBox(
|
||||
width: 700,
|
||||
height: 250,
|
||||
child: Text(
|
||||
"${widget.notes[index].insert_date}:\n${widget.notes[index].note_text}",
|
||||
style: TextStyle(fontSize: 16),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
|
||||
67
Frontend/patient_manager/lib/components/myDateInput.dart
Normal file
67
Frontend/patient_manager/lib/components/myDateInput.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyDateField extends StatefulWidget {
|
||||
final controller;
|
||||
final String LableText;
|
||||
//final bool editable;
|
||||
|
||||
const MyDateField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.LableText,
|
||||
//required this.editable,
|
||||
});
|
||||
|
||||
@override
|
||||
State<MyDateField> createState() => _MyDateFieldState();
|
||||
}
|
||||
|
||||
class _MyDateFieldState extends State<MyDateField> {
|
||||
// bool makeEditable() {
|
||||
Future<void> _selectDate(BuildContext context) async {
|
||||
DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2100),
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
setState(() {
|
||||
widget.controller.text = picked.toString().split(" ")[0];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 25.0),
|
||||
child: TextField(
|
||||
controller: widget.controller,
|
||||
readOnly: true,
|
||||
obscureText: false,
|
||||
decoration: InputDecoration(
|
||||
labelText: widget.LableText,
|
||||
prefixIcon: const Icon(Icons.calendar_today),
|
||||
fillColor: Colors.white,
|
||||
filled: true,
|
||||
//hintText: hintText,
|
||||
hintStyle: TextStyle(color: Colors.blueGrey[400]),
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.blueAccent,
|
||||
width: 2.0,
|
||||
),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
_selectDate(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
205
Frontend/patient_manager/lib/components/patientFiles.dart
Normal file
205
Frontend/patient_manager/lib/components/patientFiles.dart
Normal file
@@ -0,0 +1,205 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/buildFilesList.dart';
|
||||
import 'package:patient_manager/components/myDateInput.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');
|
||||
}
|
||||
}
|
||||
|
||||
class PatientFiles extends StatefulWidget {
|
||||
final int patientIndex;
|
||||
const PatientFiles({super.key, required this.patientIndex});
|
||||
|
||||
@override
|
||||
State<PatientFiles> createState() => _PatientFilesState();
|
||||
}
|
||||
|
||||
class _PatientFilesState extends State<PatientFiles> {
|
||||
String endpoint = "http://localhost:80/files/patients/";
|
||||
String apiUrlAddNote = "http://localhost:80/notes/insert/";
|
||||
final startDateController = TextEditingController();
|
||||
final endDateTextController = TextEditingController();
|
||||
late Future<List<PFile>> futueFiles;
|
||||
|
||||
Future<void> addPatientNoteAPICall() async {
|
||||
var response = await http.post(
|
||||
Uri.parse(apiUrlAddNote),
|
||||
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,
|
||||
}),
|
||||
);
|
||||
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);
|
||||
} else {
|
||||
messagePopUp("error");
|
||||
}
|
||||
}
|
||||
|
||||
void messagePopUp(error) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(error),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
futueFiles = fetchNotes(endpoint + widget.patientIndex.toString());
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder(
|
||||
future: futueFiles,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (snapshot.hasData) {
|
||||
final filesList = snapshot.data!;
|
||||
return Flexible(
|
||||
flex: 1,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Card(
|
||||
elevation: 20.0,
|
||||
child: Container(
|
||||
//height: 300.0,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color.fromARGB(255, 219, 218, 218),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 5.0),
|
||||
child: Column(children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
"Files",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
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",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
//addPatientNoteAPICall();
|
||||
Navigator.pop(context);
|
||||
//print(widget.patientIndex);
|
||||
},
|
||||
child: const Text(
|
||||
"Generate",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Cancel"),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.sick_outlined),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.medication_outlined),
|
||||
)
|
||||
],
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
||||
child: Divider(),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BuildFilesList(files: filesList),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: Text("Error Loading Files"),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +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");
|
||||
return notes;
|
||||
} else {
|
||||
throw Exception('failed to load patients');
|
||||
|
||||
25
Frontend/patient_manager/lib/objects/files.dart
Normal file
25
Frontend/patient_manager/lib/objects/files.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
class PFile {
|
||||
final int idpatient_files;
|
||||
final String file_path;
|
||||
final String file_name;
|
||||
final int patient_id;
|
||||
final String insert_date;
|
||||
|
||||
const PFile(
|
||||
this.idpatient_files,
|
||||
this.file_path,
|
||||
this.file_name,
|
||||
this.patient_id,
|
||||
this.insert_date,
|
||||
);
|
||||
|
||||
factory PFile.fromJson(dynamic json) {
|
||||
return PFile(
|
||||
json['idpatient_files'],
|
||||
json['file_path'],
|
||||
json['file_name'],
|
||||
json['patient_id'],
|
||||
json['insert_date'],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:patient_manager/components/patientDetails.dart';
|
||||
import 'package:patient_manager/components/myAppBar.dart';
|
||||
import 'package:patient_manager/components/patientFiles.dart';
|
||||
import 'package:patient_manager/components/patientNotes.dart';
|
||||
import 'package:patient_manager/objects/patients.dart';
|
||||
|
||||
@@ -31,7 +32,7 @@ class _PatientViewState extends State<PatientView> {
|
||||
PatientNotes(
|
||||
patientIndex: widget.selectedPatient.idpatients,
|
||||
),
|
||||
PatientNotes(
|
||||
PatientFiles(
|
||||
patientIndex: widget.selectedPatient.idpatients,
|
||||
)
|
||||
],
|
||||
|
||||
@@ -30,7 +30,7 @@ class _SignInState extends State<SignIn> {
|
||||
}
|
||||
} on AuthException catch (error) {
|
||||
loginError(error.message);
|
||||
emailController.clear();
|
||||
//emailController.clear();
|
||||
passwordController.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define the port
|
||||
PORT=9000
|
||||
PORT=8080
|
||||
|
||||
# Check if the port is in use and release it if necessary.
|
||||
echo "Checking if port $PORT is in use..."
|
||||
|
||||
Reference in New Issue
Block a user