change to have personal notes view

This commit is contained in:
2024-07-29 11:07:22 +02:00
parent 38c3b097fb
commit 0fbede68b1
3 changed files with 54 additions and 34 deletions

View File

@@ -9,12 +9,15 @@ import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart';
import 'package:patient_manager/env/env.dart';
import 'package:patient_manager/main.dart';
import 'package:patient_manager/objects/appUser.dart';
import 'package:patient_manager/objects/notes.dart';
import 'package:supertokens_flutter/http.dart' as http;
class PatientNotes extends StatefulWidget {
final int patientIndex;
const PatientNotes({super.key, required this.patientIndex});
final String patientAppId;
final AppUser signedInUser;
const PatientNotes(
{super.key, required this.patientAppId, required this.signedInUser});
@override
State<PatientNotes> createState() => _PatientNotesState();
@@ -28,7 +31,8 @@ class _PatientNotesState extends State<PatientNotes> {
late Future<List<Note>> futueNotes;
Future<List<Note>> fetchNotes(String endpoint) async {
final response = await http.get(Uri.parse(endpoint));
final response = await http.get(Uri.parse(
"${AppEnviroment.baseApiUrl}/notes/patients/${widget.patientAppId}"));
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<Note> notes =
@@ -50,12 +54,12 @@ class _PatientNotesState extends State<PatientNotes> {
body: jsonEncode(<String, dynamic>{
"note_name": titleController.text,
"note_text": noteTextController.text,
"patient_id": widget.patientIndex,
"patient_id": widget.patientAppId,
}),
);
if (response.statusCode == 201) {
setState(() {
futueNotes = fetchNotes(endpoint + widget.patientIndex.toString());
futueNotes = fetchNotes(endpoint + widget.patientAppId.toString());
});
// Navigator.of(context)
// .pushNamed('/patient-manager', arguments: widget.userEmail);
@@ -212,9 +216,42 @@ class _PatientNotesState extends State<PatientNotes> {
}
}
List<Widget> setIcons() {
if (widget.signedInUser.type == "personal") {
return [
Text(
"Notes",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
),
];
} else {
return [
Text(
"Notes",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
),
IconButton(
onPressed: () {
addNotePopUp();
},
icon: Icon(Icons.add,
color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
)
];
}
}
@override
void initState() {
futueNotes = fetchNotes(endpoint + widget.patientIndex.toString());
futueNotes = fetchNotes(endpoint + widget.patientAppId);
super.initState();
}
@@ -244,27 +281,7 @@ class _PatientNotesState extends State<PatientNotes> {
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Notes",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor()),
),
IconButton(
onPressed: () {
addNotePopUp();
},
icon: Icon(Icons.add,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor()),
)
],
children: setIcons(),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),

View File

@@ -2,14 +2,14 @@ class Note {
final int idpatient_notes;
final String note_name;
final String note_text;
final int patient_id;
final String insert_date;
final String app_id;
const Note({
required this.idpatient_notes,
required this.note_name,
required this.note_text,
required this.patient_id,
required this.app_id,
required this.insert_date,
});
@@ -19,15 +19,15 @@ class Note {
"idpatient_notes": int idpatient_notes,
"note_name": String note_name,
"note_text": String note_text,
"patient_id": int patient_id,
"insert_date": String insert_date,
"app_id": String app_id,
} =>
Note(
idpatient_notes: idpatient_notes,
note_name: note_name,
note_text: note_text,
patient_id: patient_id,
insert_date: insert_date,
app_id: app_id,
),
_ => throw const FormatException('Failed to load album.'),
};

View File

@@ -26,8 +26,10 @@ class PatientView extends StatefulWidget {
class _PatientViewState extends State<PatientView> {
Future<Patient?> fetchPatient() async {
//print("Patien manager page: $endpoint");
final response = await http.get(Uri.parse(
"${AppEnviroment.baseApiUrl}/patients/${widget.signedInUser.app_id}"));
var patientAppId = widget.signedInUser.app_id;
final response = await http
.get(Uri.parse("${AppEnviroment.baseApiUrl}/patients/$patientAppId"));
// print("Here");
// print("Body: ${response.body}");
// print("Code: ${response.statusCode}");
@@ -91,7 +93,8 @@ class _PatientViewState extends State<PatientView> {
SizedBox(
width: 650,
child: PatientNotes(
patientIndex: snapshot.data!.idpatients,
patientAppId: snapshot.data!.app_id,
signedInUser: widget.signedInUser,
),
),
SizedBox(