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,57 +1,107 @@
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 Scaffold( return FutureBuilder(
appBar: const MyAppBar(barTitle: "Patient View"), future: fetchPatient(),
body: SingleChildScrollView( builder: (ctx, snapshot) {
child: Padding( if (snapshot.connectionState == ConnectionState.waiting) {
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 15.0), return const Center(child: CircularProgressIndicator());
child: Column( }
children: [ // Checking if future is resolved
PatientDetails(selectedPatient: widget.selectedPatient), else if (snapshot.connectionState == ConnectionState.done) {
const SizedBox( if (snapshot.hasData) {
height: 10.0, return Scaffold(
), appBar: const MyAppBar(barTitle: "Patient View"),
Wrap( body: SingleChildScrollView(
spacing: 10.0, child: Padding(
runSpacing: 10.0, padding: const EdgeInsets.symmetric(
direction: Axis.horizontal, vertical: 10.0, horizontal: 15.0),
alignment: WrapAlignment.center, child: Column(
children: [ children: [
SizedBox( PatientDetails(selectedPatient: snapshot.data!),
width: 650, const SizedBox(
child: PatientNotes( height: 10.0,
patientIndex: widget.selectedPatient.idpatients, ),
), Wrap(
spacing: 10.0,
runSpacing: 10.0,
direction: Axis.horizontal,
alignment: WrapAlignment.center,
children: [
SizedBox(
width: 650,
child: PatientNotes(
patientIndex: snapshot.data!.idpatients,
),
),
SizedBox(
width: 650,
child: PatientFiles(
patientIndex: snapshot.data!.idpatients,
selectedPatient: snapshot.data!,
),
)
],
)
],
), ),
SizedBox( ),
width: 650, ),
child: PatientFiles( );
patientIndex: widget.selectedPatient.idpatients, }
selectedPatient: widget.selectedPatient, }
), return Center(
) child: Text(
], '${snapshot.error} occurred',
) style: TextStyle(fontSize: 18),
],
), ),
), );
), },
); );
} }
} }