new_configurable_card.dart 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  1. import 'dart:convert';
  2. import 'package:fis_common/event/event_type.dart';
  3. import 'package:fis_common/index.dart';
  4. import 'package:fis_common/logger/logger.dart';
  5. import 'package:fis_jsonrpc/rpc.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter/services.dart';
  8. import 'package:get/get.dart';
  9. import 'package:intl/intl.dart';
  10. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  11. import 'package:vitalapp/components/appbar.dart';
  12. import 'package:vitalapp/components/button.dart';
  13. import 'package:vitalapp/components/dialog_date.dart';
  14. import 'package:vitalapp/components/dialog_input.dart';
  15. import 'package:vitalapp/components/dialog_number.dart';
  16. import 'package:vitalapp/components/dynamic_drawer.dart';
  17. import 'package:vitalapp/managers/interfaces/cachedRecord.dart';
  18. import 'package:vitalapp/managers/interfaces/patient.dart';
  19. import 'package:vitalapp/managers/interfaces/registration.dart';
  20. import 'package:vitalapp/managers/interfaces/template.dart';
  21. import 'package:vitalapp/pages/check/models/form.dart';
  22. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_ability_radio.dart';
  23. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_abnormal.dart';
  24. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_blood_pressure.dart';
  25. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_blood_sugar.dart';
  26. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_body_temperature.dart';
  27. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_body_weight.dart';
  28. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_boold_oxygen.dart';
  29. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_check_box.dart';
  30. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_check_guidance.dart';
  31. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_checkbox_frequency.dart';
  32. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_dentition.dart';
  33. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_input.dart';
  34. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_number_input.dart';
  35. import 'dart:math' as math;
  36. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_radio.dart';
  37. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_radio_score.dart';
  38. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_risk_factor_control.dart';
  39. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_table.dart';
  40. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_toxic_substance.dart';
  41. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_urinalys.dart';
  42. import 'package:vitalapp/pages/check/widgets/exam_table/homecare_bed_history_from.dart';
  43. import 'package:vitalapp/pages/check/widgets/exam_table/hospitalization_history_from.dart';
  44. import 'package:vitalapp/pages/check/widgets/exam_table/inoculate_history_from.dart';
  45. import 'package:vitalapp/pages/check/widgets/exam_table/main_medication_status_from.dart';
  46. import 'package:vitalapp/pages/medical/controller.dart';
  47. import 'package:vitalapp/store/store.dart';
  48. class NewConfigurableCard extends StatefulWidget {
  49. final String cardKey;
  50. final Future<bool> Function(String, String, dynamic, bool) callBack;
  51. final Widget? followUpWidget;
  52. final String? patientCode;
  53. final String? examData;
  54. final FEventHandler<bool>? onChangeCurrentKeyEvent;
  55. final FEventHandler<bool>? onSubmitEvent;
  56. final String physicalExamNumber;
  57. final bool? isAllSelectZQCT;
  58. final Function(bool)? onAllSelectZQCTChange;
  59. const NewConfigurableCard({
  60. super.key,
  61. required this.cardKey,
  62. required this.callBack,
  63. required this.physicalExamNumber,
  64. this.followUpWidget,
  65. this.patientCode,
  66. this.examData,
  67. this.onSubmitEvent,
  68. this.isAllSelectZQCT,
  69. this.onChangeCurrentKeyEvent,
  70. this.onAllSelectZQCTChange,
  71. });
  72. @override
  73. State<NewConfigurableCard> createState() => NewConfigurableFormState();
  74. }
  75. class NewConfigurableFormState extends State<NewConfigurableCard> {
  76. /// 当前最新的模板的键值对
  77. Map<String, dynamic> templateRelation = {};
  78. String templateCode = '';
  79. /// 当前模板数据
  80. List<FormObject> currentTemplate = [];
  81. /// 当前title的下标
  82. // int currentTitleIndex = 0;
  83. Map<String, dynamic> formValue = {};
  84. var scaffoldKey = GlobalKey<ScaffoldState>();
  85. final _templateManager = Get.find<ITemplateManager>();
  86. final _cachedRecordManager = Get.find<ICachedRecordManager>();
  87. final arrowHeight = math.tan(120 / 180) * 19;
  88. List<String> deviceList = [
  89. 'Temp',
  90. 'GLU',
  91. 'NIBP',
  92. 'SpO2',
  93. 'BMI',
  94. "Urinary_Pro",
  95. ];
  96. Map<String, dynamic> deviceCached = {};
  97. Map currentTable = {};
  98. ScrollController _examScrollController = ScrollController();
  99. ExamDTO? _currentExam;
  100. bool _isAllSelectZQCT = false;
  101. @override
  102. void initState() {
  103. print("formValue:$formValue");
  104. _isAllSelectZQCT = widget.isAllSelectZQCT ?? false;
  105. initAddListener();
  106. super.initState();
  107. WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
  108. if (mounted) {
  109. initTemplate();
  110. }
  111. });
  112. widget.onSubmitEvent?.addListener(submitEvent);
  113. _examScrollController.addListener(_scrollListener);
  114. }
  115. @override
  116. void dispose() {
  117. super.dispose();
  118. widget.onSubmitEvent?.removeListener(submitEvent);
  119. _examScrollController.removeListener(_scrollListener);
  120. _examScrollController.dispose();
  121. }
  122. void submitEvent(sender, e) {
  123. if (mounted) {
  124. if (formValue.isNotEmpty) {
  125. submit(e);
  126. }
  127. }
  128. }
  129. /// 是否有健康检测的页面权限
  130. bool _hasHealthMonitor() {
  131. bool hasAuth = false;
  132. Store.user.menuPermissionList?.forEach((element) {
  133. if (element.code == "JKJC") {
  134. hasAuth = true;
  135. }
  136. });
  137. return hasAuth;
  138. }
  139. /// 判断是否有健康检测的页面
  140. void initAddListener() {
  141. if (_hasHealthMonitor()) {
  142. var medicalController = Get.find<MedicalController>();
  143. medicalController.setExamData.addListener(onSetExamDataEvent);
  144. }
  145. }
  146. void onSetExamDataEvent(sender, Map<String, dynamic> e) {
  147. try {
  148. Map<String, dynamic> examData = {};
  149. Map<String, dynamic> blood = {
  150. "BloodPressure": {
  151. "left": "",
  152. "right": "",
  153. }
  154. };
  155. e.forEach((key, value) {
  156. if (value is Map && value.isEmpty) {
  157. return;
  158. }
  159. if (key != "Urine") {
  160. /// 血压处理
  161. if (value["Sbp_Left"] != null && value["Dbp_Left"] != null) {
  162. blood["BloodPressure"]["left"] =
  163. jsonEncode([value["Sbp_Left"], value["Dbp_Left"]]);
  164. }
  165. if (value["Sbp_Right"] != null && value["Dbp_Right"] != null) {
  166. blood["BloodPressure"]["right"] =
  167. jsonEncode([value["Sbp_Right"], value["Dbp_Right"]]);
  168. }
  169. if (blood["BloodPressure"]["left"] != null ||
  170. blood["BloodPressure"]["right"] != null) {
  171. examData.addAll(blood);
  172. }
  173. examData.addAll(Map<String, dynamic>.from(value));
  174. } else {
  175. examData.addAll({"Urinary_Pro": value});
  176. }
  177. });
  178. Map<String, dynamic> newMap = Map.from(examData);
  179. if (examData["sugar"]?.isNotEmpty ?? false) {
  180. newMap.remove("sugar");
  181. // 将"sugar"的值作为"Fasting_Glucose_Mmol"键的值添加到新的Map中
  182. newMap["Fasting_Glucose_Mmol"] = examData["sugar"] ?? '';
  183. }
  184. formValue.addAll(newMap);
  185. submitExamData();
  186. ///MedicalController => submitDiagnosis =》 initRecordDataState =》deleteDirectory
  187. if (mounted) {
  188. setState(() {});
  189. }
  190. } catch (err) {
  191. logger.e("健康检测数据回填错误:$err");
  192. }
  193. }
  194. Future<void> submitExamData() async {
  195. Map<String, dynamic> normalItems = {};
  196. Map<String, dynamic> urinaryItems = {};
  197. Map<String, dynamic> organsItems = {};
  198. formValue.forEach((key, value) {
  199. if (key == "Urinary_Pro" || key == "Fasting_Glucose_Mmol") {
  200. urinaryItems[key] = value;
  201. } else if (key == "HEART") {
  202. organsItems[key] = value;
  203. } else {
  204. normalItems[key] = value;
  205. }
  206. });
  207. if (urinaryItems.isNotEmpty) {
  208. await widget.callBack(
  209. //辅助检查
  210. "FZJC",
  211. templateCode,
  212. jsonEncode(urinaryItems),
  213. false,
  214. );
  215. }
  216. if (normalItems.isNotEmpty) {
  217. await widget.callBack(
  218. //一般状况
  219. "ZZYBZK",
  220. templateCode,
  221. jsonEncode(normalItems),
  222. false,
  223. );
  224. }
  225. if (organsItems.isNotEmpty) {
  226. await widget.callBack(
  227. //脏器及查体
  228. "ZQCT",
  229. templateCode,
  230. jsonEncode(organsItems),
  231. false,
  232. );
  233. }
  234. }
  235. Future<void> submit(bool isManual) async {
  236. await widget.callBack(
  237. widget.cardKey,
  238. templateCode,
  239. jsonEncode(formValue),
  240. isManual,
  241. );
  242. }
  243. Future<void> initTemplate() async {
  244. try {
  245. Store.app.busy = true;
  246. await fetchTemplateIndex();
  247. await fetchTemplate(widget.cardKey);
  248. await fetchTemplateData();
  249. if (widget.cardKey == "ZQCT") {
  250. var isAllSelectZQCT = CalculatesWhetherTheSelectAllButtonIsSelected();
  251. _isAllSelectZQCT = isAllSelectZQCT;
  252. if (widget.onAllSelectZQCTChange != null) {
  253. widget.onAllSelectZQCTChange!(isAllSelectZQCT);
  254. }
  255. }
  256. Store.app.busy = false;
  257. setState(() {});
  258. } catch (e) {
  259. Store.app.busy = false;
  260. print(e.toString());
  261. logger.e("模版错误:" + e.toString());
  262. }
  263. }
  264. /// 读取健康检测的缓存
  265. Future<String?> readCachedRecord(String currentDevice) async {
  266. if (widget.patientCode == null) {
  267. return null;
  268. }
  269. String? value = await _cachedRecordManager.readCachedRecord(
  270. currentDevice,
  271. widget.patientCode!,
  272. //诊疗展示
  273. 'ZLZS',
  274. );
  275. return value;
  276. }
  277. /// 读取体检的缓存
  278. Future<String?> readCachedCheck() async {
  279. if (widget.patientCode == null) {
  280. return null;
  281. }
  282. String? value = await _cachedRecordManager.readCachedRecord(
  283. widget.cardKey,
  284. widget.patientCode!,
  285. 'exam',
  286. );
  287. return value;
  288. }
  289. Future<void> readCached() async {
  290. for (var element in deviceList) {
  291. String? value = await readCachedRecord(element);
  292. if (value?.isNotEmpty ?? false) {
  293. deviceCached.addAll(jsonDecode(value!));
  294. }
  295. }
  296. }
  297. Future<void> fetchTemplateIndex() async {
  298. try {
  299. /// 获取模板的键值对
  300. String? templates;
  301. templates = await _templateManager.readTemplateRelation(
  302. 'templateRelation',
  303. );
  304. templateRelation = jsonDecode(templates!);
  305. } catch (error) {
  306. print('发生错误: $error');
  307. logger.e("发生错误" + error.toString());
  308. }
  309. }
  310. Future<void> setExamData() async {
  311. if (widget.physicalExamNumber.isNotEmpty) {
  312. List<ExamDTO>? examList = await Get.find<IRegistrationManager>()
  313. .getExamListByPhysicalExamNumberAsync(
  314. physicalExamNumber: widget.physicalExamNumber,
  315. );
  316. ExamDTO? currentExam = examList?.firstWhereOrNull(
  317. (element) => element.key == widget.cardKey,
  318. );
  319. _currentExam = currentExam;
  320. } else if (widget.cardKey == "YZJSZABCXX") {
  321. PatientExtensionDTO? patientExtensionDTO =
  322. await Get.find<IPatientManager>()
  323. .getPatientExtensionDetailByCodeAndKey(
  324. widget.cardKey,
  325. widget.patientCode ?? '',
  326. );
  327. if (patientExtensionDTO != null) {
  328. String extensionData = patientExtensionDTO.extensionData ?? '';
  329. _currentExam = ExamDTO(
  330. code: patientExtensionDTO.code,
  331. patientCode: patientExtensionDTO.patientCode,
  332. examData: extensionData,
  333. key: patientExtensionDTO.key,
  334. );
  335. }
  336. }
  337. }
  338. Future<void> fetchTemplateData() async {
  339. await setExamData();
  340. if (_currentExam?.examData != null) {
  341. formValue = jsonDecode(_currentExam?.examData ?? '');
  342. } else if (widget.examData != null) {
  343. formValue = jsonDecode(widget.examData ?? '');
  344. } else {
  345. return;
  346. }
  347. formValue.forEach(
  348. (key, value) {
  349. if (value is List<String>) {
  350. formValue[key] = List<String>.from(formValue[key]);
  351. } else if (value is List<Map>) {
  352. formValue[key] = List<Map>.from(formValue[key]);
  353. }
  354. },
  355. );
  356. }
  357. Future<String> loadJsonFromAssets(String filePath) async {
  358. String jsonString = await rootBundle.loadString(filePath);
  359. return jsonString;
  360. }
  361. Future<void> fetchTemplate(String key) async {
  362. try {
  363. // String? templateContent = "";
  364. // String? template = "";
  365. // if (key == "YZJSZABCXX") {
  366. // templateContent =
  367. // await loadJsonFromAssets('assets/严重精神障碍患者个人信息补充表.json');
  368. // }
  369. // if (templateRelation[key] == null && templateContent.isNullOrEmpty) {
  370. if (templateRelation[key] == null) {
  371. logger.i(
  372. "ConfigurableCard - fetchTemplate Template not exist key: $key.");
  373. currentTemplate = [];
  374. setState(() {});
  375. if (!FPlatform.isWindows) {
  376. return;
  377. }
  378. }
  379. // if (templateContent.isNullOrEmpty)
  380. // template = await _templateManager.readTemplate(templateRelation[key]!);
  381. // if (templateContent.isNullOrEmpty)
  382. // templateContent =
  383. String? template;
  384. if (templateRelation.containsKey(key)) {
  385. templateCode = templateRelation[key]!;
  386. template = await _templateManager.readTemplate(templateCode);
  387. }
  388. List<Map<String, dynamic>> list = [];
  389. if (template == null) {
  390. var json = await loadJsonFromAssets('assets/templates/${key}.json');
  391. list = jsonDecode(json)["Content"].cast<Map<String, dynamic>>();
  392. } else {
  393. var templateContent =
  394. TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
  395. list = jsonDecode(templateContent).cast<Map<String, dynamic>>();
  396. }
  397. for (var i in list) {
  398. if (i['children'] != null) {
  399. List<FormObject> currentChildren = [];
  400. for (var j in i['children']) {
  401. currentChildren.add(FormObject.fromJson(j));
  402. }
  403. i['children'] = currentChildren;
  404. }
  405. var item = FormObject.fromJson(i);
  406. currentTemplate.add(item);
  407. }
  408. } catch (error) {
  409. print('发生错误: $error');
  410. logger.e("发生错误: fetchTemplate" + error.toString());
  411. }
  412. }
  413. @override
  414. Widget build(BuildContext context) {
  415. return Scaffold(
  416. key: scaffoldKey,
  417. appBar: widget.cardKey == "YZJSZABCXX"
  418. ? VAppBar(
  419. titleText: "精神障碍患者补充表",
  420. actions: [
  421. TextButton(
  422. onPressed: () {
  423. widget.callBack(
  424. widget.cardKey,
  425. templateRelation[widget.cardKey]!,
  426. jsonEncode(formValue),
  427. false,
  428. );
  429. },
  430. child: Text(
  431. "保存",
  432. style: TextStyle(fontSize: 24, color: Colors.white),
  433. ),
  434. ),
  435. ],
  436. )
  437. : null,
  438. endDrawer: VDynamicDrawerWrapper(scaffoldKey: scaffoldKey),
  439. resizeToAvoidBottomInset: false,
  440. body: Column(
  441. children: [
  442. Expanded(
  443. child: Stack(
  444. children: [
  445. Row(
  446. mainAxisAlignment: MainAxisAlignment.start,
  447. crossAxisAlignment: CrossAxisAlignment.start,
  448. children: [
  449. // _buildDiagram(),
  450. _buildContent(),
  451. ],
  452. ),
  453. if (widget.cardKey == "ZQCT")
  454. Positioned(
  455. right: 30,
  456. bottom: 20,
  457. child: Container(
  458. width: 150,
  459. height: 50,
  460. child: Row(
  461. children: [
  462. Switch(
  463. activeTrackColor: Colors.blueAccent,
  464. value: _isAllSelectZQCT,
  465. onChanged: (value) {
  466. _isAllSelectZQCT = !_isAllSelectZQCT;
  467. widget.onAllSelectZQCTChange!(value);
  468. for (var element in currentTemplate) {
  469. for (var child in element.children!) {
  470. if ([
  471. "Vision_Left",
  472. "Vision_Right",
  473. "Vision_Corrective_Left",
  474. "Vision_Corrective_Right",
  475. "Heart_Rate",
  476. "Examination_Other",
  477. "Pedal_Artery",
  478. "Rectal_Touch",
  479. "Mammary",
  480. "Vulvar",
  481. "Vagina",
  482. "Cervical",
  483. "Uteri_Body",
  484. "Uteri_Adnexa",
  485. "Eye_Ground"
  486. ].contains(child.key)) {
  487. continue;
  488. }
  489. if (_isAllSelectZQCT) {
  490. if (child.key == "Dentition") {
  491. formValue[child.key!] = {
  492. 'status': [0],
  493. 'detail_a': [],
  494. 'detail_b': [],
  495. 'detail_c': [],
  496. };
  497. } else if (child.type == "checkbox") {
  498. formValue[child.key!] = ["1"];
  499. } else {
  500. formValue[child.key!] = "1";
  501. }
  502. } else {
  503. formValue.remove(child.key);
  504. }
  505. }
  506. }
  507. setState(() {});
  508. }),
  509. Text(
  510. '全选正常',
  511. style: TextStyle(fontSize: 18),
  512. ),
  513. ],
  514. ),
  515. ),
  516. ),
  517. ],
  518. ),
  519. )
  520. ],
  521. ),
  522. );
  523. }
  524. bool CalculatesWhetherTheSelectAllButtonIsSelected() {
  525. bool isAllSelect = true;
  526. for (var element in currentTemplate) {
  527. for (var child in element.children!) {
  528. if ([
  529. "Vision_Left",
  530. "Vision_Right",
  531. "Vision_Corrective_Left",
  532. "Vision_Corrective_Right",
  533. "Heart_Rate",
  534. "Examination_Other",
  535. "Pedal_Artery",
  536. "Rectal_Touch",
  537. "Mammary",
  538. "Vulvar",
  539. "Vagina",
  540. "Cervical",
  541. "Uteri_Body",
  542. "Uteri_Adnexa",
  543. "Eye_Ground"
  544. ].contains(child.key)) {
  545. continue;
  546. }
  547. if (child.key == "Dentition") {
  548. dynamic dentitionValue = formValue[child.key!] ?? {};
  549. Map currentValue = {};
  550. if (!(dentitionValue is Map)) {
  551. currentValue = {};
  552. isAllSelect = false;
  553. } else {
  554. currentValue = dentitionValue;
  555. }
  556. if (currentValue["status"][0] != 0) {
  557. isAllSelect = false;
  558. }
  559. } else {
  560. var currentValue = formValue[child.key!];
  561. if (currentValue == null) {
  562. isAllSelect = false;
  563. } else {
  564. if (currentValue != "1") {
  565. isAllSelect = false;
  566. }
  567. }
  568. }
  569. if (!isAllSelect) {
  570. break;
  571. }
  572. }
  573. }
  574. return isAllSelect;
  575. }
  576. Widget buildSingleItem(Widget item, int span) {
  577. return FractionallySizedBox(
  578. widthFactor: span == 24 ? 1 : 0.5,
  579. child: item,
  580. );
  581. }
  582. Widget buildWidget(FormObject? currentFormObject) {
  583. Map<String, Widget Function(FormObject)> widgetMap = {
  584. 'checkbox': _buildCheckBox,
  585. 'numberInput': _buildNumberInput,
  586. 'input': _buildInput,
  587. 'radio': _buildRadio,
  588. 'radioScore': _buildRadioScore,
  589. 'bloodPressure': _buildBloodPressure,
  590. 'bodyTemperature': _buildBodyTemperature,
  591. 'weight': _buildBodyWeight,
  592. 'sugar': _buildBodySugar,
  593. 'bloodOxygen': _buildBloodOxygen,
  594. 'medicalHistory': _buildMedicalHistory,
  595. 'homecareBedHistor': _buildHomecareBedHistory,
  596. 'table': _buildMainMedicationHistory,
  597. 'inoculateHistory': _buildInoculateHistory,
  598. 'safetyPrecautions': _buildToxicSubstance,
  599. 'urinalys': _buildUrinalysis,
  600. "dentition": _buildDentition,
  601. "abnormal": _buildAbnormal,
  602. "riskFactorControl": _buildRiskFactorControl,
  603. 'ability_radio': _buildAbilityRadio,
  604. 'checkBoxFrequency': _buildCheckBoxFrequency,
  605. 'checkBoxIncludeOther': _buildCheckBoxIncludeOther,
  606. // 'inputHospitalizationTimes': _buildInputHospitalizationTimes,
  607. 'radioExtraDescription': _buildRadioExtraDescription,
  608. 'inputDiagnose': _buildInputDiagnose,
  609. 'radioInformedConsent': _buildRadioInformedConsent,
  610. 'date': _buildDate,
  611. 'checkbox_guidance': _buildGuidance,
  612. 'radioPreviousTreatment': _buildRadioPreviousTreatment,
  613. };
  614. Widget Function(FormObject) builder =
  615. widgetMap[currentFormObject?.type] ?? _buildInput;
  616. return builder(currentFormObject!);
  617. }
  618. Widget flowCardList() {
  619. int itemCount = 0;
  620. List<Widget> _cardList = [];
  621. bool currentTemplateOptionsIsNotEmpty = false;
  622. if (currentTemplate.isNotEmpty) {
  623. for (int i = 0; i < currentTemplate.length; i++) {
  624. itemCount = currentTemplate[i].children?.length ?? 0;
  625. currentTemplateOptionsIsNotEmpty =
  626. currentTemplate[i].options?.isNotEmpty ?? false;
  627. List<Widget> items = List.generate(itemCount, (index) {
  628. FormObject? currentFormObject = currentTemplate[i].children?[index];
  629. int span = currentFormObject?.span ?? 12;
  630. //父结构的options不等于空或null
  631. if (true) {
  632. //子结构的options若是无值则取父类的options值
  633. if (currentTemplateOptionsIsNotEmpty) {
  634. currentFormObject!.options = currentTemplate[i].options;
  635. }
  636. }
  637. return buildSingleItem(buildWidget(currentFormObject), span);
  638. });
  639. _cardList.addAll(items);
  640. }
  641. }
  642. return Scrollbar(
  643. thumbVisibility: true,
  644. controller: _examScrollController,
  645. child: SingleChildScrollView(
  646. controller: _examScrollController,
  647. child: Container(
  648. alignment: Alignment.topCenter,
  649. padding: const EdgeInsets.all(15),
  650. child: Wrap(
  651. runSpacing: 20, // 纵向元素间距
  652. alignment: WrapAlignment.start,
  653. children: _cardList,
  654. ),
  655. ),
  656. ),
  657. );
  658. }
  659. void _scrollListener() {
  660. if (mounted) {
  661. if (_examScrollController.position.pixels ==
  662. _examScrollController.position.maxScrollExtent) {
  663. // 滚动到底部
  664. _onScrollEnd();
  665. }
  666. }
  667. }
  668. void _onScrollEnd() {
  669. // 在这里触发您想要执行的方法
  670. print('Scroll to the bottom!');
  671. // widget.onChangeCurrentKeyEvent?.emit(this, true);
  672. }
  673. /// 主页面
  674. Widget _buildContent() {
  675. return Expanded(
  676. flex: 2,
  677. child: flowCardList(),
  678. );
  679. }
  680. /// 指导模块
  681. Widget _buildGuidance(FormObject currentFormObject) {
  682. List<Option> options = currentFormObject.options ?? [];
  683. List<dynamic> prescriptionList = formValue["PrescriptionList"] ?? [];
  684. List<dynamic> currentSelectedCheckBox = [];
  685. if (formValue[currentFormObject.key!] is List) {
  686. currentSelectedCheckBox = formValue[currentFormObject.key!] ?? [];
  687. }
  688. dynamic disabledValue = currentFormObject.disabledValue;
  689. List exclusiveValue = currentFormObject.exclusiveValue ?? [];
  690. void selectCheckBoxChange(Option e) {
  691. // 互斥项预处理
  692. if (exclusiveValue.isNotEmpty && exclusiveValue.contains(e.value)) {
  693. currentSelectedCheckBox.removeWhere((element) =>
  694. exclusiveValue.contains(element) && element != e.value);
  695. }
  696. if (currentSelectedCheckBox.contains(e.value)) {
  697. currentSelectedCheckBox.remove(e.value);
  698. } else {
  699. if (disabledValue == e.value) {
  700. currentSelectedCheckBox = [disabledValue];
  701. } else {
  702. if (currentSelectedCheckBox.contains(disabledValue)) {
  703. // PromptBox.toast('选项冲突');
  704. } else {
  705. // 最大可选处理
  706. if (currentFormObject.maxItems != null &&
  707. currentSelectedCheckBox.length >= currentFormObject.maxItems!) {
  708. PromptBox.toast('最多选择${currentFormObject.maxItems}项');
  709. return;
  710. }
  711. currentSelectedCheckBox.add(e.value ?? '');
  712. }
  713. }
  714. }
  715. formValue[currentFormObject.key!] = currentSelectedCheckBox;
  716. setState(() {});
  717. }
  718. createPrescription(Map prescription) {
  719. prescriptionList.add(prescription);
  720. formValue["PrescriptionList"] = prescriptionList;
  721. setState(() {});
  722. }
  723. removePrescription(Map prescription) {
  724. prescriptionList.remove(prescription);
  725. formValue["PrescriptionList"] = prescriptionList;
  726. setState(() {});
  727. }
  728. // void deletePrescription(int index) {
  729. // prescriptionList.removeAt(index);
  730. // formValue["PrescriptionList"] = prescriptionList;
  731. // setState(() {});
  732. // }
  733. return ExamCheckBoxGuidance(
  734. options: options,
  735. currentSelectedCheckBox: currentSelectedCheckBox,
  736. currentFormObject: currentFormObject,
  737. selectCheckBoxChange: selectCheckBoxChange,
  738. disbaleOthers: currentSelectedCheckBox.contains(disabledValue),
  739. physicalExamNumber: widget.physicalExamNumber,
  740. patientCode: widget.patientCode!,
  741. createPrescription: createPrescription,
  742. removePrescription: removePrescription,
  743. prescriptionList: prescriptionList,
  744. );
  745. }
  746. Widget _buildRadioPreviousTreatment(FormObject currentFormObject) {
  747. DateFormat format = DateFormat('yyyy-MM-dd');
  748. String currentSelected = formValue[currentFormObject.key!] ?? '';
  749. String firstAntipsyTreatDate =
  750. formValue[currentFormObject.childrenKey!.first] ?? '';
  751. String pastPsyInpatTimes =
  752. formValue[currentFormObject.childrenKey!.last] ?? '';
  753. Future<void> commonInput() async {
  754. String? result = await VDialogNumber(
  755. title: "曾住精神专科医院/综合医院精神专科次数",
  756. initialValue: pastPsyInpatTimes,
  757. ).show();
  758. if (result?.isNotEmpty ?? false) {
  759. formValue[currentFormObject.childrenKey!.last] = result;
  760. pastPsyInpatTimes = formValue[currentFormObject.childrenKey!.last];
  761. setState(() {});
  762. }
  763. }
  764. void selectRaidoChange(Option e) {
  765. if (currentSelected == e.value) {
  766. currentSelected = '';
  767. } else {
  768. currentSelected = e.value ?? '';
  769. }
  770. formValue[currentFormObject.key!] = currentSelected;
  771. setState(() {});
  772. }
  773. Future<void> commonInputDate() async {
  774. DateTime? result = await VDialogDate(
  775. title: "首次抗精神病药治疗时间",
  776. initialValue: firstAntipsyTreatDate.isNotNullOrEmpty
  777. ? format.parse(firstAntipsyTreatDate)
  778. : DateTime.now(),
  779. ).show();
  780. if (result != null) {
  781. firstAntipsyTreatDate = DateFormat("yyyy-MM-dd").format(result);
  782. formValue[currentFormObject.childrenKey!.first] = firstAntipsyTreatDate;
  783. setState(() {});
  784. }
  785. }
  786. return ExamRadioPreviousTreatment(
  787. currentSelected: currentSelected,
  788. options: currentFormObject.options!,
  789. commonInput: commonInput,
  790. commonInputDate: commonInputDate,
  791. selectRaidoChange: selectRaidoChange,
  792. firstAntipsyTreatDate: firstAntipsyTreatDate,
  793. pastPsyInpatTimes: pastPsyInpatTimes,
  794. currentFormObject: currentFormObject,
  795. );
  796. }
  797. /// 多选框组件
  798. Widget _buildCheckBox(FormObject currentFormObject) {
  799. List<Option> options = currentFormObject.options ?? [];
  800. List<dynamic> currentSelectedCheckBox = [];
  801. if (formValue[currentFormObject.key!] is List) {
  802. currentSelectedCheckBox = formValue[currentFormObject.key!] ?? [];
  803. }
  804. dynamic disabledValue = currentFormObject.disabledValue;
  805. List exclusiveValue = currentFormObject.exclusiveValue ?? [];
  806. void selectCheckBoxChange(Option e) {
  807. // 互斥项预处理
  808. if (exclusiveValue.isNotEmpty && exclusiveValue.contains(e.value)) {
  809. currentSelectedCheckBox.removeWhere((element) =>
  810. exclusiveValue.contains(element) && element != e.value);
  811. }
  812. if (currentSelectedCheckBox.contains(e.value)) {
  813. currentSelectedCheckBox.remove(e.value);
  814. } else {
  815. if (disabledValue == e.value) {
  816. currentSelectedCheckBox = [disabledValue];
  817. } else {
  818. if (currentSelectedCheckBox.contains(disabledValue)) {
  819. // PromptBox.toast('选项冲突');
  820. } else {
  821. // 最大可选处理
  822. if (currentFormObject.maxItems != null &&
  823. currentSelectedCheckBox.length >= currentFormObject.maxItems!) {
  824. PromptBox.toast('最多选择${currentFormObject.maxItems}项');
  825. return;
  826. }
  827. currentSelectedCheckBox.add(e.value ?? '');
  828. }
  829. }
  830. }
  831. formValue[currentFormObject.key!] = currentSelectedCheckBox;
  832. setState(() {});
  833. }
  834. return ExamCheckBox(
  835. options: options,
  836. currentSelectedCheckBox: currentSelectedCheckBox,
  837. currentFormObject: currentFormObject,
  838. selectCheckBoxChange: selectCheckBoxChange,
  839. disbaleOthers: currentSelectedCheckBox.contains(disabledValue),
  840. );
  841. }
  842. /// 数字输入框组件
  843. Widget _buildNumberInput(FormObject currentFormObject) {
  844. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  845. if ((formValue['Height']?.isNotEmpty ?? false) &&
  846. (formValue['Weight']?.isNotEmpty ?? false)) {
  847. formValue['Bmi'] = (double.parse(formValue['Weight']) /
  848. ((double.parse(formValue['Height']) / 100) *
  849. (double.parse(formValue['Height']) / 100)))
  850. .toStringAsFixed(2);
  851. }
  852. Future<void> commonInput() async {
  853. String? result = await VDialogNumber(
  854. title: currentFormObject.label,
  855. initialValue: formValue[currentFormObject.key],
  856. ).show();
  857. if (result?.isNotEmpty ?? false) {
  858. formValue[currentFormObject.key!] = result;
  859. currentInputValue = formValue[currentFormObject.key!];
  860. setState(() {});
  861. } else {
  862. formValue[currentFormObject.key!] = '';
  863. currentInputValue = formValue[currentFormObject.key!];
  864. setState(() {});
  865. }
  866. }
  867. void specialInput(String value) {
  868. formValue[currentFormObject.key!] = value;
  869. currentInputValue = formValue[currentFormObject.key!];
  870. setState(() {});
  871. }
  872. return ExamNumberInput(
  873. currentInputValue: currentInputValue,
  874. commonInput: commonInput,
  875. specialInput: specialInput,
  876. currentFormObject: currentFormObject,
  877. );
  878. }
  879. Widget _buildInput(FormObject currentFormObject) {
  880. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  881. Future<void> commonInput() async {
  882. String? result = await VDialogInput(
  883. title: currentFormObject.label,
  884. initialValue: formValue[currentFormObject.key],
  885. ).show();
  886. if (result?.isNotEmpty ?? false) {
  887. formValue[currentFormObject.key!] = result;
  888. currentInputValue = formValue[currentFormObject.key!];
  889. setState(() {});
  890. }
  891. }
  892. return ExamInput(
  893. currentInputValue: currentInputValue,
  894. commonInput: commonInput,
  895. currentFormObject: currentFormObject,
  896. );
  897. }
  898. ///住院次数
  899. // Widget _buildInputHospitalizationTimes(FormObject currentFormObject) {
  900. // DateFormat format = DateFormat('yyyy-MM-dd');
  901. // String currentSelected = formValue[currentFormObject.key!] ?? '';
  902. // String firstAntipsyTreatDate =
  903. // formValue[currentFormObject.childrenKey!.first] ?? '';
  904. // String pastPsyInpatTimes =
  905. // formValue[currentFormObject.childrenKey!.last] ?? '';
  906. // Future<void> commonInput() async {
  907. // String? result = await VDialogNumber(
  908. // title: "曾住精神专科医院/综合医院精神专科次数",
  909. // initialValue: formValue[currentFormObject.key],
  910. // ).show();
  911. // if (result?.isNotEmpty ?? false) {
  912. // formValue[currentFormObject.childrenKey!.last] = result;
  913. // pastPsyInpatTimes = formValue[currentFormObject.childrenKey!.last];
  914. // setState(() {});
  915. // }
  916. // }
  917. // void selectRaidoChange(Option e) {
  918. // if (currentSelected == e.value) {
  919. // currentSelected = '';
  920. // } else {
  921. // currentSelected = e.value ?? '';
  922. // }
  923. // formValue[currentFormObject.key!] = currentSelected;
  924. // setState(() {});
  925. // }
  926. // Future<void> commonInputDate() async {
  927. // DateTime? result = await VDialogDate(
  928. // title: "签字时间",
  929. // initialValue: firstAntipsyTreatDate.isNotNullOrEmpty
  930. // ? format.parse(firstAntipsyTreatDate)
  931. // : DateTime.now(),
  932. // ).show();
  933. // if (result != null) {
  934. // firstAntipsyTreatDate = DateFormat("yyyy-MM-dd").format(result);
  935. // formValue[currentFormObject.childrenKey!.last] = firstAntipsyTreatDate;
  936. // setState(() {});
  937. // }
  938. // }
  939. // return ExamRadioPreviousTreatment(
  940. // currentSelected: currentSelected,
  941. // options: currentFormObject.options!,
  942. // commonInput: commonInput,
  943. // commonInputDate: commonInputDate,
  944. // selectRaidoChange: selectRaidoChange,
  945. // firstAntipsyTreatDate: firstAntipsyTreatDate,
  946. // pastPsyInpatTimes: pastPsyInpatTimes,
  947. // currentFormObject: currentFormObject,
  948. // );
  949. // }
  950. ///目前诊断情况
  951. Widget _buildInputDiagnose(FormObject currentFormObject) {
  952. DateFormat format = DateFormat('yyyy-MM-dd');
  953. String currentInputValue =
  954. formValue[currentFormObject.childrenKey![0]] ?? '';
  955. String currentConfirmationHospitals =
  956. formValue[currentFormObject.childrenKey![1]] ?? '';
  957. String currentTimeDiagnosis =
  958. formValue[currentFormObject.childrenKey![2]] ?? '';
  959. Future<void> commonInput() async {
  960. String? result = await VDialogInput(
  961. title: "诊断",
  962. initialValue: formValue[currentFormObject.childrenKey![0]],
  963. ).show();
  964. if (result?.isNotEmpty ?? false) {
  965. formValue[currentFormObject.key!] = result;
  966. currentInputValue = formValue[currentFormObject.key!];
  967. setState(() {});
  968. }
  969. }
  970. Future<void> commonConfirmationHospitals() async {
  971. String? result = await VDialogInput(
  972. title: "确诊医院",
  973. initialValue: currentConfirmationHospitals,
  974. ).show();
  975. if (result?.isNotEmpty ?? false) {
  976. formValue[currentFormObject.childrenKey![1]] = result;
  977. currentConfirmationHospitals = formValue[currentFormObject.key!];
  978. setState(() {});
  979. }
  980. }
  981. Future<void> commonTimeDiagnosis() async {
  982. DateTime? result = await VDialogDate(
  983. title: "确诊日期",
  984. initialValue: currentTimeDiagnosis.isNotNullOrEmpty
  985. ? format.parse(currentTimeDiagnosis)
  986. : DateTime.now(),
  987. maxValue: DateTime.now(),
  988. ).show();
  989. if (result != null) {
  990. formValue[currentFormObject.childrenKey![2]] =
  991. DateFormat("yyyy-MM-dd").format(result);
  992. currentTimeDiagnosis = formValue[currentFormObject.childrenKey![2]];
  993. setState(() {});
  994. }
  995. }
  996. return ExamInputDiagnose(
  997. currentInputValue: currentInputValue,
  998. currentConfirmationHospitals: currentConfirmationHospitals,
  999. currentTimeDiagnosis: currentTimeDiagnosis,
  1000. commonInput: commonInput,
  1001. currentFormObject: currentFormObject,
  1002. commonConfirmationHospitals: commonConfirmationHospitals,
  1003. commonTimeDiagnosis: commonTimeDiagnosis,
  1004. );
  1005. }
  1006. ///签字同意
  1007. Widget _buildRadioInformedConsent(FormObject currentFormObject) {
  1008. DateFormat format = DateFormat('yyyy-MM-dd');
  1009. List<Option> options = currentFormObject.options ?? [];
  1010. var currentValue = formValue[currentFormObject.key!] ?? '';
  1011. String currentSelected = "";
  1012. if (currentValue is String) {
  1013. currentSelected = currentValue;
  1014. }
  1015. String sign = formValue[currentFormObject.childrenKey!.first] ?? "";
  1016. String signingTime = formValue[currentFormObject.childrenKey!.last] ?? "";
  1017. void selectRaidoChange(Option e) {
  1018. currentSelected = e.value ?? '';
  1019. formValue[currentFormObject.key!] = currentSelected;
  1020. setState(() {});
  1021. }
  1022. Future<void> commonInput() async {
  1023. String? result = await VDialogInput(
  1024. title: "签字",
  1025. initialValue: sign,
  1026. ).show();
  1027. if (result?.isNotEmpty ?? false) {
  1028. sign = result ?? '';
  1029. formValue[currentFormObject.childrenKey!.first] = sign;
  1030. setState(() {});
  1031. }
  1032. }
  1033. Future<void> commonInputDate() async {
  1034. DateTime? result = await VDialogDate(
  1035. title: "签字时间",
  1036. initialValue: signingTime.isNotNullOrEmpty
  1037. ? format.parse(signingTime)
  1038. : DateTime.now(),
  1039. ).show();
  1040. if (result != null) {
  1041. signingTime = DateFormat("yyyy-MM-dd").format(result);
  1042. formValue[currentFormObject.childrenKey!.last] = signingTime;
  1043. setState(() {});
  1044. }
  1045. }
  1046. return ExamRadioInformedConsent(
  1047. options: options,
  1048. currentFormObject: currentFormObject,
  1049. selectRaidoChange: selectRaidoChange,
  1050. currentSelected: currentSelected,
  1051. commonInput: commonInput,
  1052. commonInputDate: commonInputDate,
  1053. sign: sign,
  1054. signingTime: signingTime,
  1055. );
  1056. }
  1057. ///时间组件
  1058. Widget _buildDate(FormObject currentFormObject) {
  1059. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  1060. DateTime currentDateValue = DateTime.now();
  1061. if (currentInputValue.isNotNullOrEmpty) {
  1062. DateFormat format = DateFormat('yyyy-MM-dd');
  1063. currentDateValue = format.parse(currentInputValue);
  1064. }
  1065. Future<void> commonInput() async {
  1066. DateTime? result = await VDialogDate(
  1067. title: currentFormObject.label,
  1068. initialValue: currentDateValue,
  1069. maxValue: DateTime.now(),
  1070. ).show();
  1071. if (result != null) {
  1072. formValue[currentFormObject.key!] =
  1073. DateFormat("yyyy-MM-dd").format(result);
  1074. currentInputValue = formValue[currentFormObject.key!];
  1075. setState(() {});
  1076. }
  1077. }
  1078. return ExamInput(
  1079. currentInputValue: currentInputValue,
  1080. commonInput: commonInput,
  1081. currentFormObject: currentFormObject,
  1082. );
  1083. }
  1084. /// 血压组件
  1085. Widget _buildBloodPressure(FormObject currentFormObject) {
  1086. Map currentValue = formValue[currentFormObject.key!] ?? {};
  1087. print(currentFormObject.key!);
  1088. void bloodPressure(Map value) {
  1089. currentValue = value;
  1090. formValue[currentFormObject.key!] = currentValue;
  1091. // setState(() {});
  1092. }
  1093. return ExamBloodPressure(
  1094. currentValue: currentValue,
  1095. bloodPressure: bloodPressure,
  1096. );
  1097. }
  1098. Widget _buildUrinalysis(FormObject currentFormObject) {
  1099. Map currentValue = formValue[currentFormObject.key!] ?? {};
  1100. void urinalysis(Map value) {
  1101. currentValue = value;
  1102. formValue[currentFormObject.key!] = currentValue;
  1103. setState(() {});
  1104. }
  1105. return ExamUrinalysis(
  1106. currentValue: currentValue,
  1107. urinalysis: urinalysis,
  1108. );
  1109. }
  1110. Widget _buildDentition(FormObject currentFormObject) {
  1111. dynamic dentitionValue = formValue[currentFormObject.key!] ?? {};
  1112. Map currentValue = {};
  1113. if (!(dentitionValue is Map)) {
  1114. currentValue = {};
  1115. } else {
  1116. currentValue = dentitionValue;
  1117. }
  1118. void onValueChange(Map value) {
  1119. currentValue = value;
  1120. formValue[currentFormObject.key!] = currentValue;
  1121. setState(() {});
  1122. if (widget.cardKey == "ZQCT") {
  1123. var isAllSelectZQCT = CalculatesWhetherTheSelectAllButtonIsSelected();
  1124. _isAllSelectZQCT = isAllSelectZQCT;
  1125. if (widget.onAllSelectZQCTChange != null) {
  1126. widget.onAllSelectZQCTChange!(isAllSelectZQCT);
  1127. }
  1128. }
  1129. }
  1130. return ExamDentition(
  1131. currentValue: currentValue,
  1132. onValueChange: onValueChange,
  1133. );
  1134. }
  1135. Widget _buildRiskFactorControl(FormObject currentFormObject) {
  1136. dynamic value = formValue[currentFormObject.key!] ?? {};
  1137. Map currentValue = {};
  1138. if (value is Map) {
  1139. currentValue = value;
  1140. }
  1141. void onValueChange(Map value) {
  1142. currentValue = value;
  1143. formValue[currentFormObject.key!] = currentValue;
  1144. setState(() {});
  1145. }
  1146. return ExamRiskFactorControl(
  1147. currentValue: currentValue,
  1148. onValueChange: onValueChange,
  1149. );
  1150. }
  1151. Widget _buildAbilityRadio(FormObject currentFormObject) {
  1152. List<Option> options = currentFormObject.options ?? [];
  1153. String currentSelected = formValue[currentFormObject.key!] ?? "";
  1154. String abilityCode = formValue["Ability_Code"] ?? '';
  1155. void selectRaidoChange(Option e) {
  1156. if (currentSelected == e.value) {
  1157. currentSelected = '';
  1158. } else {
  1159. currentSelected = e.value ?? '';
  1160. }
  1161. formValue[currentFormObject.key!] = currentSelected;
  1162. setState(() {});
  1163. }
  1164. void examAbilityCodeChange(String? e) {
  1165. formValue["Ability_Code"] = e;
  1166. setState(() {});
  1167. }
  1168. return ExamAbilityRadio(
  1169. options: options,
  1170. currentFormObject: currentFormObject,
  1171. selectRaidoChange: selectRaidoChange,
  1172. currentSelected: currentSelected,
  1173. patientCode: widget.patientCode!,
  1174. lNRZLPGCode: abilityCode,
  1175. physicalExamNumber: widget.physicalExamNumber,
  1176. examAbilityCodeChange: examAbilityCodeChange,
  1177. );
  1178. }
  1179. /// 危险行为
  1180. Widget _buildCheckBoxFrequency(FormObject currentFormObject) {
  1181. List<Option> options = currentFormObject.options ?? [];
  1182. List<dynamic> currentFormObjectFrom =
  1183. formValue[currentFormObject.key!] ?? [];
  1184. List<DangerFrequency> currentSelectedCheckBox =
  1185. currentFormObjectFrom.map((e) {
  1186. if (e is Map<String, dynamic>) {
  1187. return DangerFrequency.fromJson(e);
  1188. } else {
  1189. return DangerFrequency.fromJson(e.toJson());
  1190. }
  1191. }).toList();
  1192. dynamic disabledValue = currentFormObject.disabledValue;
  1193. Future<void> selectCheckBoxChange(Option e) async {
  1194. var ddd =
  1195. currentSelectedCheckBox.firstWhereOrNull((f) => f.value == e.value);
  1196. if (ddd != null) {
  1197. currentSelectedCheckBox.remove(ddd);
  1198. } else {
  1199. if (disabledValue == e.value) {
  1200. currentSelectedCheckBox = [
  1201. DangerFrequency(frequency: "0", value: disabledValue)
  1202. ];
  1203. } else {
  1204. var ccc = currentSelectedCheckBox
  1205. .firstWhereOrNull((f) => f.value == disabledValue);
  1206. if (ccc != null) {
  1207. // PromptBox.toast('选项冲突');
  1208. } else {
  1209. String? result = await VDialogNumber(
  1210. title: "${e.label}次数",
  1211. // initialValue: formValue[currentFormObject.key],
  1212. ).show();
  1213. if (result?.isNotEmpty ?? false) {
  1214. currentSelectedCheckBox.add(
  1215. DangerFrequency(frequency: result, value: e.value ?? ''));
  1216. }
  1217. }
  1218. }
  1219. }
  1220. formValue[currentFormObject.key!] = currentSelectedCheckBox;
  1221. setState(() {});
  1222. }
  1223. return ExamCheckBoxFrequency(
  1224. options: options,
  1225. currentSelectedCheckBox: currentSelectedCheckBox,
  1226. currentFormObject: currentFormObject,
  1227. func: selectCheckBoxChange,
  1228. disbaleOthers: currentSelectedCheckBox
  1229. .firstWhereOrNull((f) => f.value == disabledValue) !=
  1230. null,
  1231. );
  1232. }
  1233. Widget _buildCheckBoxIncludeOther(FormObject currentFormObject) {
  1234. List<Option> options = currentFormObject.options ?? [];
  1235. List<dynamic> currentSelected = formValue[currentFormObject.key!] ?? [];
  1236. dynamic disabledValue = currentFormObject.disabledValue;
  1237. dynamic otherItem = currentFormObject.groupKeys!.first;
  1238. String otherDecrition =
  1239. formValue[currentFormObject.childrenKey!.first] ?? "";
  1240. void selectCheckBoxChange(Option e) {
  1241. if (currentSelected.contains(e.value)) {
  1242. currentSelected.remove(e.value);
  1243. if (e.value == otherItem) {
  1244. otherDecrition = '';
  1245. }
  1246. } else {
  1247. if (disabledValue == e.value) {
  1248. currentSelected = [disabledValue];
  1249. } else {
  1250. if (currentSelected.contains(disabledValue)) {
  1251. // PromptBox.toast('选项冲突');
  1252. } else {
  1253. currentSelected.add(e.value ?? '');
  1254. }
  1255. }
  1256. }
  1257. formValue[currentFormObject.key!] = currentSelected;
  1258. setState(() {});
  1259. }
  1260. void changeExtraDescription(String? extraDescription) {
  1261. otherDecrition = extraDescription ?? '';
  1262. formValue[currentFormObject.childrenKey!.first] = otherDecrition;
  1263. setState(() {});
  1264. }
  1265. return ExamCheckBoxIncludeOther(
  1266. options: options,
  1267. currentSelectedCheckBox: currentSelected,
  1268. currentFormObject: currentFormObject,
  1269. selectCheckBoxChange: selectCheckBoxChange,
  1270. disbaleOthers: currentSelected.contains(disabledValue),
  1271. changeExtraDescription: changeExtraDescription,
  1272. currentExtraDescription: otherDecrition,
  1273. extraDescriptiveItem: otherItem,
  1274. );
  1275. }
  1276. /// 单选框组件
  1277. Widget _buildRadio(FormObject currentFormObject) {
  1278. List<Option> options = currentFormObject.options ?? [];
  1279. String currentSelected = formValue[currentFormObject.key!] ?? "";
  1280. void selectRaidoChange(Option e) {
  1281. if (currentSelected == e.value) {
  1282. currentSelected = '';
  1283. } else {
  1284. currentSelected = e.value ?? '';
  1285. }
  1286. formValue[currentFormObject.key!] = currentSelected;
  1287. if (widget.cardKey == "ZQCT") {
  1288. var isAllSelectZQCT = CalculatesWhetherTheSelectAllButtonIsSelected();
  1289. _isAllSelectZQCT = isAllSelectZQCT;
  1290. if (widget.onAllSelectZQCTChange != null) {
  1291. widget.onAllSelectZQCTChange!(isAllSelectZQCT);
  1292. }
  1293. }
  1294. setState(() {});
  1295. }
  1296. return ExamRadio(
  1297. options: options,
  1298. currentFormObject: currentFormObject,
  1299. selectRaidoChange: selectRaidoChange,
  1300. currentSelected: currentSelected,
  1301. );
  1302. }
  1303. Widget _buildRadioScore(FormObject currentFormObject) {
  1304. List<Option> options = currentFormObject.options ?? [];
  1305. String currentSelected =
  1306. formValue[currentFormObject.childrenKey!.first] ?? "";
  1307. String currentScore = formValue[currentFormObject.childrenKey!.last] ?? "";
  1308. void selectRaidoChange(Option e) {
  1309. if (formValue[currentFormObject.childrenKey!.first] == e.value) {
  1310. formValue[currentFormObject.childrenKey!.first] = '';
  1311. currentSelected = '';
  1312. } else {
  1313. currentSelected = e.value ?? '';
  1314. formValue[currentFormObject.childrenKey!.first] = currentSelected;
  1315. }
  1316. setState(() {});
  1317. }
  1318. void changeScore(String? score) {
  1319. currentScore = score ?? '';
  1320. formValue[currentFormObject.childrenKey!.last] = currentScore;
  1321. setState(() {});
  1322. }
  1323. return ExamRadioScore(
  1324. options: options,
  1325. currentFormObject: currentFormObject,
  1326. selectRaidoChange: selectRaidoChange,
  1327. currentSelected: currentSelected,
  1328. changeScore: changeScore,
  1329. currentScore: currentScore,
  1330. );
  1331. }
  1332. Widget _buildRadioExtraDescription(FormObject currentFormObject) {
  1333. print(currentFormObject.toJson());
  1334. List<Option> options = currentFormObject.options ?? [];
  1335. String currentValue = formValue[currentFormObject.key!] ?? "";
  1336. String otherDecrition =
  1337. formValue[currentFormObject.childrenKey!.first] ?? "";
  1338. dynamic otherItem = currentFormObject.groupKeys!.first;
  1339. void selectRaidoChange(Option e) {
  1340. currentValue = e.value ?? '';
  1341. formValue[currentFormObject.key!] = currentValue;
  1342. setState(() {});
  1343. }
  1344. void changeExtraDescription(String? extraDescription) {
  1345. otherDecrition = extraDescription ?? '';
  1346. formValue[currentFormObject.childrenKey!.first] = otherDecrition;
  1347. setState(() {});
  1348. }
  1349. return ExamRadioExtraDescription(
  1350. options: options,
  1351. currentFormObject: currentFormObject,
  1352. selectRaidoChange: selectRaidoChange,
  1353. currentSelected: currentValue,
  1354. changeExtraDescription: changeExtraDescription,
  1355. currentExtraDescription: otherDecrition,
  1356. extraDescriptiveItem: otherItem,
  1357. );
  1358. }
  1359. /// 体温组件
  1360. Widget _buildBodyTemperature(FormObject currentFormObject) {
  1361. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  1362. void bodyTemperatureInput(String value) {
  1363. formValue[currentFormObject.key!] = value;
  1364. currentInputValue = formValue[currentFormObject.key!];
  1365. setState(() {});
  1366. }
  1367. return ExamBodyTemperature(
  1368. currentInputValue: currentInputValue,
  1369. bodyTemperatureInput: bodyTemperatureInput,
  1370. currentFormObject: currentFormObject,
  1371. );
  1372. }
  1373. Widget _buildToxicSubstance(FormObject currentFormObject) {
  1374. List<Option> options = currentFormObject.options ?? [];
  1375. String currentValue = formValue[currentFormObject.childrenKey!.first] ?? "";
  1376. Map? currentSelectedToxicSubstance =
  1377. formValue[currentFormObject.childrenKey!.last];
  1378. void selectRaidoChange(Map e) {
  1379. // TODO 处理一下取消选择的问题
  1380. currentSelectedToxicSubstance = e;
  1381. formValue[currentFormObject.childrenKey!.last] =
  1382. currentSelectedToxicSubstance;
  1383. setState(() {});
  1384. }
  1385. void selectValueChange(String e) {
  1386. currentValue = e;
  1387. formValue[currentFormObject.childrenKey!.first] = currentValue;
  1388. setState(() {});
  1389. }
  1390. return ExamToxicSubstance(
  1391. currentFormObject: currentFormObject,
  1392. currentSelectedToxicSubstance: currentSelectedToxicSubstance,
  1393. currentValue: currentValue,
  1394. options: options,
  1395. selectRadioChange: selectRaidoChange,
  1396. selectValueChange: selectValueChange,
  1397. );
  1398. }
  1399. /// 血氧
  1400. Widget _buildBloodOxygen(FormObject currentFormObject) {
  1401. Map<String, dynamic> currentValue = formValue;
  1402. void bloodOxygenInput(Map<String, dynamic> bloodOxygen) {
  1403. formValue['Pulse_Frequency'] = bloodOxygen['Pulse_Frequency'];
  1404. formValue['Spo2'] = bloodOxygen['Spo2'];
  1405. currentValue = bloodOxygen;
  1406. setState(() {});
  1407. }
  1408. return ExamBloodOxygen(
  1409. currentValue: currentValue,
  1410. bloodOxygenInput: bloodOxygenInput,
  1411. );
  1412. }
  1413. /// 住院史
  1414. Widget _buildMedicalHistory(FormObject currentFormObject) {
  1415. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  1416. int currentId = currentValue.length + 1;
  1417. void resultChange(Map result) {
  1418. currentValue.add(result);
  1419. formValue[currentFormObject.key!] = currentValue;
  1420. setState(() {});
  1421. }
  1422. void editResult(EditTableValue result) {
  1423. currentValue[result.id! - 1] = result.value;
  1424. formValue[currentFormObject.key!] = currentValue;
  1425. setState(() {});
  1426. }
  1427. Future<void> addTableData() async {
  1428. Get.dialog(
  1429. HospitalizationHistoryForm(
  1430. fromResult: (result) => resultChange(result),
  1431. currentId: currentId,
  1432. ),
  1433. );
  1434. }
  1435. Future<void> editTableData(EditTableValue editTableValue) async {
  1436. Get.dialog(
  1437. HospitalizationHistoryForm(
  1438. fromResult: (result) => editResult(result),
  1439. currentId: editTableValue.id!,
  1440. admissionJson: editTableValue.value,
  1441. ),
  1442. );
  1443. }
  1444. return FittedBox(
  1445. child: ExamTable(
  1446. tableThList: const ['序号', '入院日期', '出院日期', '原因', '医疗机构名称', '病案号', '操作'],
  1447. currentFormObject: currentFormObject,
  1448. currentValue: currentValue,
  1449. addTableData: addTableData,
  1450. editTableData: (value) => editTableData(value),
  1451. removeTableData: (id) {
  1452. List values = formValue[currentFormObject.key!];
  1453. values.removeWhere((element) => element["id"] == id.toString());
  1454. setState(() {});
  1455. },
  1456. ),
  1457. );
  1458. }
  1459. /// 家庭病床史
  1460. Widget _buildHomecareBedHistory(FormObject currentFormObject) {
  1461. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  1462. int currentId = currentValue.length + 1;
  1463. void resultChange(Map result) {
  1464. int length = 0;
  1465. for (var i in result.keys) {
  1466. if (result[i] == "") {
  1467. length++;
  1468. continue;
  1469. }
  1470. }
  1471. if (length == result.keys.length - 1) {
  1472. return;
  1473. }
  1474. currentValue.add(result);
  1475. formValue[currentFormObject.key!] = currentValue;
  1476. setState(() {});
  1477. }
  1478. void editResult(EditTableValue result) {
  1479. currentValue[result.id! - 1] = result.value;
  1480. formValue[currentFormObject.key!] = currentValue;
  1481. setState(() {});
  1482. }
  1483. Future<void> addTableData() async {
  1484. Get.dialog(
  1485. HomecareBedHistoryFrom(
  1486. fromResult: (result) => resultChange(result),
  1487. currentId: currentId,
  1488. ),
  1489. );
  1490. }
  1491. Future<void> editTableData(EditTableValue editTableValue) async {
  1492. Get.dialog(
  1493. HomecareBedHistoryFrom(
  1494. fromResult: (result) => editResult(result),
  1495. currentId: editTableValue.id!,
  1496. admissionJson: editTableValue.value,
  1497. ),
  1498. );
  1499. }
  1500. return FittedBox(
  1501. child: ExamTable(
  1502. tableThList: const ['序号', '建床日期', '撤床日期', '原因', '医疗机构名称', '病案号', '操作'],
  1503. currentFormObject: currentFormObject,
  1504. currentValue: currentValue,
  1505. addTableData: addTableData,
  1506. editTableData: (value) => editTableData(value),
  1507. removeTableData: (id) {
  1508. List values = formValue[currentFormObject.key!];
  1509. values.removeWhere((element) => element["id"] == id.toString());
  1510. setState(() {});
  1511. },
  1512. ),
  1513. );
  1514. }
  1515. Widget _buildMainMedicationHistory(FormObject currentFormObject) {
  1516. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  1517. int currentId = currentValue.length + 1;
  1518. void resultChange(Map result) {
  1519. currentValue.add(result);
  1520. formValue[currentFormObject.key!] = currentValue;
  1521. setState(() {});
  1522. }
  1523. void editResult(EditTableValue result) {
  1524. currentValue[result.id! - 1] = result.value;
  1525. formValue[currentFormObject.key!] = currentValue;
  1526. setState(() {});
  1527. }
  1528. Future<void> addTableData() async {
  1529. Get.dialog(
  1530. MainMedicationStatusFrom(
  1531. fromResult: (result) => resultChange(result),
  1532. currentId: currentId,
  1533. ),
  1534. );
  1535. }
  1536. Future<void> editTableData(EditTableValue editTableValue) async {
  1537. Get.dialog(
  1538. MainMedicationStatusFrom(
  1539. fromResult: (result) => editResult(result),
  1540. currentId: editTableValue.id!,
  1541. admissionJson: editTableValue.value,
  1542. ),
  1543. );
  1544. }
  1545. return FittedBox(
  1546. child: ExamTable(
  1547. tableThList: const [
  1548. '序号',
  1549. '药物名称',
  1550. '用法',
  1551. '用量',
  1552. '用药时间',
  1553. '服药依从性(1规律 2间断 3不服药)',
  1554. '操作'
  1555. ],
  1556. currentFormObject: currentFormObject,
  1557. currentValue: currentValue,
  1558. addTableData: addTableData,
  1559. editTableData: (value) => editTableData(value),
  1560. removeTableData: (id) {
  1561. List values = formValue[currentFormObject.key!];
  1562. values.removeWhere((element) => element["id"] == id.toString());
  1563. setState(() {});
  1564. },
  1565. ),
  1566. );
  1567. }
  1568. Widget _buildInoculateHistory(FormObject currentFormObject) {
  1569. List<dynamic> currentValue = formValue[currentFormObject.key!] ?? [];
  1570. int currentId = currentValue.length + 1;
  1571. void resultChange(Map result) {
  1572. currentValue.add(result);
  1573. formValue[currentFormObject.key!] = currentValue;
  1574. setState(() {});
  1575. }
  1576. void editResult(EditTableValue result) {
  1577. currentValue[result.id! - 1] = result.value;
  1578. formValue[currentFormObject.key!] = currentValue;
  1579. setState(() {});
  1580. }
  1581. Future<void> addTableData() async {
  1582. Get.dialog(
  1583. InoculateHistoryFrom(
  1584. fromResult: (result) => resultChange(result),
  1585. currentId: currentId,
  1586. ),
  1587. );
  1588. }
  1589. Future<void> editTableData(EditTableValue editTableValue) async {
  1590. Get.dialog(
  1591. InoculateHistoryFrom(
  1592. fromResult: (result) => editResult(result),
  1593. currentId: editTableValue.id!,
  1594. admissionJson: editTableValue.value,
  1595. ),
  1596. );
  1597. }
  1598. return ExamTable(
  1599. tableThList: const ['序号', '疫苗名称', '接种日期', '接种机构', '操作'],
  1600. currentFormObject: currentFormObject,
  1601. currentValue: currentValue,
  1602. addTableData: addTableData,
  1603. editTableData: (value) => editTableData(value),
  1604. removeTableData: (id) {
  1605. List values = formValue[currentFormObject.key!];
  1606. values.removeWhere((element) => element["id"] == id.toString());
  1607. setState(() {});
  1608. },
  1609. );
  1610. }
  1611. /// 体重
  1612. Widget _buildBodyWeight(FormObject currentFormObject) {
  1613. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  1614. void bodyWeightInput(String value) {
  1615. formValue[currentFormObject.key!] = value;
  1616. currentInputValue = formValue[currentFormObject.key!];
  1617. setState(() {});
  1618. }
  1619. return ExamBodyWeight(
  1620. currentInputValue: currentInputValue,
  1621. bodyWeightInput: bodyWeightInput,
  1622. currentFormObject: currentFormObject,
  1623. );
  1624. }
  1625. /// 血糖
  1626. Widget _buildBodySugar(FormObject currentFormObject) {
  1627. String currentInputValue = formValue[currentFormObject.key!] ?? '';
  1628. void bloodSugarInput(String value) {
  1629. formValue[currentFormObject.key!] = value;
  1630. currentInputValue = formValue[currentFormObject.key!];
  1631. setState(() {});
  1632. }
  1633. return ExamBloodSugar(
  1634. currentInputValue: currentInputValue,
  1635. bloodSugarInput: bloodSugarInput,
  1636. currentFormObject: currentFormObject,
  1637. );
  1638. }
  1639. Widget _buildAbnormal(FormObject currentFormObject) {
  1640. List<dynamic> currentValue = [];
  1641. var value = formValue[currentFormObject.key!];
  1642. if (value is String) {
  1643. currentValue.add(value);
  1644. } else {
  1645. currentValue = value ?? [];
  1646. }
  1647. Future<void> addAbnormalData() async {
  1648. String? result = await VDialogInput(
  1649. title: currentFormObject.label,
  1650. ).show();
  1651. if (result.isNotNullOrEmpty) {
  1652. currentValue.add(result);
  1653. formValue[currentFormObject.key!] = null;
  1654. formValue[currentFormObject.key!] = currentValue;
  1655. }
  1656. setState(() {});
  1657. }
  1658. Future<void> deleteAbnormalData(int index) async {
  1659. currentValue.removeAt(index);
  1660. formValue[currentFormObject.key!] = null;
  1661. formValue[currentFormObject.key!] = currentValue;
  1662. setState(() {});
  1663. }
  1664. return ExamAbnormal(
  1665. currentFormObject: currentFormObject,
  1666. currentValue: currentValue,
  1667. addAbnormal: addAbnormalData,
  1668. deleteAbnormal: deleteAbnormalData,
  1669. );
  1670. }
  1671. }