new_configurable_card.dart 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. import 'dart:convert';
  2. import 'package:fis_common/event/event_type.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/components/dialog_input.dart';
  7. import 'package:vitalapp/components/dialog_number.dart';
  8. import 'package:vitalapp/components/dynamic_drawer.dart';
  9. import 'package:vitalapp/managers/interfaces/cachedRecord.dart';
  10. import 'package:vitalapp/managers/interfaces/template.dart';
  11. import 'package:vitalapp/pages/check/models/form.dart';
  12. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_blood_pressure.dart';
  13. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_blood_sugar.dart';
  14. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_body_temperature.dart';
  15. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_body_weight.dart';
  16. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_boold_oxygen.dart';
  17. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_check_box.dart';
  18. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_health_guidance_check_box.dart';
  19. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_input.dart';
  20. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_number_input.dart';
  21. import 'dart:math' as math;
  22. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_radio.dart';
  23. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_radio_score.dart';
  24. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_table.dart';
  25. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_toxic_substance.dart';
  26. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_urinalys.dart';
  27. import 'package:vitalapp/pages/check/widgets/exam_table/homecare_bed_history_from.dart';
  28. import 'package:vitalapp/pages/check/widgets/exam_table/hospitalization_history_from.dart';
  29. import 'package:vitalapp/pages/check/widgets/exam_table/inoculate_history_from.dart';
  30. import 'package:vitalapp/pages/check/widgets/exam_table/main_medication_status_from.dart';
  31. import 'package:vitalapp/pages/medical/controller.dart';
  32. import 'package:vitalapp/store/store.dart';
  33. class NewConfigurableCard extends StatefulWidget {
  34. final String cardKey;
  35. final Future<bool> Function(String, String, dynamic) callBack;
  36. final Widget? followUpWidget;
  37. final String? patientCode;
  38. final String? examData;
  39. final FEventHandler<bool>? onChangeCurrentKeyEvent;
  40. final FEventHandler<bool>? onSubmitEvent;
  41. const NewConfigurableCard({
  42. super.key,
  43. required this.cardKey,
  44. required this.callBack,
  45. this.followUpWidget,
  46. this.patientCode,
  47. this.examData,
  48. this.onSubmitEvent,
  49. this.onChangeCurrentKeyEvent,
  50. });
  51. @override
  52. State<NewConfigurableCard> createState() => NewConfigurableFormState();
  53. }
  54. class NewConfigurableFormState extends State<NewConfigurableCard> {
  55. /// 当前最新的模板的键值对
  56. Map<String, dynamic> templateRelation = {};
  57. /// 当前模板数据
  58. List<FormObject> currentTemplate = [];
  59. /// 当前title的下标
  60. // int currentTitleIndex = 0;
  61. Map<String, dynamic> formValue = {};
  62. var scaffoldKey = GlobalKey<ScaffoldState>();
  63. final _templateManager = Get.find<ITemplateManager>();
  64. final _cachedRecordManager = Get.find<ICachedRecordManager>();
  65. final arrowHeight = math.tan(120 / 180) * 19;
  66. List<String> deviceList = ['Temp', 'GLU', 'NIBP', 'SpO2', 'BMI'];
  67. Map<String, dynamic> deviceCached = {};
  68. Map currentTable = {};
  69. ScrollController _examScrollController = ScrollController();
  70. List<String> storeTypeList = [
  71. 'Qi_Score',
  72. 'Yang_Score',
  73. 'Yin_Score',
  74. 'Tan_Score',
  75. 'Shi_Score',
  76. 'Xue_Score',
  77. 'Qiyu_Score',
  78. 'Te_Score',
  79. 'Ping_Score'
  80. ];
  81. @override
  82. void initState() {
  83. initAddListener();
  84. super.initState();
  85. WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  86. if (mounted) {
  87. initTemplate();
  88. }
  89. });
  90. widget.onSubmitEvent?.addListener(submitEvent);
  91. _examScrollController.addListener(_scrollListener);
  92. }
  93. @override
  94. void dispose() {
  95. super.dispose();
  96. widget.onSubmitEvent?.removeListener(submitEvent);
  97. _examScrollController.removeListener(_scrollListener);
  98. _examScrollController.dispose();
  99. }
  100. void submitEvent(sender, e) {
  101. if (mounted) {
  102. if (e) {
  103. if (formValue.isNotEmpty) {
  104. submit();
  105. }
  106. }
  107. }
  108. }
  109. /// 是否有健康检测的页面权限
  110. bool _hasHealthMonitor() {
  111. bool hasAuth = false;
  112. Store.user.menuPermissionList?.forEach((element) {
  113. if (element.code == "JKJC") {
  114. hasAuth = true;
  115. }
  116. });
  117. return hasAuth;
  118. }
  119. /// 判断是否有健康检测的页面
  120. void initAddListener() {
  121. if (_hasHealthMonitor()) {
  122. var medicalController = Get.find<MedicalController>();
  123. medicalController.setExamData.addListener(onSetExamDataEvent);
  124. }
  125. }
  126. void onSetExamDataEvent(sender, Map<String, dynamic> e) {
  127. if (mounted) {
  128. Map<String, dynamic> examData = {};
  129. setState(() {
  130. print(widget.cardKey);
  131. e.forEach((key, value) {
  132. if (key != "Urine") {
  133. examData.addAll(value);
  134. } else {
  135. examData.addAll({"Urinary_Pro": value});
  136. }
  137. });
  138. Map<String, dynamic> newMap = Map.from(examData);
  139. if (examData["sugar"]?.isNotEmpty ?? false) {
  140. newMap.remove("sugar");
  141. // 将"sugar"的值作为"Fasting_Glucose_Mmol"键的值添加到新的Map中
  142. newMap["Fasting_Glucose_Mmol"] = examData["sugar"] ?? '';
  143. }
  144. formValue.addAll(newMap);
  145. });
  146. }
  147. }
  148. Future<void> submit() async {
  149. await widget.callBack(
  150. widget.cardKey,
  151. templateRelation[widget.cardKey]!,
  152. jsonEncode(formValue),
  153. );
  154. }
  155. Future<void> initTemplate() async {
  156. Store.app.busy = true;
  157. await fetchTemplateIndex();
  158. await fetchTemplate(widget.cardKey);
  159. await fetchTemplateData();
  160. Store.app.busy = false;
  161. }
  162. /// 读取健康检测的缓存
  163. Future<String?> readCachedRecord(String currentDevice) async {
  164. if (widget.patientCode == null) {
  165. return null;
  166. }
  167. String? value = await _cachedRecordManager.readCachedRecord(
  168. currentDevice,
  169. widget.patientCode!,
  170. 'ZLZS',
  171. );
  172. return value;
  173. }
  174. /// 读取体检的缓存
  175. Future<String?> readCachedCheck() async {
  176. if (widget.patientCode == null) {
  177. return null;
  178. }
  179. String? value = await _cachedRecordManager.readCachedRecord(
  180. widget.cardKey,
  181. widget.patientCode!,
  182. 'exam',
  183. );
  184. return value;
  185. }
  186. Future<void> readCached() async {
  187. for (var element in deviceList) {
  188. String? value = await readCachedRecord(element);
  189. if (value?.isNotEmpty ?? false) {
  190. deviceCached.addAll(jsonDecode(value!));
  191. }
  192. }
  193. }
  194. Future<void> fetchTemplateIndex() async {
  195. try {
  196. /// 获取模板的键值对
  197. String? templates;
  198. templates =
  199. await _templateManager.readTemplateRelation('templateRelation');
  200. templateRelation = jsonDecode(templates!);
  201. setState(() {});
  202. } catch (error) {
  203. print('发生错误: $error');
  204. }
  205. }
  206. Future<void> fetchTemplateData() async {
  207. // / 这逻辑需要优化
  208. if (widget.examData?.isNotEmpty ?? false) {
  209. formValue = jsonDecode(widget.examData!);
  210. return;
  211. }
  212. String? value = await readCachedCheck();
  213. await readCached();
  214. if (deviceCached.isNotEmpty) {
  215. formValue = deviceCached;
  216. setState(() {});
  217. return;
  218. }
  219. if (value?.isNotEmpty ?? false) {
  220. formValue = jsonDecode(value!);
  221. }
  222. formValue.forEach(
  223. (key, value) {
  224. if (value is List<String>) {
  225. formValue[key] = List<String>.from(formValue[key]);
  226. } else if (value is List<Map>) {
  227. formValue[key] = List<Map>.from(formValue[key]);
  228. }
  229. },
  230. );
  231. setState(() {});
  232. }
  233. Future<void> fetchTemplate(String key) async {
  234. try {
  235. if (templateRelation[key] == null) {
  236. currentTemplate = [];
  237. setState(() {});
  238. return;
  239. }
  240. var template =
  241. await _templateManager.readTemplate(templateRelation[key]!);
  242. String templateContent =
  243. TemplateDTO.fromJson(jsonDecode(template!)).templateContent!;
  244. List<Map<String, dynamic>> list =
  245. jsonDecode(templateContent).cast<Map<String, dynamic>>();
  246. for (var i in list) {
  247. if (i['children'] != null) {
  248. List<FormObject> currentChildren = [];
  249. for (var j in i['children']) {
  250. currentChildren.add(FormObject.fromJson(j));
  251. }
  252. i['children'] = currentChildren;
  253. }
  254. var item = FormObject.fromJson(i);
  255. currentTemplate.add(item);
  256. }
  257. if (widget.cardKey == 'LNRZYYJKGLFWJL') {
  258. for (var element in storeTypeList) {
  259. formValue[element] =
  260. calculatePhysicalFitnessScore(element, element == 'Ping_Score');
  261. }
  262. }
  263. setState(() {});
  264. } catch (error) {
  265. print('发生错误: $error');
  266. }
  267. }
  268. @override
  269. Widget build(BuildContext context) {
  270. return Scaffold(
  271. key: scaffoldKey,
  272. endDrawer: VDynamicDrawerWrapper(scaffoldKey: scaffoldKey),
  273. resizeToAvoidBottomInset: false,
  274. body: Column(
  275. children: [
  276. Expanded(
  277. child: Stack(
  278. children: [
  279. Row(
  280. mainAxisAlignment: MainAxisAlignment.start,
  281. crossAxisAlignment: CrossAxisAlignment.start,
  282. children: [
  283. // _buildDiagram(),
  284. _buildContent(),
  285. ],
  286. ),
  287. ],
  288. ),
  289. )
  290. ],
  291. ),
  292. );
  293. }
  294. Widget buildSingleItem(Widget item, int span) {
  295. return FractionallySizedBox(
  296. widthFactor: span == 24 ? 1 : 0.5,
  297. child: item,
  298. );
  299. }
  300. Widget buildWidget(FormObject? currentFormObject) {
  301. Map<String, Widget Function(FormObject)> widgetMap = {
  302. 'checkbox': _buildCheckBox,
  303. 'numberInput': _buildNumberInput,
  304. 'input': _buildInput,
  305. 'radio': _buildRadio,
  306. 'radioScore': _buildRadioScore,
  307. 'bloodPressure': _buildBloodPressure,
  308. 'bodyTemperature': _buildBodyTemperature,
  309. 'weight': _buildBodyWeight,
  310. 'sugar': _buildBodySugar,
  311. 'bloodOxygen': _buildBloodOxygen,
  312. 'healthGuidanceCheckBox': _buildHealthGuidanceCheckBox,
  313. 'medicalHistory': _buildMedicalHistory,
  314. 'homecareBedHistor': _buildHomecareBedHistory,
  315. 'table': _buildMainMedicationHistory,
  316. 'inoculateHistory': _buildInoculateHistory,
  317. 'safetyPrecautions': _buildToxicSubstance,
  318. 'urinalys': _buildUrinalysis,
  319. };
  320. Widget Function(FormObject) builder =
  321. widgetMap[currentFormObject?.type] ?? _buildInput;
  322. return builder(currentFormObject!);
  323. }
  324. Widget flowCardList() {
  325. int itemCount = 0;
  326. List<Widget> _cardList = [];
  327. bool currentTemplateOptionsIsNotEmpty = false;
  328. if (currentTemplate.isNotEmpty) {
  329. for (int i = 0; i < currentTemplate.length; i++) {
  330. itemCount = currentTemplate[i].children?.length ?? 0;
  331. currentTemplateOptionsIsNotEmpty =
  332. currentTemplate[i].options?.isNotEmpty ?? false;
  333. List<Widget> items = List.generate(itemCount, (index) {
  334. FormObject? currentFormObject = currentTemplate[i].children?[index];
  335. int span = currentFormObject?.span ?? 12;
  336. //父结构的options不等于空或null
  337. if (true) {
  338. //子结构的options若是无值则取父类的options值
  339. if (currentTemplateOptionsIsNotEmpty) {
  340. currentFormObject!.options = currentTemplate[i].options;
  341. }
  342. }
  343. return buildSingleItem(buildWidget(currentFormObject), span);
  344. });
  345. _cardList.addAll(items);
  346. }
  347. }
  348. return Scrollbar(
  349. thumbVisibility: true,
  350. controller: _examScrollController,
  351. child: SingleChildScrollView(
  352. controller: _examScrollController,
  353. child: Container(
  354. alignment: Alignment.topCenter,
  355. padding: const EdgeInsets.all(15),
  356. child: Wrap(
  357. runSpacing: 20, // 纵向元素间距
  358. alignment: WrapAlignment.start,
  359. children: _cardList,
  360. ),
  361. ),
  362. ),
  363. );
  364. }
  365. void _scrollListener() {
  366. if (mounted) {
  367. if (_examScrollController.position.pixels ==
  368. _examScrollController.position.maxScrollExtent) {
  369. // 滚动到底部
  370. _onScrollEnd();
  371. }
  372. }
  373. }
  374. void _onScrollEnd() {
  375. // 在这里触发您想要执行的方法
  376. print('Scroll to the bottom!');
  377. // widget.onChangeCurrentKeyEvent?.emit(this, true);
  378. }
  379. /// 主页面
  380. Widget _buildContent() {
  381. return Expanded(
  382. flex: 2,
  383. child: flowCardList(),
  384. );
  385. }
  386. /// 多选框组件
  387. Widget _buildCheckBox(FormObject currentFormObject) {
  388. List<Option> options = currentFormObject.options ?? [];
  389. List<dynamic> currentSelectedCheckBox =
  390. formValue[currentFormObject.key!] ?? [];
  391. dynamic disabledValue = currentFormObject.disabledValue;
  392. void selectCheckBoxChange(Option e) {
  393. if (currentSelectedCheckBox.contains(e.value)) {
  394. currentSelectedCheckBox.remove(e.value);
  395. } else {
  396. if (disabledValue == e.value) {
  397. currentSelectedCheckBox = [disabledValue];
  398. } else {
  399. if (currentSelectedCheckBox.contains(disabledValue)) {
  400. // PromptBox.toast('选项冲突');
  401. } else {
  402. currentSelectedCheckBox.add(e.value ?? '');
  403. }
  404. }
  405. }
  406. formValue[currentFormObject.key!] = currentSelectedCheckBox;
  407. setState(() {});
  408. }
  409. return ExamCheckBox(
  410. options: options,
  411. currentSelectedCheckBox: currentSelectedCheckBox,
  412. currentFormObject: currentFormObject,
  413. selectCheckBoxChange: selectCheckBoxChange,
  414. disbaleOthers: currentSelectedCheckBox.contains(disabledValue),
  415. );
  416. }
  417. ///中医药健康指导多选框组件
  418. Widget _buildHealthGuidanceCheckBox(FormObject currentFormObject) {
  419. List<Option> options = currentFormObject.options ?? [];
  420. List<dynamic> currentSelectedCheckBox =
  421. formValue[currentFormObject.key!] ?? [];
  422. // var templateFromObj = currentTemplate.firstWhere(
  423. // (element) => element.label!.contains());
  424. var currentScoreKey = currentFormObject.groupKeys != null
  425. ? currentFormObject.groupKeys![0]
  426. : '';
  427. int score = formValue[currentScoreKey] ?? 0;
  428. String judgmentResult = getJudgmentResult(currentScoreKey);
  429. void selectCheckBoxChange(Option e) {
  430. if (currentSelectedCheckBox.contains(e.value)) {
  431. currentSelectedCheckBox.remove(e.value);
  432. } else {
  433. currentSelectedCheckBox.add(e.value ?? '');
  434. }
  435. formValue[currentFormObject.key!] = currentSelectedCheckBox;
  436. setState(() {});
  437. }
  438. return ExamHealthGuidanceCheckBox(
  439. options: options,
  440. currentSelectedCheckBox: currentSelectedCheckBox,
  441. currentFormObject: currentFormObject,
  442. selectCheckBoxChange: selectCheckBoxChange,
  443. score: score,
  444. judgmentResult: judgmentResult,
  445. );
  446. }
  447. String getJudgmentResult(String storeKey) {
  448. var score = formValue[storeKey] ?? 0;
  449. if (storeKey == 'Ping_Score') {
  450. if (score >= 17) {
  451. bool is8 = true;
  452. bool is10 = true;
  453. for (var e in storeTypeList) {
  454. if (formValue[e] != null && e != 'Ping_Score') {
  455. var otherScore = formValue[e];
  456. if (otherScore > 8) {
  457. if (is8) {
  458. is8 = false;
  459. }
  460. if (otherScore > 10) {
  461. is10 = false;
  462. }
  463. }
  464. if (!is10) {
  465. break;
  466. }
  467. }
  468. }
  469. if (is8) {
  470. return '是';
  471. } else if (is10) {
  472. return '基本是';
  473. }
  474. }
  475. return '否';
  476. } else {
  477. if (score >= 11) {
  478. return '是';
  479. } else if (9 == score && score == 10) {
  480. return '倾向是';
  481. } else {
  482. return '否';
  483. }
  484. }
  485. }
  486. /// 数字输入框组件
  487. Widget _buildNumberInput(FormObject currentFormObject) {
  488. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  489. if ((formValue['Height']?.isNotEmpty ?? false) &&
  490. (formValue['Weight']?.isNotEmpty ?? false)) {
  491. formValue['Bmi'] = (double.parse(formValue['Weight']) /
  492. ((double.parse(formValue['Height']) / 100) *
  493. (double.parse(formValue['Height']) / 100)))
  494. .toStringAsFixed(2);
  495. }
  496. Future<void> commonInput() async {
  497. String? result = await VDialogNumber(
  498. title: currentFormObject.label,
  499. initialValue: formValue[currentFormObject.key],
  500. ).show();
  501. if (result?.isNotEmpty ?? false) {
  502. formValue[currentFormObject.key!] = result;
  503. currentInputValue = formValue[currentFormObject.key!];
  504. setState(() {});
  505. }
  506. }
  507. void specialInput(String value) {
  508. formValue[currentFormObject.key!] = value;
  509. currentInputValue = formValue[currentFormObject.key!];
  510. setState(() {});
  511. }
  512. return ExamNumberInput(
  513. currentInputValue: currentInputValue,
  514. commonInput: commonInput,
  515. specialInput: specialInput,
  516. currentFormObject: currentFormObject,
  517. );
  518. }
  519. Widget _buildInput(FormObject currentFormObject) {
  520. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  521. Future<void> commonInput() async {
  522. String? result = await VDialogInput(
  523. title: currentFormObject.label,
  524. initialValue: formValue[currentFormObject.key],
  525. ).show();
  526. if (result?.isNotEmpty ?? false) {
  527. formValue[currentFormObject.key!] = result;
  528. currentInputValue = formValue[currentFormObject.key!];
  529. setState(() {});
  530. }
  531. }
  532. return ExamInput(
  533. currentInputValue: currentInputValue,
  534. commonInput: commonInput,
  535. currentFormObject: currentFormObject,
  536. );
  537. }
  538. /// 血压组件
  539. Widget _buildBloodPressure(FormObject currentFormObject) {
  540. Map currentValue = formValue[currentFormObject.key!] ?? {};
  541. print(currentFormObject.key!);
  542. void bloodPressure(Map value) {
  543. currentValue = value;
  544. formValue[currentFormObject.key!] = currentValue;
  545. // setState(() {});
  546. }
  547. return ExamBloodPressure(
  548. currentValue: currentValue,
  549. bloodPressure: bloodPressure,
  550. );
  551. }
  552. Widget _buildUrinalysis(FormObject currentFormObject) {
  553. Map currentValue = formValue[currentFormObject.key!] ?? {};
  554. void urinalysis(Map value) {
  555. currentValue = value;
  556. formValue[currentFormObject.key!] = currentValue;
  557. setState(() {});
  558. }
  559. return ExamUrinalysis(
  560. currentValue: currentValue,
  561. urinalysis: urinalysis,
  562. );
  563. }
  564. /// 单选框组件
  565. Widget _buildRadio(FormObject currentFormObject) {
  566. List<Option> options = currentFormObject.options ?? [];
  567. String currentSelected = formValue[currentFormObject.key!] ?? "";
  568. void selectRaidoChange(Option e) {
  569. currentSelected = e.value ?? '';
  570. formValue[currentFormObject.key!] = currentSelected;
  571. if (widget.cardKey == 'LNRZYYJKGLFWJL') {
  572. var pingScore = [
  573. 'qusition1',
  574. 'qusition2',
  575. 'qusition4',
  576. 'qusition5',
  577. 'qusition13'
  578. ];
  579. var isPingScore = pingScore.contains(currentFormObject.key);
  580. formValue[currentFormObject.groupKeys?[0]] =
  581. calculatePhysicalFitnessScore(
  582. currentFormObject.groupKeys?[0], false);
  583. if (isPingScore) {
  584. formValue['Ping_Score'] =
  585. calculatePhysicalFitnessScore('Ping_Score', isPingScore);
  586. }
  587. }
  588. setState(() {});
  589. }
  590. return ExamRadio(
  591. options: options,
  592. currentFormObject: currentFormObject,
  593. selectRaidoChange: selectRaidoChange,
  594. currentSelected: currentSelected,
  595. );
  596. }
  597. int calculatePhysicalFitnessScore(String currentScoreKey, bool isPingScore) {
  598. int score = 0;
  599. var currentTemplateStoreList = currentTemplate[0].children?.where(
  600. (element) =>
  601. element.groupKeys != null &&
  602. element.groupKeys!.contains(currentScoreKey));
  603. if (!isPingScore) {
  604. for (var element in currentTemplateStoreList!) {
  605. if (formValue[element.key!] != null) {
  606. score += int.parse(formValue[element.key!]!);
  607. }
  608. }
  609. } else {
  610. int index = 0;
  611. for (var element in currentTemplateStoreList!) {
  612. if (index == 0) {
  613. if (formValue[element.key!] != null) {
  614. score += int.parse(formValue[element.key!]!);
  615. }
  616. } else {
  617. score += formValue[element.key!] != null
  618. ? (6 - int.parse(formValue[element.key!]!))
  619. : 0;
  620. }
  621. index++;
  622. }
  623. }
  624. return score;
  625. }
  626. Widget _buildRadioScore(FormObject currentFormObject) {
  627. List<Option> options = currentFormObject.options ?? [];
  628. String currentSelected =
  629. formValue[currentFormObject.childrenKey!.first] ?? "";
  630. String currentScore = formValue[currentFormObject.childrenKey!.last] ?? "";
  631. void selectRaidoChange(Option e) {
  632. currentSelected = e.value ?? '';
  633. formValue[currentFormObject.childrenKey!.first] = currentSelected;
  634. setState(() {});
  635. }
  636. void changeScore(String? score) {
  637. currentScore = score ?? '';
  638. formValue[currentFormObject.childrenKey!.last] = currentScore;
  639. setState(() {});
  640. }
  641. return ExamRadioScore(
  642. options: options,
  643. currentFormObject: currentFormObject,
  644. selectRaidoChange: selectRaidoChange,
  645. currentSelected: currentSelected,
  646. changeScore: changeScore,
  647. currentScore: currentScore,
  648. );
  649. }
  650. /// 体温组件
  651. Widget _buildBodyTemperature(FormObject currentFormObject) {
  652. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  653. void bodyTemperatureInput(String value) {
  654. formValue[currentFormObject.key!] = value;
  655. currentInputValue = formValue[currentFormObject.key!];
  656. setState(() {});
  657. }
  658. return ExamBodyTemperature(
  659. currentInputValue: currentInputValue,
  660. bodyTemperatureInput: bodyTemperatureInput,
  661. currentFormObject: currentFormObject,
  662. );
  663. }
  664. Widget _buildToxicSubstance(FormObject currentFormObject) {
  665. List<Option> options = currentFormObject.options ?? [];
  666. String currentValue = formValue[currentFormObject.childrenKey!.first] ?? "";
  667. Map? currentSelectedToxicSubstance =
  668. formValue[currentFormObject.childrenKey!.last];
  669. void selectRaidoChange(Map e) {
  670. currentSelectedToxicSubstance = e;
  671. formValue[currentFormObject.childrenKey!.last] =
  672. currentSelectedToxicSubstance;
  673. setState(() {});
  674. }
  675. void selectValueChange(String e) {
  676. currentValue = e;
  677. formValue[currentFormObject.childrenKey!.first] = currentValue;
  678. setState(() {});
  679. }
  680. return ExamToxicSubstance(
  681. currentFormObject: currentFormObject,
  682. currentSelectedToxicSubstance: currentSelectedToxicSubstance,
  683. currentValue: currentValue,
  684. options: options,
  685. selectRadioChange: selectRaidoChange,
  686. selectValueChange: selectValueChange,
  687. );
  688. }
  689. /// 血氧
  690. Widget _buildBloodOxygen(FormObject currentFormObject) {
  691. Map<String, dynamic> currentValue = formValue;
  692. void bloodOxygenInput(Map<String, dynamic> bloodOxygen) {
  693. formValue['Pulse_Frequency'] = bloodOxygen['Pulse_Frequency'];
  694. formValue['Spo2'] = bloodOxygen['Spo2'];
  695. currentValue = bloodOxygen;
  696. setState(() {});
  697. }
  698. return ExamBloodOxygen(
  699. currentValue: currentValue,
  700. bloodOxygenInput: bloodOxygenInput,
  701. );
  702. }
  703. /// 住院史
  704. Widget _buildMedicalHistory(FormObject currentFormObject) {
  705. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  706. int currentId = currentValue.length + 1;
  707. void resultChange(Map result) {
  708. currentValue.add(result);
  709. formValue[currentFormObject.key!] = currentValue;
  710. setState(() {});
  711. }
  712. void editResult(EditTableValue result) {
  713. currentValue[result.id! - 1] = result.value;
  714. formValue[currentFormObject.key!] = currentValue;
  715. setState(() {});
  716. }
  717. Future<void> addTableData() async {
  718. Get.dialog(
  719. HospitalizationHistoryForm(
  720. fromResult: (result) => resultChange(result),
  721. currentId: currentId,
  722. ),
  723. );
  724. }
  725. Future<void> editTableData(EditTableValue editTableValue) async {
  726. Get.dialog(
  727. HospitalizationHistoryForm(
  728. fromResult: (result) => editResult(result),
  729. currentId: editTableValue.id!,
  730. admissionJson: editTableValue.value,
  731. ),
  732. );
  733. }
  734. return ExamTable(
  735. tableThList: const ['序号', '入院日期', '出院日期', '原因', '医疗机构名称', '病案号', '操作'],
  736. currentFormObject: currentFormObject,
  737. currentValue: currentValue,
  738. addTableData: addTableData,
  739. editTableData: (value) => editTableData(value),
  740. );
  741. }
  742. /// 家庭病床史
  743. Widget _buildHomecareBedHistory(FormObject currentFormObject) {
  744. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  745. int currentId = currentValue.length + 1;
  746. void resultChange(Map result) {
  747. for (var i in result.keys) {
  748. if (result[i] == "") {
  749. return;
  750. }
  751. }
  752. currentValue.add(result);
  753. formValue[currentFormObject.key!] = currentValue;
  754. setState(() {});
  755. }
  756. void editResult(EditTableValue result) {
  757. currentValue[result.id! - 1] = result.value;
  758. formValue[currentFormObject.key!] = currentValue;
  759. setState(() {});
  760. }
  761. Future<void> addTableData() async {
  762. Get.dialog(
  763. HomecareBedHistoryFrom(
  764. fromResult: (result) => resultChange(result),
  765. currentId: currentId,
  766. ),
  767. );
  768. }
  769. Future<void> editTableData(EditTableValue editTableValue) async {
  770. Get.dialog(
  771. HomecareBedHistoryFrom(
  772. fromResult: (result) => editResult(result),
  773. currentId: editTableValue.id!,
  774. admissionJson: editTableValue.value,
  775. ),
  776. );
  777. }
  778. return ExamTable(
  779. tableThList: const ['序号', '建床日期', '撤床日期', '原因', '医疗机构名称', '病案号', '操作'],
  780. currentFormObject: currentFormObject,
  781. currentValue: currentValue,
  782. addTableData: addTableData,
  783. editTableData: (value) => editTableData(value),
  784. );
  785. }
  786. Widget _buildMainMedicationHistory(FormObject currentFormObject) {
  787. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  788. int currentId = currentValue.length + 1;
  789. void resultChange(Map result) {
  790. currentValue.add(result);
  791. formValue[currentFormObject.key!] = currentValue;
  792. setState(() {});
  793. }
  794. void editResult(EditTableValue result) {
  795. currentValue[result.id! - 1] = result.value;
  796. formValue[currentFormObject.key!] = currentValue;
  797. setState(() {});
  798. }
  799. Future<void> addTableData() async {
  800. Get.dialog(
  801. MainMedicationStatusFrom(
  802. fromResult: (result) => resultChange(result),
  803. currentId: currentId,
  804. ),
  805. );
  806. }
  807. Future<void> editTableData(EditTableValue editTableValue) async {
  808. Get.dialog(
  809. MainMedicationStatusFrom(
  810. fromResult: (result) => editResult(result),
  811. currentId: editTableValue.id!,
  812. admissionJson: editTableValue.value,
  813. ),
  814. );
  815. }
  816. return ExamTable(
  817. tableThList: const ['序号', '药物名称', '用法', '用量', '用药时间', '服药依从性', '操作'],
  818. currentFormObject: currentFormObject,
  819. currentValue: currentValue,
  820. addTableData: addTableData,
  821. editTableData: (value) => editTableData(value),
  822. );
  823. }
  824. Widget _buildInoculateHistory(FormObject currentFormObject) {
  825. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  826. int currentId = currentValue.length + 1;
  827. void resultChange(Map result) {
  828. currentValue.add(result);
  829. formValue[currentFormObject.key!] = currentValue;
  830. setState(() {});
  831. }
  832. void editResult(EditTableValue result) {
  833. currentValue[result.id! - 1] = result.value;
  834. formValue[currentFormObject.key!] = currentValue;
  835. setState(() {});
  836. }
  837. Future<void> addTableData() async {
  838. Get.dialog(
  839. InoculateHistoryFrom(
  840. fromResult: (result) => resultChange(result),
  841. currentId: currentId,
  842. ),
  843. );
  844. }
  845. Future<void> editTableData(EditTableValue editTableValue) async {
  846. Get.dialog(
  847. InoculateHistoryFrom(
  848. fromResult: (result) => editResult(result),
  849. currentId: editTableValue.id!,
  850. admissionJson: editTableValue.value,
  851. ),
  852. );
  853. }
  854. return ExamTable(
  855. tableThList: const ['序号', '疫苗名称', '接种日期', '接种机构', '操作'],
  856. currentFormObject: currentFormObject,
  857. currentValue: currentValue,
  858. addTableData: addTableData,
  859. editTableData: (value) => editTableData(value),
  860. );
  861. }
  862. /// 体重
  863. Widget _buildBodyWeight(FormObject currentFormObject) {
  864. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  865. void bodyWeightInput(String value) {
  866. formValue[currentFormObject.key!] = value;
  867. currentInputValue = formValue[currentFormObject.key!];
  868. setState(() {});
  869. }
  870. return ExamBodyWeight(
  871. currentInputValue: currentInputValue,
  872. bodyWeightInput: bodyWeightInput,
  873. currentFormObject: currentFormObject,
  874. );
  875. }
  876. /// 血糖
  877. Widget _buildBodySugar(FormObject currentFormObject) {
  878. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  879. void bloodSugarInput(String value) {
  880. formValue[currentFormObject.key!] = value;
  881. currentInputValue = formValue[currentFormObject.key!];
  882. setState(() {});
  883. }
  884. return ExamBloodSugar(
  885. currentInputValue: currentInputValue,
  886. bloodSugarInput: bloodSugarInput,
  887. currentFormObject: currentFormObject,
  888. );
  889. }
  890. }