From e75137afb5a67a835493332441e02387df6c99b0 Mon Sep 17 00:00:00 2001 From: yaso-meth Date: Fri, 5 Jul 2024 17:44:27 +0200 Subject: [PATCH] 1) buildmedlist - update data to add unit and form when clicking a medicine --- .../lib/components/buildMedList.dart | 7 +- .../lib/components/medicineSearch.dart | 20 +- .../lib/components/prescipInput.dart | 332 +++++++++++------- 3 files changed, 222 insertions(+), 137 deletions(-) diff --git a/Frontend/patient_manager/lib/components/buildMedList.dart b/Frontend/patient_manager/lib/components/buildMedList.dart index 0fbbe7a5..0c6151ff 100644 --- a/Frontend/patient_manager/lib/components/buildMedList.dart +++ b/Frontend/patient_manager/lib/components/buildMedList.dart @@ -17,9 +17,9 @@ class BuildMedicinesList extends StatefulWidget { State createState() => _BuildMedicinesListState(); } -int indexOn = 0; - class _BuildMedicinesListState extends State { + int indexOn = 0; + @override Widget build(BuildContext context) { return ListView.separated( @@ -35,7 +35,8 @@ class _BuildMedicinesListState extends State { "${widget.medicines[index].unit} - ${widget.medicines[index].form}"), onTap: () { setState(() { - widget.contoller.text = widget.medicines[index].name; + widget.contoller.text = + "${widget.medicines[index].name}%t${widget.medicines[index].unit}%t${widget.medicines[index].form}"; Navigator.of(context).pop(); }); }, diff --git a/Frontend/patient_manager/lib/components/medicineSearch.dart b/Frontend/patient_manager/lib/components/medicineSearch.dart index c7c01aa2..16019287 100644 --- a/Frontend/patient_manager/lib/components/medicineSearch.dart +++ b/Frontend/patient_manager/lib/components/medicineSearch.dart @@ -84,18 +84,6 @@ class _MedicineSearchState extends State { ), ), const SizedBox(height: 25.0), - // MySearchField( - // controller: searchController, - // hintText: "Medicine", - // onChanged: (value) { - // setState(() { - // searchString = value; - // }); - // }, - // required: true, - // editable: true, - // onTap: () {}, - // ), FutureBuilder( future: futueMeds, builder: (context, snapshot) { @@ -106,7 +94,7 @@ class _MedicineSearchState extends State { child: CircularProgressIndicator(), ), ); - } else if (snapshot.hasData) { + } else if (snapshot.hasData && snapshot.data!.isNotEmpty) { final medsList = snapshot.data!; return SizedBox( height: 400, @@ -120,7 +108,11 @@ class _MedicineSearchState extends State { return const SizedBox( height: 400, child: const Center( - child: Text("Error Loading Medicines"), + child: Text( + "No Match Found\nPlease close and manually capture medicine", + style: TextStyle(fontSize: 25, color: Colors.grey), + textAlign: TextAlign.center, + ), ), ); } diff --git a/Frontend/patient_manager/lib/components/prescipInput.dart b/Frontend/patient_manager/lib/components/prescipInput.dart index 7d535f12..2f05c95c 100644 --- a/Frontend/patient_manager/lib/components/prescipInput.dart +++ b/Frontend/patient_manager/lib/components/prescipInput.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:patient_manager/components/medicineSearch.dart'; import 'package:patient_manager/components/myDropdownInput.dart'; -import 'package:patient_manager/components/myMLTextInput.dart'; +import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/mySearchInput.dart'; import 'package:patient_manager/components/mybutton.dart'; @@ -30,7 +30,8 @@ class PrescripInput extends StatefulWidget { } class _PrescripInputState extends State { - String searchString = ""; + //String perscriptionOutput = ""; + List> perscriptionOutput = []; final numberOptions = [ "0", @@ -77,6 +78,213 @@ class _PrescripInputState extends State { ); } + bool isFieldsFilled() { + if (widget.medicineController.text.isEmpty || + widget.quantityController.text.isEmpty || + widget.dosageController.text.isEmpty || + widget.timesDailyController.text.isEmpty || + widget.noDaysController.text.isEmpty || + widget.noRepeatsController.text.isEmpty) { + return false; + } else { + return true; + } + } + + void updatePerscriptionList() { + List medNameList = widget.medicineController.text.split("%t"); + List temp = []; + temp.add(medNameList[0]); //Name 0 + temp.add(medNameList[1]); //Unit 1 + temp.add(medNameList[2]); //Form 2 + temp.add(widget.quantityController.text); //Quantity 3 + temp.add(widget.quantityController.text); //Dosage 4 + temp.add(widget.timesDailyController.text); //Times Daily 5 + temp.add(widget.noDaysController.text); //No Days 6 + temp.add(widget.noRepeatsController.text); //No Repeats 7 + + perscriptionOutput.add(temp); + } + + String getPerscTitle(int index) { + return "${perscriptionOutput[index][0]} (${perscriptionOutput[index][1]})"; + } + + String getPerscSubtitle(int index) { + if (perscriptionOutput[index][3].toLowerCase() == "syr") { + return "${perscriptionOutput[index][4]} ${perscriptionOutput[index][3]}, ${perscriptionOutput[index][5]} times daily, for ${perscriptionOutput[index][6]}\nQuantity: ${perscriptionOutput[index][3]}\nNo. of repeats ${perscriptionOutput[index][7]}"; + } else { + return "${perscriptionOutput[index][4]} ${perscriptionOutput[index][1]}, ${perscriptionOutput[index][5]} times daily, for ${perscriptionOutput[index][6]}\nQuantity: ${perscriptionOutput[index][3]}\nNo. of repeats ${perscriptionOutput[index][7]}"; + } + } + + Widget displayMedInput() { + return Column( + children: [ + SizedBox( + width: 300, + child: MySearchField( + controller: widget.medicineController, + hintText: "Medicine", + onChanged: (value) {}, + required: true, + editable: true, + onTap: () { + getMedsPopUp(widget.medicineController); + }, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 300, + child: MyDropdownField( + controller: widget.quantityController, + hintText: "Quantity", + dropdownOptions: numberOptions, + required: true, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 300, + child: MyDropdownField( + controller: widget.dosageController, + hintText: "Dosage", + dropdownOptions: numberOptions, + required: true, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 300, + child: MyDropdownField( + controller: widget.timesDailyController, + hintText: "Times Daily", + dropdownOptions: numberOptions, + required: true, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 300, + child: MyDropdownField( + controller: widget.noDaysController, + hintText: "No. Days", + dropdownOptions: numberOptions, + required: true, + ), + ), + const SizedBox(height: 25.0), + SizedBox( + width: 300, + child: MyDropdownField( + controller: widget.noRepeatsController, + hintText: "No. Repeats", + dropdownOptions: numberOptions, + required: true, + ), + ), + SizedBox( + width: 300, + child: MyButton( + onTap: () { + if (isFieldsFilled()) { + setState(() { + updatePerscriptionList(); + widget.medicineController.clear(); + widget.quantityController.clear(); + widget.dosageController.clear(); + widget.timesDailyController.clear(); + widget.noDaysController.clear(); + widget.noRepeatsController.clear(); + }); + + //addPatientAPICall(); + } else { + showDialog( + context: context, + builder: (context) { + return const MyErrorMessage(errorType: "Input Error"); + }, + ); + } + }, + buttonText: "Add", + buttonColor: Colors.blueAccent, + textColor: Colors.white, + ), + ) + ], + ); + } + + Widget displayPerscList() { + return Column( + children: [ + Container( + width: 550, + height: 400, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(25.0), + border: Border.all(color: Colors.blueAccent, width: 3.0), + ), + child: ListView.separated( + separatorBuilder: (BuildContext context, int index) { + return const Divider(); + }, + itemCount: perscriptionOutput.length, + itemBuilder: (context, index) { + //final patient = widget.patients[index].id_no.contains(widget.searchString); + return ListTile( + title: Text( + getPerscTitle(index), + ), + subtitle: Text( + getPerscSubtitle(index), + ), + //onTap: () {}, + trailing: IconButton( + icon: const Icon( + Icons.delete_forever_outlined, + ), + onPressed: () { + setState(() { + perscriptionOutput.removeAt(index); + }); + }, + ), + ); + }, + ), + ), + SizedBox( + width: 300, + height: 100, + child: MyButton( + onTap: () { + // if (isMedCertFieldsFilled()) { + // generateMedCert(); + // Navigator.pop(context); + // } else { + // showDialog( + // context: context, + // builder: (context) { + // return const MyErrorMessage( + // errorType: "Input Error"); + // }, + // ); + // } + }, + buttonText: "Generate", + buttonColor: Colors.green, + textColor: Colors.white, + ), + ) + ], + ); + } + @override void initState() { //futueMeds = getMedList(endpointMeds); @@ -91,124 +299,8 @@ class _PrescripInputState extends State { mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Column( - children: [ - SizedBox( - width: 300, - child: MySearchField( - controller: widget.medicineController, - hintText: "Medicine", - onChanged: (value) { - setState(() { - searchString = value; - }); - }, - required: true, - editable: true, - onTap: () { - getMedsPopUp(widget.medicineController); - }, - ), - ), - const SizedBox(height: 25.0), - SizedBox( - width: 300, - child: MyDropdownField( - controller: widget.quantityController, - hintText: "Quantity", - dropdownOptions: numberOptions, - required: true, - ), - ), - const SizedBox(height: 25.0), - SizedBox( - width: 300, - child: MyDropdownField( - controller: widget.dosageController, - hintText: "Dosage", - dropdownOptions: numberOptions, - required: true, - ), - ), - const SizedBox(height: 25.0), - SizedBox( - width: 300, - child: MyDropdownField( - controller: widget.timesDailyController, - hintText: "Times Daily", - dropdownOptions: numberOptions, - required: true, - ), - ), - const SizedBox(height: 25.0), - SizedBox( - width: 300, - child: MyDropdownField( - controller: widget.noDaysController, - hintText: "No. Days", - dropdownOptions: numberOptions, - required: true, - ), - ), - const SizedBox(height: 25.0), - SizedBox( - width: 300, - child: MyDropdownField( - controller: widget.noRepeatsController, - hintText: "No. Repeats", - dropdownOptions: numberOptions, - required: true, - ), - ), - SizedBox( - width: 300, - child: MyButton( - onTap: () {}, - buttonText: "Add", - buttonColor: Colors.blueAccent, - textColor: Colors.white, - ), - ) - ], - ), - //const SizedBox(height: 50.0), - Column( - children: [ - SizedBox( - width: 550, - height: 400, - child: MyMLTextField( - controller: widget.outputController, - hintText: "Prescrion Output", - editable: false, - required: false, - ), - ), - SizedBox( - width: 300, - height: 100, - child: MyButton( - onTap: () { - // if (isMedCertFieldsFilled()) { - // generateMedCert(); - // Navigator.pop(context); - // } else { - // showDialog( - // context: context, - // builder: (context) { - // return const MyErrorMessage( - // errorType: "Input Error"); - // }, - // ); - // } - }, - buttonText: "Generate", - buttonColor: Colors.green, - textColor: Colors.white, - ), - ) - ], - ), + displayMedInput(), + displayPerscList(), ], ), );