From 52554d1aef9ead047f2694c0d228339d75c567ac Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 23 Dec 2020 15:16:54 +0200 Subject: [PATCH] add and remove allergy --- .../SOAP/subjective/add_allergies_widget.dart | 55 ++--- .../SOAP/subjective/add_history_widget.dart | 194 +++++++++++++----- .../SOAP/subjective/subjective_page.dart | 9 +- 3 files changed, 181 insertions(+), 77 deletions(-) diff --git a/lib/widgets/patients/profile/SOAP/subjective/add_allergies_widget.dart b/lib/widgets/patients/profile/SOAP/subjective/add_allergies_widget.dart index d3260776..eaa3889d 100644 --- a/lib/widgets/patients/profile/SOAP/subjective/add_allergies_widget.dart +++ b/lib/widgets/patients/profile/SOAP/subjective/add_allergies_widget.dart @@ -25,7 +25,6 @@ class AddAllergiesWidget extends StatefulWidget { } class _AddAllergiesWidgetState extends State { - List myAllergiesList; TextEditingController remarkController = TextEditingController(); @@ -73,35 +72,45 @@ class _AddAllergiesWidgetState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Texts(selectedAllergy.selectedAllergy.nameEn + Texts(selectedAllergy.selectedAllergy.nameEn.toUpperCase(), + variant: "bodyText", bold: true, color: Colors.black), + Texts( + selectedAllergy.selectedAllergySeverity.nameEn .toUpperCase(), - variant: "bodyText", - bold: true, - color: Colors.black), - Texts(selectedAllergy.selectedAllergySeverity.nameEn - .toUpperCase(), - variant: "bodyText", - bold: true, - color: AppGlobal.appPrimaryColor), - Icon( - FontAwesomeIcons.trash, - color: Colors.grey, - size: 20, - ) - ], - ), SizedBox( - height: 20, - ), + variant: "bodyText", + bold: true, + color: AppGlobal.appPrimaryColor), + InkWell( + child: Icon( + FontAwesomeIcons.trash, + color: Colors.grey, + size: 20, + ), + onTap: () => removeAllergy(selectedAllergy), + ) ], - ); - }).toList() - - ), + ), + SizedBox( + height: 10, + ), + ], + ); + }).toList()), ) ], ); } + removeAllergy(MySelectedAllergy mySelectedAllergy) { + Iterable allergy = + widget.myAllergiesList.where((element) => mySelectedAllergy == element); + + if (allergy.length > 0) + setState(() { + widget.myAllergiesList.remove(allergy.first); + }); + } + openAllergiesList(BuildContext context) { showModalBottomSheet( backgroundColor: Colors.white, diff --git a/lib/widgets/patients/profile/SOAP/subjective/add_history_widget.dart b/lib/widgets/patients/profile/SOAP/subjective/add_history_widget.dart index 085fa68d..1907453d 100644 --- a/lib/widgets/patients/profile/SOAP/subjective/add_history_widget.dart +++ b/lib/widgets/patients/profile/SOAP/subjective/add_history_widget.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/enum/viewstate.dart'; import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart'; +import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/Text.dart'; @@ -16,6 +17,10 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:hexcolor/hexcolor.dart'; class AddHistoryWidget extends StatefulWidget { + final List myHistoryList; + + const AddHistoryWidget({Key key, this.myHistoryList}) : super(key: key); + @override _AddHistoryWidgetState createState() => _AddHistoryWidgetState(); } @@ -69,54 +74,63 @@ class _AddHistoryWidgetState extends State margin: EdgeInsets.only(left: 15, right: 15, top: 15), child: Column( - children: [ - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Texts('Abdomen Pain', - variant: "bodyText", - bold: true, - color: Colors.black), - Icon( - FontAwesomeIcons.trash, - color: Colors.grey, - size: 20, - ) - ], - ), - SizedBox( - height: 20, - ), - Row( - mainAxisAlignment: - MainAxisAlignment.spaceBetween, + children: widget.myHistoryList.map((myHistory) { + return Column( children: [ - Texts('Back Pain', - variant: "bodyText", - bold: true, - color: Colors.black), - Icon( - FontAwesomeIcons.trash, - color: Colors.grey, - size: 20, - ) + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Texts(myHistory.nameEn, + variant: "bodyText", bold: true, color: Colors.black), + InkWell( + child: Icon( + FontAwesomeIcons.trash, + color: Colors.grey, + size: 20, + ), + onTap: () => removeHistory(myHistory), + ) + ], + ), + SizedBox( + height: 20, + ), ], - ), - ], + ); + }).toList(), ), ) ], ); } + removeHistory(MasterKeyModel masterKey) { + Iterable history = widget.myHistoryList.where((element) => + masterKey.id == element.id && masterKey.typeId == element.typeId); + + if (history.length > 0) + setState(() { + widget.myHistoryList.remove(history.first); + }); + } + openHistoryList(BuildContext context) { showModalBottomSheet( backgroundColor: Colors.white, isScrollControlled: true, context: context, builder: (context) { - return AddHistoryDialog(changePageViewIndex:changePageViewIndex, controller: _controller,); + return AddHistoryDialog( + changePageViewIndex: changePageViewIndex, + controller: _controller, + myHistoryList: widget.myHistoryList, + addSelectedHistories: () { + setState(() { + Navigator.of(context).pop(); + }); + }, + removeHistory: (masterKey) => removeHistory(masterKey), + ); }); } } @@ -203,8 +217,12 @@ class _PriorityBarState extends State { class AddHistoryDialog extends StatefulWidget { final Function changePageViewIndex; final PageController controller; + final List myHistoryList; + final Function addSelectedHistories; + final Function (MasterKeyModel) removeHistory; - const AddHistoryDialog({Key key, this.changePageViewIndex, this.controller}) + const AddHistoryDialog( + {Key key, this.changePageViewIndex, this.controller, this.myHistoryList, this.addSelectedHistories, this.removeHistory}) : super(key: key); @override @@ -286,12 +304,28 @@ class _AddHistoryDialogState extends State { Row( children: [ Checkbox( - value: true, + value: isServiceSelected( + historyInfo), activeColor: - Colors.red[800], + Colors.red[800], onChanged: (bool newValue) { - setState(() {}); + setState(() { + if (isServiceSelected( + historyInfo + )) { + widget + .removeHistory( + historyInfo + ); + } + else { + widget + .myHistoryList + .add( + historyInfo); + } + }); }), Expanded( child: Padding( @@ -325,8 +359,11 @@ class _AddHistoryDialogState extends State { ), if (model.state == ViewState.Idle) AppButton( - title: "Add SELECTED HISTORIES".toUpperCase(), - onPressed: () {}, + title: "Add SELECTED HISTORIES" + .toUpperCase(), + onPressed: () { + widget.addSelectedHistories(); + }, ), ], ), @@ -355,12 +392,29 @@ class _AddHistoryDialogState extends State { Row( children: [ Checkbox( - value: true, + value: isServiceSelected( + historyInfo), activeColor: Colors.red[800], onChanged: - (bool newValue) { - setState(() {}); + ( + bool newValue) { + setState(() { + if (isServiceSelected( + historyInfo + )) { + widget + .removeHistory( + historyInfo + ); + } + else { + widget + .myHistoryList + .add( + historyInfo); + } + }); }), Expanded( child: Padding( @@ -394,8 +448,11 @@ class _AddHistoryDialogState extends State { ), if (model.state == ViewState.Idle) AppButton( - title: "Add SELECTED HISTORIES".toUpperCase(), - onPressed: () {}, + title: "Add SELECTED HISTORIES" + .toUpperCase(), + onPressed: () { + widget.addSelectedHistories(); + }, ), ], ), @@ -424,12 +481,29 @@ class _AddHistoryDialogState extends State { Row( children: [ Checkbox( - value: true, + value: isServiceSelected( + historyInfo), activeColor: Colors.red[800], onChanged: - (bool newValue) { - setState(() {}); + ( + bool newValue) { + setState(() { + if (isServiceSelected( + historyInfo + )) { + widget + .removeHistory( + historyInfo + ); + } + else { + widget + .myHistoryList + .add( + historyInfo); + } + }); }), Expanded( child: Padding( @@ -463,8 +537,13 @@ class _AddHistoryDialogState extends State { ), if (model.state == ViewState.Idle) AppButton( - title: "Add SELECTED HISTORIES".toUpperCase(), - onPressed: () {}, + title: "Add SELECTED HISTORIES" + .toUpperCase(), + onPressed: () { + setState(() { + widget.addSelectedHistories(); + }); + }, ), ], ), @@ -474,9 +553,22 @@ class _AddHistoryDialogState extends State { ), ], ), - )), + )), ), ), )); } + + isServiceSelected(MasterKeyModel masterKey) { + Iterable history = + widget + .myHistoryList + .where((element) => + masterKey.id == element.id && masterKey.typeId == element.typeId); + if (history.length > 0) { + return true; + } + return false; + } + } diff --git a/lib/widgets/patients/profile/SOAP/subjective/subjective_page.dart b/lib/widgets/patients/profile/SOAP/subjective/subjective_page.dart index 74d2aa43..bfea6d35 100644 --- a/lib/widgets/patients/profile/SOAP/subjective/subjective_page.dart +++ b/lib/widgets/patients/profile/SOAP/subjective/subjective_page.dart @@ -1,6 +1,7 @@ import 'package:doctor_app_flutter/config/config.dart'; import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart'; import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart'; +import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart'; import 'package:doctor_app_flutter/models/SOAP/my_selected_allergy.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; @@ -30,6 +31,7 @@ class _SubjectivePageState extends State { bool isHistoryExpand = false; bool isAllergiesExpand = false; List myAllergiesList = List(); + List myHistoryList = List(); TextEditingController messageController = TextEditingController(); @override @@ -143,7 +145,7 @@ class _SubjectivePageState extends State { children: [ Row( children: [ - Texts('History', + Texts('History'.toUpperCase(), variant: isHistoryExpand ? "bodyText" : '', bold: isHistoryExpand ? true : false, color: Colors.black), @@ -167,7 +169,7 @@ class _SubjectivePageState extends State { ), bodyWidget: Column( children: [ - AddHistoryWidget() + AddHistoryWidget(myHistoryList: myHistoryList) ], ), isExpand: isHistoryExpand, @@ -189,7 +191,7 @@ class _SubjectivePageState extends State { children: [ Row( children: [ - Texts('Allergies', + Texts('Allergies'.toUpperCase(), variant: isAllergiesExpand ? "bodyText" : '', bold: isAllergiesExpand ? true : false, color: Colors.black), @@ -238,6 +240,7 @@ class _SubjectivePageState extends State { .of(context) .next, onPressed: () { + print( myHistoryList.toString()); widget.changePageViewIndex(1); }, ),