new_configurable_card.dart 30 KB

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