configurable_card.dart 34 KB

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