takes in signedin user and get patient based on signed in user

This commit is contained in:
2024-07-26 13:41:58 +02:00
parent 3f557ec1ac
commit 271e279baf

View File

@@ -1,29 +1,69 @@
import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:patient_manager/components/patientDetails.dart'; import 'package:patient_manager/components/patientDetails.dart';
import 'package:patient_manager/components/myAppBar.dart'; import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/patientFiles.dart'; import 'package:patient_manager/components/patientFiles.dart';
import 'package:patient_manager/components/patientNotes.dart'; import 'package:patient_manager/components/patientNotes.dart';
import 'package:patient_manager/env/env.dart';
import 'package:patient_manager/objects/appUser.dart';
import 'package:patient_manager/objects/patients.dart'; import 'package:patient_manager/objects/patients.dart';
import 'package:supertokens_flutter/http.dart' as http;
class PatientView extends StatefulWidget { class PatientView extends StatefulWidget {
final Patient selectedPatient; final AppUser signedInUser;
const PatientView({super.key, required this.selectedPatient}); const PatientView({
super.key,
required this.signedInUser,
});
@override @override
State<PatientView> createState() => _PatientViewState(); State<PatientView> createState() => _PatientViewState();
} }
class _PatientViewState extends State<PatientView> { 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}"));
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder(
future: fetchPatient(),
builder: (ctx, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
// Checking if future is resolved
else if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
return Scaffold( return Scaffold(
appBar: const MyAppBar(barTitle: "Patient View"), appBar: const MyAppBar(barTitle: "Patient View"),
body: SingleChildScrollView( body: SingleChildScrollView(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), padding: const EdgeInsets.symmetric(
vertical: 10.0, horizontal: 15.0),
child: Column( child: Column(
children: [ children: [
PatientDetails(selectedPatient: widget.selectedPatient), PatientDetails(selectedPatient: snapshot.data!),
const SizedBox( const SizedBox(
height: 10.0, height: 10.0,
), ),
@@ -36,14 +76,14 @@ class _PatientViewState extends State<PatientView> {
SizedBox( SizedBox(
width: 650, width: 650,
child: PatientNotes( child: PatientNotes(
patientIndex: widget.selectedPatient.idpatients, patientIndex: snapshot.data!.idpatients,
), ),
), ),
SizedBox( SizedBox(
width: 650, width: 650,
child: PatientFiles( child: PatientFiles(
patientIndex: widget.selectedPatient.idpatients, patientIndex: snapshot.data!.idpatients,
selectedPatient: widget.selectedPatient, selectedPatient: snapshot.data!,
), ),
) )
], ],
@@ -55,3 +95,13 @@ class _PatientViewState extends State<PatientView> {
); );
} }
} }
return Center(
child: Text(
'${snapshot.error} occurred',
style: TextStyle(fontSize: 18),
),
);
},
);
}
}