Merge pull request #191 from yaso-meth/NEW--Triiger-Mzansi-Ai-from-home

NEW--Triiger-Mzansi-Ai-from-home
This commit is contained in:
yaso-meth
2025-06-02 11:05:43 +02:00
committed by GitHub
14 changed files with 350 additions and 303 deletions

View File

@@ -124,6 +124,10 @@ class _MihSearchBarState extends State<MihSearchBar> {
child: TextField(
controller: widget.controller, // Assign the controller
focusNode: widget.searchFocusNode,
onSubmitted: (value) {
widget.onPrefixIconTap
?.call(); // Call the prefix icon tap handler
},
style: TextStyle(
color: widget.hintColor,
fontWeight: FontWeight.w600,

View File

@@ -207,3 +207,13 @@ class WalletArguments {
this.index,
);
}
class MzansiAiArguments {
final AppUser signedInUser;
final String? startUpQuestion;
MzansiAiArguments(
this.signedInUser,
this.startUpQuestion,
);
}

View File

@@ -229,7 +229,10 @@ class _MIHHomeLegacyState extends State<MIHHomeLegacy> {
onTap: () {
Navigator.of(context).pushNamed(
'/mzansi-ai',
arguments: widget.signedInUser,
arguments: MzansiAiArguments(
widget.signedInUser,
"",
),
);
},
tileName: "Mzansi AI",
@@ -464,7 +467,10 @@ class _MIHHomeLegacyState extends State<MIHHomeLegacy> {
onTap: () {
Navigator.of(context).pushNamed(
'/mzansi-ai',
arguments: widget.signedInUser,
arguments: MzansiAiArguments(
widget.signedInUser,
"",
),
);
},
tileName: "Mzansi AI",

View File

@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
@@ -216,7 +217,16 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
hintColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onPrefixIconTap: () {
print("Search Text: ${searchController.text}");
Navigator.of(context).pushNamed(
'/mzansi-ai',
arguments: MzansiAiArguments(
widget.signedInUser,
searchController.text.isEmpty
? null
: searchController.text,
),
);
searchController.clear();
},
searchFocusNode: _searchFocusNode,
),
@@ -231,6 +241,7 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
.contains(searchController.text.toLowerCase()))
.map((package) => package.values.first)
.toList();
if (filteredPackages.isNotEmpty) {
return GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
@@ -245,6 +256,34 @@ class _MihBusinessHomeState extends State<MihBusinessHome>
return filteredPackages[index];
},
);
} else {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
MihIcons.mzansiAi,
size: 165,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor(),
),
const SizedBox(height: 10),
Text(
"Mzansi AI is here to help you!",
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor(),
),
),
],
);
}
},
),
],

View File

@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:mzansi_innovation_hub/main.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
@@ -259,7 +260,16 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
hintColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onPrefixIconTap: () {
print("Search Text: ${searchController.text}");
Navigator.of(context).pushNamed(
'/mzansi-ai',
arguments: MzansiAiArguments(
widget.signedInUser,
searchController.text.isEmpty
? null
: searchController.text,
),
);
searchController.clear();
},
searchFocusNode: _searchFocusNode,
),
@@ -274,6 +284,7 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
.contains(searchController.text.toLowerCase()))
.map((package) => package.values.first)
.toList();
if (filteredPackages.isNotEmpty) {
return GridView.builder(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
@@ -289,6 +300,34 @@ class _MihPersonalHomeState extends State<MihPersonalHome>
// return personalPackages[index];
},
);
} else {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
MihIcons.mzansiAi,
size: 165,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor(),
),
const SizedBox(height: 10),
Text(
"Mzansi AI is here to help you!",
textAlign: TextAlign.center,
overflow: TextOverflow.visible,
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: MzanziInnovationHub.of(context)!
.theme
.secondaryColor(),
),
),
],
);
}
},
),
],

View File

@@ -1,15 +1,19 @@
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_action.dart';
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tools.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_packages/mzansi_ai/package_tools/ai_chat.dart';
import 'package:flutter/material.dart';
class MzansiAi extends StatefulWidget {
final AppUser signedInUser;
// final AppUser signedInUser;
// final String? startUpQuestion;
final MzansiAiArguments arguments;
const MzansiAi({
super.key,
required this.signedInUser,
required this.arguments,
// required this.signedInUser,
// this.startUpQuestion,
});
@override
@@ -46,7 +50,10 @@ class _MzansiAiState extends State<MzansiAi> {
List<Widget> getToolBody() {
List<Widget> toolBodies = [
AiChat(signedInUser: widget.signedInUser),
AiChat(
signedInUser: widget.arguments.signedInUser,
startUpQuestion: widget.arguments.startUpQuestion,
),
];
return toolBodies;
}

View File

@@ -3,6 +3,7 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_icons.dart';
import 'package:mzansi_innovation_hub/mih_objects/app_user.dart';
import 'package:flutter/material.dart';
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
class MzansiAiTile extends StatefulWidget {
final AppUser signedInUser;
@@ -25,7 +26,10 @@ class _MzansiAiTileState extends State<MzansiAiTile> {
onTap: () {
Navigator.of(context).pushNamed(
'/mzansi-ai',
arguments: widget.signedInUser,
arguments: MzansiAiArguments(
widget.signedInUser,
"",
),
);
},
appName: "Mzansi AI",

View File

@@ -21,9 +21,11 @@ import 'package:uuid/uuid.dart';
class AiChat extends StatefulWidget {
final AppUser signedInUser;
final String? startUpQuestion;
const AiChat({
super.key,
required this.signedInUser,
this.startUpQuestion,
});
@override
@@ -593,6 +595,12 @@ class _AiChatState extends State<AiChat> {
_loadMessages();
initTTS();
_ttsVoiceController.addListener(voiceSelected);
if (widget.startUpQuestion != null && widget.startUpQuestion!.isNotEmpty) {
final partialText = types.PartialText(text: widget.startUpQuestion!);
WidgetsBinding.instance.addPostFrameCallback((_) {
_handleSendPressed(partialText);
});
}
}
@override

View File

@@ -24,7 +24,6 @@ class MihBusinessUserSearch extends StatefulWidget {
}
class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
final FocusNode _focusNode = FocusNode();
final TextEditingController searchController = TextEditingController();
late Future<List<AppUser>> userSearchResults;
final FocusNode _searchFocusNode = FocusNode();
@@ -101,15 +100,6 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
Widget getBody(double width) {
return MihSingleChildScroll(
child: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
submitUserForm();
}
},
child: Column(mainAxisSize: MainAxisSize.max, children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20),
@@ -117,8 +107,7 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
controller: searchController,
hintText: "Search Users",
prefixIcon: Icons.search,
fillColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
hintColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onPrefixIconTap: () {
submitUserForm();
@@ -156,9 +145,8 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
"$errorCode: Error pulling Patients Data\n/patients/search/$userSearch\n$errorBody",
style: TextStyle(
fontSize: 25,
color: MzanziInnovationHub.of(context)!
.theme
.errorColor()),
color:
MzanziInnovationHub.of(context)!.theme.errorColor()),
textAlign: TextAlign.center,
),
);
@@ -166,7 +154,6 @@ class _MihBusinessUserSearchState extends State<MihBusinessUserSearch> {
},
),
]),
),
);
}
}

View File

@@ -42,18 +42,6 @@ class _MihPatientSearchState extends State<MihPatientSearch> {
Widget getPatientSearch(double width) {
return MihSingleChildScroll(
child: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
// submitPatientForm();
submitPatientSearch();
//To-Do: Implement the search function
// print("To-Do: Implement the search function");
}
},
child: Column(mainAxisSize: MainAxisSize.max, children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20),
@@ -61,12 +49,10 @@ class _MihPatientSearchState extends State<MihPatientSearch> {
controller: _mihPatientSearchController,
hintText: "Search Patient ID/ Aid No.",
prefixIcon: Icons.search,
fillColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
hintColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onPrefixIconTap: () {
submitPatientSearch();
print("Search Text: ${_mihPatientSearchController.text}");
},
onClearIconTap: () {
setState(() {
@@ -98,17 +84,15 @@ class _MihPatientSearchState extends State<MihPatientSearch> {
snapshot.data!, _mihPatientSearchString);
//print(patientsList);
}
return displayPatientList(
patientsList, _mihPatientSearchString);
return displayPatientList(patientsList, _mihPatientSearchString);
} else {
return Center(
child: Text(
"Error pulling Patients Data\n$baseUrl/patients/search/$_mihPatientSearchString",
style: TextStyle(
fontSize: 25,
color: MzanziInnovationHub.of(context)!
.theme
.errorColor()),
color:
MzanziInnovationHub.of(context)!.theme.errorColor()),
textAlign: TextAlign.center,
),
);
@@ -116,7 +100,6 @@ class _MihPatientSearchState extends State<MihPatientSearch> {
},
),
]),
),
);
}

View File

@@ -42,19 +42,6 @@ class _MyPatientListState extends State<MyPatientList> {
Widget myPatientListTool(double width) {
return MihSingleChildScroll(
child: KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
setState(() {
_myPatientIdSearchString = _myPatientSearchController.text;
_myPatientList = MIHApiCalls.getPatientAccessListOfBusiness(
widget.business!.business_id);
});
}
},
child: Column(mainAxisSize: MainAxisSize.max, children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: width / 20),
@@ -62,8 +49,7 @@ class _MyPatientListState extends State<MyPatientList> {
controller: _myPatientSearchController,
hintText: "Search Patient ID",
prefixIcon: Icons.search,
fillColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
fillColor: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
hintColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
onPrefixIconTap: () {
setState(() {
@@ -107,9 +93,8 @@ class _MyPatientListState extends State<MyPatientList> {
"Error pulling Patient Access Data\n$baseUrl/access-requests/business/patient/${widget.business!.business_id}",
style: TextStyle(
fontSize: 25,
color: MzanziInnovationHub.of(context)!
.theme
.errorColor()),
color:
MzanziInnovationHub.of(context)!.theme.errorColor()),
textAlign: TextAlign.center,
),
);
@@ -117,7 +102,6 @@ class _MyPatientListState extends State<MyPatientList> {
},
),
]),
),
);
}

View File

@@ -66,7 +66,6 @@ class _ClaimStatementWindowState extends State<ClaimStatementWindow> {
final ValueNotifier<String> medAid = ValueNotifier("");
List<ICD10Code> icd10codeList = [];
final FocusNode _searchFocusNode = FocusNode();
final FocusNode _focusNode = FocusNode();
void icd10SearchWindow(List<ICD10Code> codeList) {
showDialog(
@@ -189,19 +188,7 @@ class _ClaimStatementWindowState extends State<ClaimStatementWindow> {
},
),
//const SizedBox(height: 10),
KeyboardListener(
focusNode: _focusNode,
autofocus: true,
onKeyEvent: (event) async {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.enter) {
MIHIcd10CodeApis.getIcd10Codes(_icd10CodeController.text, context)
.then((result) {
icd10SearchWindow(result);
});
}
},
child: MihSearchBar(
MihSearchBar(
controller: _icd10CodeController,
hintText: "ICD-10 Code & Description",
prefixIcon: Icons.search,
@@ -218,7 +205,6 @@ class _ClaimStatementWindowState extends State<ClaimStatementWindow> {
},
searchFocusNode: _searchFocusNode,
),
),
const SizedBox(height: 10),
MIHTextField(
controller: _amountController,

View File

@@ -353,16 +353,7 @@ class _PrescripInputState extends State<PrescripInput> {
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: MihSearchBar(
MihSearchBar(
controller: widget.medicineController,
hintText: "Search Medicine",
prefixIcon: Icons.search,
@@ -376,7 +367,6 @@ class _PrescripInputState extends State<PrescripInput> {
},
searchFocusNode: _searchFocusNode,
),
),
const SizedBox(height: 10.0),
MIHDropdownField(

View File

@@ -331,11 +331,11 @@ class RouteGenerator {
//Mzansi AI
case '/mzansi-ai':
if (args is AppUser) {
if (args is MzansiAiArguments) {
return MaterialPageRoute(
settings: settings,
builder: (_) => MzansiAi(
signedInUser: args,
arguments: args,
),
);
}