1) buildmedlist - update data to add unit and form when clicking a medicine

This commit is contained in:
2024-07-05 17:44:27 +02:00
parent 65640133a8
commit e75137afb5
3 changed files with 222 additions and 137 deletions

View File

@@ -17,9 +17,9 @@ class BuildMedicinesList extends StatefulWidget {
State<BuildMedicinesList> createState() => _BuildMedicinesListState();
}
int indexOn = 0;
class _BuildMedicinesListState extends State<BuildMedicinesList> {
int indexOn = 0;
@override
Widget build(BuildContext context) {
return ListView.separated(
@@ -35,7 +35,8 @@ class _BuildMedicinesListState extends State<BuildMedicinesList> {
"${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();
});
},

View File

@@ -84,18 +84,6 @@ class _MedicineSearchState extends State<MedicineSearch> {
),
),
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<MedicineSearch> {
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<MedicineSearch> {
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,
),
),
);
}

View File

@@ -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<PrescripInput> {
String searchString = "";
//String perscriptionOutput = "";
List<List<String>> perscriptionOutput = [];
final numberOptions = [
"0",
@@ -77,6 +78,213 @@ class _PrescripInputState extends State<PrescripInput> {
);
}
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<String> medNameList = widget.medicineController.text.split("%t");
List<String> 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<PrescripInput> {
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(),
],
),
);