forked from yaso_meth/mih-project
new components
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_apis/mih_claim_statement_generation_api.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih-app_tool_body.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/claim_statement_file.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_packages/patient_profile/pat_profile/components/Claim_Statement_Window.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_packages/patient_profile/pat_profile/list_builders/build_claim_statement_files_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PatientClaimOrStatement extends StatefulWidget {
|
||||
final int patientIndex;
|
||||
final Patient selectedPatient;
|
||||
final AppUser signedInUser;
|
||||
final Business? business;
|
||||
final BusinessUser? businessUser;
|
||||
final String type;
|
||||
const PatientClaimOrStatement({
|
||||
super.key,
|
||||
required this.patientIndex,
|
||||
required this.selectedPatient,
|
||||
required this.signedInUser,
|
||||
required this.business,
|
||||
required this.businessUser,
|
||||
required this.type,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PatientClaimOrStatement> createState() =>
|
||||
_PatientClaimOrStatementState();
|
||||
}
|
||||
|
||||
class _PatientClaimOrStatementState extends State<PatientClaimOrStatement> {
|
||||
late Future<List<ClaimStatementFile>> futueFiles;
|
||||
|
||||
void claimOrStatementWindow() {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => ClaimStatementWindow(
|
||||
selectedPatient: widget.selectedPatient,
|
||||
signedInUser: widget.signedInUser,
|
||||
business: widget.business,
|
||||
businessUser: widget.businessUser,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> setIcons() {
|
||||
if (widget.type == "personal") {
|
||||
return [
|
||||
Text(
|
||||
"Claims/ Statements",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
Text(
|
||||
"Claims/ Statements",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// new window to input fields for claim/ statements
|
||||
claimOrStatementWindow();
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.add,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.business == null) {
|
||||
futueFiles =
|
||||
MIHClaimStatementGenerationApi.getClaimStatementFilesByPatient(
|
||||
widget.signedInUser.app_id);
|
||||
} else {
|
||||
futueFiles =
|
||||
MIHClaimStatementGenerationApi.getClaimStatementFilesByBusiness(
|
||||
widget.business!.business_id);
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MihAppToolBody(
|
||||
borderOn: true,
|
||||
bodyItem: getBody(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getBody() {
|
||||
return FutureBuilder(
|
||||
future: futueFiles,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: Mihloadingcircle(),
|
||||
);
|
||||
} else if (snapshot.hasData) {
|
||||
final filesList = snapshot.data!;
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: setIcons(),
|
||||
),
|
||||
Divider(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||
const SizedBox(height: 10),
|
||||
//const Placeholder(),
|
||||
BuildClaimStatementFileList(
|
||||
files: filesList,
|
||||
signedInUser: widget.signedInUser,
|
||||
selectedPatient: widget.selectedPatient,
|
||||
business: widget.business,
|
||||
businessUser: widget.businessUser,
|
||||
type: widget.type,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return const Center(
|
||||
child: Text("Error Loading Notes"),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,511 @@
|
||||
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_apis/mih_claim_statement_generation_api.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_apis/mih_icd10_code_api.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_date_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_search_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_text_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/icd10_code.dart.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_packages/patient_profile/icd10_search_window.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class ClaimStatementWindow extends StatefulWidget {
|
||||
final Patient selectedPatient;
|
||||
final AppUser signedInUser;
|
||||
final Business? business;
|
||||
final BusinessUser? businessUser;
|
||||
const ClaimStatementWindow({
|
||||
super.key,
|
||||
required this.selectedPatient,
|
||||
required this.signedInUser,
|
||||
required this.business,
|
||||
required this.businessUser,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ClaimStatementWindow> createState() => _ClaimStatementWindowState();
|
||||
}
|
||||
|
||||
class _ClaimStatementWindowState extends State<ClaimStatementWindow> {
|
||||
final TextEditingController _docTypeController = TextEditingController();
|
||||
final TextEditingController _fullNameController = TextEditingController();
|
||||
final TextEditingController _idController = TextEditingController();
|
||||
final TextEditingController _medAidController = TextEditingController();
|
||||
final TextEditingController _medAidNoController = TextEditingController();
|
||||
final TextEditingController _medAidCodeController = TextEditingController();
|
||||
final TextEditingController _medAidNameController = TextEditingController();
|
||||
final TextEditingController _medAidSchemeController = TextEditingController();
|
||||
final TextEditingController _providerNameController = TextEditingController();
|
||||
final TextEditingController _practiceNoController = TextEditingController();
|
||||
final TextEditingController _vatNoController = TextEditingController();
|
||||
final TextEditingController _serviceDateController = TextEditingController();
|
||||
final TextEditingController _serviceDescController = TextEditingController();
|
||||
final TextEditingController _serviceDescOptionsController =
|
||||
TextEditingController();
|
||||
final TextEditingController _prcedureNameController = TextEditingController();
|
||||
// final TextEditingController _procedureDateController =
|
||||
// TextEditingController();
|
||||
final TextEditingController _proceedureAdditionalInfoController =
|
||||
TextEditingController();
|
||||
final TextEditingController _icd10CodeController = TextEditingController();
|
||||
final TextEditingController _amountController = TextEditingController();
|
||||
final TextEditingController _preauthNoController = TextEditingController();
|
||||
final ValueNotifier<String> serviceDesc = ValueNotifier("");
|
||||
final ValueNotifier<String> medAid = ValueNotifier("");
|
||||
List<ICD10Code> icd10codeList = [];
|
||||
|
||||
void icd10SearchWindow(List<ICD10Code> codeList) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => ICD10SearchWindow(
|
||||
icd10CodeController: _icd10CodeController,
|
||||
icd10codeList: codeList,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getWindowBody() {
|
||||
return Column(
|
||||
children: [
|
||||
MIHDropdownField(
|
||||
controller: _docTypeController,
|
||||
hintText: "Document Type",
|
||||
dropdownOptions: const ["Claim", "Statement"],
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// Text(
|
||||
// "Patient Details",
|
||||
// textAlign: TextAlign.center,
|
||||
// style: TextStyle(
|
||||
// fontSize: 20,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// ),
|
||||
// ),
|
||||
// Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _fullNameController,
|
||||
// hintText: "Full Name",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _idController,
|
||||
// hintText: "ID No.",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _medAidController,
|
||||
// hintText: "Has Medical Aid",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ValueListenableBuilder(
|
||||
// valueListenable: serviceDesc,
|
||||
// builder: (BuildContext context, String value, Widget? child) {
|
||||
// return Visibility(
|
||||
// visible: value == "Yes",
|
||||
// child: Column(
|
||||
// children: [
|
||||
// MIHTextField(
|
||||
// controller: _medAidNoController,
|
||||
// hintText: "Medical Aid No.",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _medAidCodeController,
|
||||
// hintText: "Medical Aid Code",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _medAidNameController,
|
||||
// hintText: "Medical Aid Name",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _medAidSchemeController,
|
||||
// hintText: "Medical Aid Scheme",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// Text(
|
||||
// "Provider Details",
|
||||
// textAlign: TextAlign.center,
|
||||
// style: TextStyle(
|
||||
// fontSize: 20,
|
||||
// fontWeight: FontWeight.bold,
|
||||
// color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
// ),
|
||||
// ),
|
||||
// Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _providerNameController,
|
||||
// hintText: "Provider Name",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _practiceNoController,
|
||||
// hintText: "Practice No.",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// MIHTextField(
|
||||
// controller: _vatNoController,
|
||||
// hintText: "VAT No.",
|
||||
// editable: false,
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
Text(
|
||||
"Service Details",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||
const SizedBox(height: 10),
|
||||
MIHDateField(
|
||||
controller: _serviceDateController,
|
||||
lableText: "Date of Service",
|
||||
required: true,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MIHDropdownField(
|
||||
controller: _serviceDescController,
|
||||
hintText: "Service Decription",
|
||||
dropdownOptions: const [
|
||||
"Consultation",
|
||||
"Procedure",
|
||||
"Other",
|
||||
],
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: serviceDesc,
|
||||
builder: (BuildContext context, String value, Widget? child) {
|
||||
Widget returnWidget;
|
||||
switch (value) {
|
||||
case 'Consultation':
|
||||
returnWidget = Column(
|
||||
children: [
|
||||
MIHDropdownField(
|
||||
controller: _serviceDescOptionsController,
|
||||
hintText: "Service Decription Options",
|
||||
dropdownOptions: const [
|
||||
"General Consultation",
|
||||
"Follow-Up Consultation",
|
||||
"Specialist Consultation",
|
||||
"Emergency Consultation",
|
||||
],
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
case 'Procedure':
|
||||
returnWidget = Column(
|
||||
children: [
|
||||
MIHTextField(
|
||||
controller: _prcedureNameController,
|
||||
hintText: "Procedure Name",
|
||||
editable: true,
|
||||
required: true,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// MIHDateField(
|
||||
// controller: _procedureDateController,
|
||||
// lableText: "Procedure Date",
|
||||
// required: true,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
MIHTextField(
|
||||
controller: _proceedureAdditionalInfoController,
|
||||
hintText: "Additional Information",
|
||||
editable: true,
|
||||
required: true,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
case 'Other':
|
||||
returnWidget = Column(
|
||||
children: [
|
||||
MIHTextField(
|
||||
controller: _serviceDescOptionsController,
|
||||
hintText: "Service Decription text",
|
||||
editable: false,
|
||||
required: true,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
default:
|
||||
returnWidget = const SizedBox();
|
||||
}
|
||||
return returnWidget;
|
||||
},
|
||||
),
|
||||
//const SizedBox(height: 10),
|
||||
MIHSearchField(
|
||||
controller: _icd10CodeController,
|
||||
hintText: "ICD-10 Code & Description",
|
||||
required: true,
|
||||
editable: true,
|
||||
onTap: () {
|
||||
//api
|
||||
MIHIcd10CodeApis.getIcd10Codes(_icd10CodeController.text, context)
|
||||
.then((result) {
|
||||
icd10SearchWindow(result);
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
MIHTextField(
|
||||
controller: _amountController,
|
||||
hintText: "Amount",
|
||||
editable: true,
|
||||
required: true,
|
||||
),
|
||||
Text(
|
||||
"Additional Infomation",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||
const SizedBox(height: 10),
|
||||
MIHTextField(
|
||||
controller: _preauthNoController,
|
||||
hintText: "Pre-authorisation No.",
|
||||
editable: true,
|
||||
required: false,
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
SizedBox(
|
||||
width: 500,
|
||||
height: 50,
|
||||
child: MIHButton(
|
||||
onTap: () {
|
||||
//generate document and uploud it
|
||||
if (isInputValid()) {
|
||||
MIHClaimStatementGenerationApi().generateClaimStatement(
|
||||
ClaimStatementGenerationArguments(
|
||||
_docTypeController.text,
|
||||
widget.selectedPatient.app_id,
|
||||
_fullNameController.text,
|
||||
_idController.text,
|
||||
_medAidController.text,
|
||||
_medAidNoController.text,
|
||||
_medAidCodeController.text,
|
||||
_medAidNameController.text,
|
||||
_medAidSchemeController.text,
|
||||
widget.business!.Name,
|
||||
"*To-Be Added*",
|
||||
widget.business!.contact_no,
|
||||
widget.business!.bus_email,
|
||||
_providerNameController.text,
|
||||
_practiceNoController.text,
|
||||
_vatNoController.text,
|
||||
_serviceDateController.text,
|
||||
_serviceDescController.text,
|
||||
_serviceDescOptionsController.text,
|
||||
_prcedureNameController.text,
|
||||
_proceedureAdditionalInfoController.text,
|
||||
_icd10CodeController.text,
|
||||
_amountController.text,
|
||||
_preauthNoController.text,
|
||||
widget.business!.logo_path,
|
||||
widget.businessUser!.sig_path,
|
||||
),
|
||||
PatientViewArguments(
|
||||
widget.signedInUser,
|
||||
widget.selectedPatient,
|
||||
widget.businessUser,
|
||||
widget.business,
|
||||
"business",
|
||||
),
|
||||
context);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHErrorMessage(errorType: "Input Error");
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
buttonText: "Generate",
|
||||
buttonColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void serviceDescriptionSelected() {
|
||||
if (_serviceDescController.text.isNotEmpty) {
|
||||
serviceDesc.value = _serviceDescController.text;
|
||||
} else {
|
||||
serviceDesc.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
void hasMedAid() {
|
||||
if (_medAidController.text.isNotEmpty) {
|
||||
medAid.value = _medAidController.text;
|
||||
} else {
|
||||
medAid.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
bool isInputValid() {
|
||||
switch (_serviceDescController.text) {
|
||||
case 'Procedure':
|
||||
if (_docTypeController.text.isEmpty ||
|
||||
_serviceDateController.text.isEmpty ||
|
||||
_icd10CodeController.text.isEmpty ||
|
||||
_amountController.text.isEmpty ||
|
||||
_prcedureNameController.text.isEmpty ||
|
||||
_proceedureAdditionalInfoController.text.isEmpty) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
if (_docTypeController.text.isEmpty ||
|
||||
_serviceDateController.text.isEmpty ||
|
||||
_icd10CodeController.text.isEmpty ||
|
||||
_amountController.text.isEmpty ||
|
||||
_serviceDescOptionsController.text.isEmpty) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String getUserTitle() {
|
||||
if (widget.businessUser!.title == "Doctor") {
|
||||
return "Dr.";
|
||||
} else {
|
||||
return widget.businessUser!.title;
|
||||
}
|
||||
}
|
||||
|
||||
String getTodayDate() {
|
||||
DateTime today = DateTime.now();
|
||||
return DateFormat('yyyy-MM-dd').format(today);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_docTypeController.dispose();
|
||||
_fullNameController.dispose();
|
||||
_idController.dispose();
|
||||
_medAidController.dispose();
|
||||
_medAidNoController.dispose();
|
||||
_medAidCodeController.dispose();
|
||||
_medAidNameController.dispose();
|
||||
_medAidSchemeController.dispose();
|
||||
_providerNameController.dispose();
|
||||
_practiceNoController.dispose();
|
||||
_vatNoController.dispose();
|
||||
_serviceDateController.dispose();
|
||||
_serviceDescController.dispose();
|
||||
_serviceDescOptionsController.dispose();
|
||||
_prcedureNameController.dispose();
|
||||
// _procedureDateController.dispose();
|
||||
_proceedureAdditionalInfoController.dispose();
|
||||
_icd10CodeController.dispose();
|
||||
_preauthNoController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_serviceDescController.addListener(serviceDescriptionSelected);
|
||||
_medAidController.addListener(hasMedAid);
|
||||
_fullNameController.text =
|
||||
"${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}";
|
||||
_idController.text = widget.selectedPatient.id_no;
|
||||
_medAidController.text = widget.selectedPatient.medical_aid;
|
||||
_medAidNameController.text = widget.selectedPatient.medical_aid_name;
|
||||
_medAidCodeController.text = widget.selectedPatient.medical_aid_code;
|
||||
_medAidNoController.text = widget.selectedPatient.medical_aid_no;
|
||||
_medAidSchemeController.text = widget.selectedPatient.medical_aid_scheme;
|
||||
_serviceDateController.text = getTodayDate();
|
||||
_providerNameController.text =
|
||||
"${getUserTitle()} ${widget.signedInUser.fname} ${widget.signedInUser.lname}";
|
||||
_practiceNoController.text = widget.business!.practice_no;
|
||||
_vatNoController.text = widget.business!.vat_no;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MIHWindow(
|
||||
fullscreen: false,
|
||||
windowTitle: "Generate Claim/ Statement Document",
|
||||
windowTools: const [],
|
||||
onWindowTapClose: () {
|
||||
// medicineController.clear();
|
||||
// quantityController.clear();
|
||||
// dosageController.clear();
|
||||
// timesDailyController.clear();
|
||||
// noDaysController.clear();
|
||||
// noRepeatsController.clear();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
windowBody: [
|
||||
getWindowBody(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,573 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/medicine_search.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_search_input.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_env/env.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/app_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/patients.dart';
|
||||
import 'package:Mzansi_Innovation_Hub/mih_objects/perscription.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
|
||||
class PrescripInput extends StatefulWidget {
|
||||
final TextEditingController medicineController;
|
||||
final TextEditingController quantityController;
|
||||
final TextEditingController dosageController;
|
||||
final TextEditingController timesDailyController;
|
||||
final TextEditingController noDaysController;
|
||||
final TextEditingController noRepeatsController;
|
||||
final TextEditingController outputController;
|
||||
final Patient selectedPatient;
|
||||
final AppUser signedInUser;
|
||||
final Business? business;
|
||||
final BusinessUser? businessUser;
|
||||
const PrescripInput({
|
||||
super.key,
|
||||
required this.medicineController,
|
||||
required this.quantityController,
|
||||
required this.dosageController,
|
||||
required this.timesDailyController,
|
||||
required this.noDaysController,
|
||||
required this.noRepeatsController,
|
||||
required this.outputController,
|
||||
required this.selectedPatient,
|
||||
required this.signedInUser,
|
||||
required this.business,
|
||||
required this.businessUser,
|
||||
});
|
||||
|
||||
@override
|
||||
State<PrescripInput> createState() => _PrescripInputState();
|
||||
}
|
||||
|
||||
class _PrescripInputState extends State<PrescripInput> {
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
List<Perscription> perscriptionObjOutput = [];
|
||||
late double width;
|
||||
late double height;
|
||||
|
||||
final numberOptions = [
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20",
|
||||
"21",
|
||||
"22",
|
||||
"23",
|
||||
"24",
|
||||
"25",
|
||||
"26",
|
||||
"27",
|
||||
"28",
|
||||
"29",
|
||||
"30"
|
||||
];
|
||||
|
||||
Future<void> generatePerscription() async {
|
||||
//start loading circle
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const Mihloadingcircle();
|
||||
},
|
||||
);
|
||||
|
||||
var response1 = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/minio/generate/perscription/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"app_id": widget.selectedPatient.app_id,
|
||||
"fullName":
|
||||
"${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}",
|
||||
"id_no": widget.selectedPatient.id_no,
|
||||
"docfname":
|
||||
"DR. ${widget.signedInUser.fname} ${widget.signedInUser.lname}",
|
||||
"busName": widget.business!.Name,
|
||||
"busAddr": "*TO BE ADDED IN THE FUTURE*",
|
||||
"busNo": widget.business!.contact_no,
|
||||
"busEmail": widget.business!.bus_email,
|
||||
"logo_path": widget.business!.logo_path,
|
||||
"sig_path": widget.businessUser!.sig_path,
|
||||
"data": perscriptionObjOutput,
|
||||
}),
|
||||
);
|
||||
//print(response1.statusCode);
|
||||
DateTime now = new DateTime.now();
|
||||
DateTime date = new DateTime(now.year, now.month, now.day);
|
||||
String fileName =
|
||||
"Perscription-${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}-${date.toString().substring(0, 10)}.pdf";
|
||||
if (response1.statusCode == 200) {
|
||||
var response2 = await http.post(
|
||||
Uri.parse("${AppEnviroment.baseApiUrl}/files/insert/"),
|
||||
headers: <String, String>{
|
||||
"Content-Type": "application/json; charset=UTF-8"
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"file_path":
|
||||
"${widget.selectedPatient.app_id}/patient_files/$fileName",
|
||||
"file_name": fileName,
|
||||
"app_id": widget.selectedPatient.app_id
|
||||
}),
|
||||
);
|
||||
//print(response2.statusCode);
|
||||
if (response2.statusCode == 201) {
|
||||
setState(() {
|
||||
//To do
|
||||
widget.medicineController.clear();
|
||||
widget.dosageController.clear();
|
||||
widget.timesDailyController.clear();
|
||||
widget.noDaysController.clear();
|
||||
widget.timesDailyController.clear();
|
||||
widget.noRepeatsController.clear();
|
||||
widget.quantityController.clear();
|
||||
widget.outputController.clear();
|
||||
// futueFiles = fetchFiles();
|
||||
});
|
||||
// end loading circle
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed('/patient-manager/patient',
|
||||
arguments: PatientViewArguments(
|
||||
widget.signedInUser,
|
||||
widget.selectedPatient,
|
||||
widget.businessUser,
|
||||
widget.business,
|
||||
"business",
|
||||
));
|
||||
String message =
|
||||
"The perscription $fileName has been successfully generated and added to ${widget.selectedPatient.first_name} ${widget.selectedPatient.last_name}'s record. You can now access and download it for their use.";
|
||||
successPopUp(message);
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
} else {
|
||||
internetConnectionPopUp();
|
||||
}
|
||||
}
|
||||
|
||||
void internetConnectionPopUp() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHErrorMessage(errorType: "Internet Connection");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void successPopUp(String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MIHSuccessMessage(
|
||||
successType: "Success",
|
||||
successMessage: message,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void getMedsPopUp(TextEditingController medSearch) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return MedicineSearch(
|
||||
searchVlaue: medSearch,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
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() {
|
||||
String name;
|
||||
String unit;
|
||||
String form;
|
||||
List<String> medNameList = widget.medicineController.text.split("%t");
|
||||
if (medNameList.length == 1) {
|
||||
name = medNameList[0];
|
||||
unit = "";
|
||||
form = "";
|
||||
} else {
|
||||
name = medNameList[0];
|
||||
unit = medNameList[1];
|
||||
form = medNameList[2];
|
||||
}
|
||||
int quantityCalc = calcQuantity(
|
||||
widget.dosageController.text,
|
||||
widget.timesDailyController.text,
|
||||
widget.noDaysController.text,
|
||||
medNameList[2].toLowerCase());
|
||||
Perscription tempObj = Perscription(
|
||||
name: name,
|
||||
unit: unit,
|
||||
form: form,
|
||||
fullForm: getFullDoagesForm(form),
|
||||
quantity: "$quantityCalc",
|
||||
dosage: widget.dosageController.text,
|
||||
times: widget.timesDailyController.text,
|
||||
days: widget.noDaysController.text,
|
||||
repeats: widget.noRepeatsController.text,
|
||||
);
|
||||
perscriptionObjOutput.add(tempObj);
|
||||
}
|
||||
|
||||
String getPerscTitle(int index) {
|
||||
return "${perscriptionObjOutput[index].name} - ${perscriptionObjOutput[index].form}";
|
||||
}
|
||||
|
||||
String getPerscSubtitle(int index) {
|
||||
if (perscriptionObjOutput[index].form.toLowerCase() == "syr") {
|
||||
String unit = perscriptionObjOutput[index].unit.toLowerCase();
|
||||
if (perscriptionObjOutput[index].unit.toLowerCase().contains("ml")) {
|
||||
unit = "ml";
|
||||
}
|
||||
return "${perscriptionObjOutput[index].dosage} $unit, ${perscriptionObjOutput[index].times} time(s) daily, for ${perscriptionObjOutput[index].days} day(s)\nQuantity: ${perscriptionObjOutput[index].quantity}\nNo. of repeats: ${perscriptionObjOutput[index].repeats}";
|
||||
} else {
|
||||
return "${perscriptionObjOutput[index].dosage} ${perscriptionObjOutput[index].fullForm}(s), ${perscriptionObjOutput[index].times} time(s) daily, for ${perscriptionObjOutput[index].days} day(s)\nQuantity: ${perscriptionObjOutput[index].quantity}\nNo. of repeats: ${perscriptionObjOutput[index].repeats}";
|
||||
}
|
||||
}
|
||||
|
||||
String getFullDoagesForm(String abr) {
|
||||
var dosageFormList = {
|
||||
"liq": "liquid",
|
||||
"tab": "tablet",
|
||||
"cap": "capsule",
|
||||
"cps": "capsule",
|
||||
"oin": "ointment",
|
||||
"lit": "lotion",
|
||||
"lot": "lotion",
|
||||
"inj": "injection",
|
||||
"syr": "syrup",
|
||||
"dsp": "effervescent tablet",
|
||||
"eft": "effervescent tablet",
|
||||
"ear": "drops",
|
||||
"drp": "drops",
|
||||
"opd": "drops",
|
||||
"udv": "vial",
|
||||
"sus": "suspension",
|
||||
"susp": "suspension",
|
||||
"cal": "calasthetic",
|
||||
"sol": "solution",
|
||||
"sln": "solution",
|
||||
"neb": "nebuliser",
|
||||
"inh": "inhaler",
|
||||
"spo": "inhaler",
|
||||
"inf": "infusion",
|
||||
"chg": "chewing Gum",
|
||||
"vac": "vacutainer",
|
||||
"vag": "vaginal gel",
|
||||
"jel": "gel",
|
||||
"eyo": "eye ointment",
|
||||
"vat": "vaginal cream",
|
||||
"poi": "injection",
|
||||
"ped": "powder",
|
||||
"pow": "powder",
|
||||
"por": "powder",
|
||||
"sac": "sachet",
|
||||
"sup": "suppository",
|
||||
"cre": "cream",
|
||||
"ptd": "patch",
|
||||
"ect": "tablet",
|
||||
"nas": "spray",
|
||||
};
|
||||
String form;
|
||||
if (dosageFormList[abr.toLowerCase()] == null) {
|
||||
form = abr;
|
||||
} else {
|
||||
form = dosageFormList[abr.toLowerCase()]!;
|
||||
}
|
||||
return form;
|
||||
}
|
||||
|
||||
int calcQuantity(String dosage, String times, String days, String form) {
|
||||
var dosageFormList = [
|
||||
"tab",
|
||||
"cap",
|
||||
"cps",
|
||||
"dsp",
|
||||
"eft",
|
||||
"udv",
|
||||
"chg",
|
||||
"sac",
|
||||
"sup",
|
||||
"ptd",
|
||||
"ect",
|
||||
];
|
||||
if (dosageFormList.contains(form)) {
|
||||
return int.parse(dosage) * int.parse(times) * int.parse(days);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
Widget displayMedInput() {
|
||||
return Column(
|
||||
children: [
|
||||
//const SizedBox(height: 25.0),
|
||||
|
||||
KeyboardListener(
|
||||
focusNode: _focusNode,
|
||||
autofocus: true,
|
||||
onKeyEvent: (event) async {
|
||||
if (event is KeyDownEvent &&
|
||||
event.logicalKey == LogicalKeyboardKey.enter) {
|
||||
getMedsPopUp(widget.medicineController);
|
||||
}
|
||||
},
|
||||
child: MIHSearchField(
|
||||
controller: widget.medicineController,
|
||||
hintText: "Medicine",
|
||||
required: true,
|
||||
editable: true,
|
||||
onTap: () {
|
||||
getMedsPopUp(widget.medicineController);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
// SizedBox(
|
||||
// width: 300,
|
||||
// child: MIHDropdownField(
|
||||
// controller: widget.quantityController,
|
||||
// hintText: "Quantity",
|
||||
// dropdownOptions: numberOptions,
|
||||
// required: true,
|
||||
// editable: true,
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 10.0),
|
||||
MIHDropdownField(
|
||||
controller: widget.dosageController,
|
||||
hintText: "Dosage",
|
||||
dropdownOptions: numberOptions,
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
MIHDropdownField(
|
||||
controller: widget.timesDailyController,
|
||||
hintText: "Times Daily",
|
||||
dropdownOptions: numberOptions,
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
MIHDropdownField(
|
||||
controller: widget.noDaysController,
|
||||
hintText: "No. Days",
|
||||
dropdownOptions: numberOptions,
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 10.0),
|
||||
MIHDropdownField(
|
||||
controller: widget.noRepeatsController,
|
||||
hintText: "No. Repeats",
|
||||
dropdownOptions: numberOptions,
|
||||
required: true,
|
||||
editable: true,
|
||||
enableSearch: false,
|
||||
),
|
||||
const SizedBox(height: 15.0),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
height: 50,
|
||||
child: MIHButton(
|
||||
buttonText: "Add",
|
||||
buttonColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
onTap: () {
|
||||
if (isFieldsFilled()) {
|
||||
// int quantity;
|
||||
// int.parse(widget.dosageController.text) *
|
||||
// int.parse(widget.timesDailyController.text) *
|
||||
// int.parse(widget.noDaysController.text);
|
||||
setState(() {
|
||||
//widget.quantityController.text = "$quantity";
|
||||
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 MIHErrorMessage(errorType: "Input Error");
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget displayPerscList() {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 550,
|
||||
height: 325,
|
||||
decoration: BoxDecoration(
|
||||
color: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
border: Border.all(
|
||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
width: 3.0),
|
||||
),
|
||||
child: ListView.separated(
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
||||
child: Divider(),
|
||||
);
|
||||
},
|
||||
itemCount: perscriptionObjOutput.length,
|
||||
itemBuilder: (context, index) {
|
||||
//final patient = widget.patients[index].id_no.contains(widget.searchString);
|
||||
return ListTile(
|
||||
title: Text(
|
||||
getPerscTitle(index),
|
||||
style: TextStyle(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
getPerscSubtitle(index),
|
||||
style: TextStyle(
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
),
|
||||
//onTap: () {},
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.delete_forever_outlined,
|
||||
color:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
perscriptionObjOutput.removeAt(index);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15.0),
|
||||
SizedBox(
|
||||
width: 300,
|
||||
height: 50,
|
||||
child: MIHButton(
|
||||
onTap: () async {
|
||||
if (perscriptionObjOutput.isNotEmpty) {
|
||||
//print(jsonEncode(perscriptionObjOutput));
|
||||
await generatePerscription();
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const MIHErrorMessage(errorType: "Input Error");
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
buttonText: "Generate",
|
||||
buttonColor: MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
//futueMeds = getMedList(endpointMeds);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var size = MediaQuery.of(context).size;
|
||||
setState(() {
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
});
|
||||
return Wrap(
|
||||
direction: Axis.horizontal,
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: 500, child: displayMedInput()),
|
||||
displayPerscList(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user