maternal_health_form.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. import 'base_form_value.dart';
  2. import 'form_info.dart';
  3. class MaternalHealthFormValue extends BaseFormValueChange {
  4. static MaternalHealthFormValue? _maternalHealthManagementForm;
  5. MaternalHealthFormValue._internal();
  6. ///第 1 次产前检查服务记录表的值
  7. static MaternalHealthFormValue get instance {
  8. _maternalHealthManagementForm ??= MaternalHealthFormValue._internal();
  9. return _maternalHealthManagementForm!;
  10. }
  11. void initListener() {
  12. FormInfo.instance.onValueChange.addListener(_onValueChange);
  13. }
  14. void dispose() {
  15. FormInfo.instance.onValueChange.removeListener(_onValueChange);
  16. }
  17. void _onValueChange(Object sender, UpdateFormArgs e) {
  18. String sourceKey = e.sourceKey;
  19. UpdateFormType type = e.type;
  20. switch (sourceKey) {
  21. //末次月经
  22. case "Last_Period":
  23. changeLastPeriodDate(e);
  24. break;
  25. //既往史
  26. case "Past_History":
  27. //既往史选择无
  28. changePastHistory(e);
  29. break;
  30. //家族史
  31. case "Family_History":
  32. changeFamilyHistory(e);
  33. break;
  34. //妇产科手术史
  35. case "Operation_History":
  36. changeOperationHistory(e);
  37. break;
  38. //升高、体重计算BMI
  39. case "Weight":
  40. case "Height":
  41. super.onHeightOrWeightChange(e);
  42. break;
  43. //心脏
  44. case "Heart_Abnormal":
  45. changeHeartAbnormal(e);
  46. break;
  47. //肺部
  48. case "Lung_Abnormal":
  49. changeLungAbnormal(e);
  50. break;
  51. //外阴
  52. case "Vulvar":
  53. changeVulvar(e);
  54. break;
  55. //阴道
  56. case "Vagina":
  57. onValueChange(e, "Vagina_1", "Vagina_Abnormality");
  58. break;
  59. //宫颈
  60. case "Cervical":
  61. onValueChange(e, "Cervical_1", "Cervical_Abnormality");
  62. break;
  63. //子宫
  64. case "Uteri_Body":
  65. onValueChange(e, "Uteri_Body_1", "Uteri_Body_Abnormality");
  66. break;
  67. //附件
  68. case "Uteri_Adnexa":
  69. onValueChange(e, "Uteri_Adnexa_1", "Uteri_Adnexa_Abnormality");
  70. break;
  71. //阴道分泌物
  72. case "Vaginal_Discharge":
  73. onVaginalDischargeChange(e);
  74. break;
  75. case "MaternalHealthManagement_Overall_Assessment":
  76. onValueChange(e, "M_O_A_No_Abnormality_Detected", "M_O_A_Abnormality");
  77. break;
  78. case "Referral":
  79. onReferralChange(e);
  80. break;
  81. case "Last_Period_Date":
  82. onLastPeriodDateChange(e);
  83. break;
  84. case "Health_History":
  85. onHealthHistoryChange(e);
  86. break;
  87. }
  88. }
  89. void changeLastPeriodDate(UpdateFormArgs e) {
  90. UpdateFormType type = e.type;
  91. if (type == UpdateFormType.Add) {
  92. if (FormInfo.instance.formValue.containsKey("Last_Period_Date")) {
  93. FormInfo.instance.formValue.remove("Last_Period_Date");
  94. }
  95. ///选中了末次月经的不详,则禁用日期选择器
  96. FormInfo.instance.onChangeTargetValue.emit(
  97. this,
  98. TargetFormArgs(
  99. "Last_Period_Date",
  100. isDisabledValue: true,
  101. ),
  102. );
  103. } else if (type == UpdateFormType.Remove) {
  104. ///取消选中了末次月经的不详,则取消禁用日期选择器
  105. FormInfo.instance.onChangeTargetValue.emit(
  106. this,
  107. TargetFormArgs(
  108. "Last_Period_Date",
  109. isDisabledValue: false,
  110. ),
  111. );
  112. }
  113. }
  114. void changePastHistory(UpdateFormArgs e) {
  115. UpdateFormType type = e.type;
  116. bool isDisabledValue = false;
  117. if (type == UpdateFormType.Add && e.sourceValue == "Past_History_1") {
  118. ///选中了无,则禁用其他选项
  119. isDisabledValue = true;
  120. } else if (type == UpdateFormType.Remove &&
  121. e.sourceValue == "Past_History_1") {
  122. ///取消选中无,则取消禁用其他选项
  123. isDisabledValue = false;
  124. } else {
  125. return;
  126. }
  127. FormInfo.instance.onChangeTargetValue.emit(
  128. this,
  129. TargetFormArgs(
  130. "Past_History_2",
  131. isDisabledValue: isDisabledValue,
  132. ),
  133. );
  134. FormInfo.instance.onChangeTargetValue.emit(
  135. this,
  136. TargetFormArgs(
  137. "Past_History_3",
  138. isDisabledValue: isDisabledValue,
  139. ),
  140. );
  141. FormInfo.instance.onChangeTargetValue.emit(
  142. this,
  143. TargetFormArgs(
  144. "Past_History_4",
  145. isDisabledValue: isDisabledValue,
  146. ),
  147. );
  148. FormInfo.instance.onChangeTargetValue.emit(
  149. this,
  150. TargetFormArgs(
  151. "Past_History_5",
  152. isDisabledValue: isDisabledValue,
  153. ),
  154. );
  155. FormInfo.instance.onChangeTargetValue.emit(
  156. this,
  157. TargetFormArgs(
  158. "Past_History_6",
  159. isDisabledValue: isDisabledValue,
  160. ),
  161. );
  162. FormInfo.instance.onChangeTargetValue.emit(
  163. this,
  164. TargetFormArgs(
  165. "Past_History_7",
  166. isDisabledValue: isDisabledValue,
  167. ),
  168. );
  169. FormInfo.instance.onChangeTargetValue.emit(
  170. this,
  171. TargetFormArgs(
  172. "Past_History_Other",
  173. isDisabledValue: isDisabledValue,
  174. ),
  175. );
  176. }
  177. void changeFamilyHistory(UpdateFormArgs e) {
  178. UpdateFormType type = e.type;
  179. bool isDisabledValue = false;
  180. if (type == UpdateFormType.Add && e.sourceValue == "Family_History_1") {
  181. ///选中了无,则禁用其他选项
  182. isDisabledValue = true;
  183. } else if (type == UpdateFormType.Remove &&
  184. e.sourceValue == "Family_History_1") {
  185. ///取消选中无,则取消禁用其他选项
  186. isDisabledValue = false;
  187. } else if (type == UpdateFormType.Add &&
  188. e.sourceValue == "Family_History_2") {
  189. //选中了遗传性病史,则显示遗传性病史详情
  190. FormInfo.instance.onChangeTargetValue.emit(
  191. this,
  192. TargetFormArgs(
  193. "Family_History_2_Detail",
  194. isHidden: false,
  195. ),
  196. );
  197. return;
  198. } else if (type == UpdateFormType.Remove &&
  199. e.sourceValue == "Family_History_2") {
  200. //取消选中了遗传性病史,则隐藏遗传性病史详情
  201. FormInfo.instance.onChangeTargetValue.emit(
  202. this,
  203. TargetFormArgs(
  204. "Family_History_2_Detail",
  205. isHidden: true,
  206. ),
  207. );
  208. return;
  209. } else if (type == UpdateFormType.Add &&
  210. e.sourceValue == "Family_History_3") {
  211. //选中了精神疾病史,则显示精神疾病史详情
  212. FormInfo.instance.onChangeTargetValue.emit(
  213. this,
  214. TargetFormArgs(
  215. "Family_History_3_Detail",
  216. isHidden: false,
  217. ),
  218. );
  219. return;
  220. } else if (type == UpdateFormType.Remove &&
  221. e.sourceValue == "Family_History_3") {
  222. //取消选中了精神疾病史
  223. FormInfo.instance.onChangeTargetValue.emit(
  224. this,
  225. TargetFormArgs(
  226. "Family_History_3_Detail",
  227. isHidden: true,
  228. ),
  229. );
  230. return;
  231. } else {
  232. return;
  233. }
  234. if (isDisabledValue) {
  235. FormInfo.instance.onChangeTargetValue.emit(
  236. this,
  237. TargetFormArgs(
  238. "Family_History_3_Detail",
  239. isHidden: true,
  240. ),
  241. );
  242. FormInfo.instance.onChangeTargetValue.emit(
  243. this,
  244. TargetFormArgs(
  245. "Family_History_2_Detail",
  246. isHidden: true,
  247. ),
  248. );
  249. }
  250. FormInfo.instance.onChangeTargetValue.emit(
  251. this,
  252. TargetFormArgs(
  253. "Family_History_2",
  254. isDisabledValue: isDisabledValue,
  255. ),
  256. );
  257. FormInfo.instance.onChangeTargetValue.emit(
  258. this,
  259. TargetFormArgs(
  260. "Family_History_3",
  261. isDisabledValue: isDisabledValue,
  262. ),
  263. );
  264. FormInfo.instance.onChangeTargetValue.emit(
  265. this,
  266. TargetFormArgs(
  267. "Family_History_Other",
  268. isDisabledValue: isDisabledValue,
  269. ),
  270. );
  271. }
  272. void changeOperationHistory(UpdateFormArgs e) {
  273. UpdateFormType type = e.type;
  274. if (e.sourceValue == "Operation_History_null") {
  275. if (type == UpdateFormType.Add) {
  276. FormInfo.instance.onChangeTargetValue.emit(
  277. this,
  278. TargetFormArgs(
  279. "Operation_History_True",
  280. targetValue: "cancelSelection",
  281. ),
  282. );
  283. FormInfo.instance.onChangeTargetValue.emit(
  284. this,
  285. TargetFormArgs(
  286. "Operation_History_True_Detail",
  287. isHidden: true,
  288. ),
  289. );
  290. }
  291. FormInfo.instance.formValue[e.sourceKey] = [e.sourceValue];
  292. } else if (e.sourceValue == "Operation_History_True") {
  293. FormInfo.instance.formValue[e.sourceKey] = [e.sourceValue];
  294. if (type == UpdateFormType.Add) {
  295. FormInfo.instance.onChangeTargetValue.emit(
  296. this,
  297. TargetFormArgs(
  298. "Operation_History_null",
  299. targetValue: "cancelSelection",
  300. ),
  301. );
  302. FormInfo.instance.onChangeTargetValue.emit(
  303. this,
  304. TargetFormArgs(
  305. "Operation_History_True_Detail",
  306. isHidden: false,
  307. ),
  308. );
  309. } else if (type == UpdateFormType.Remove) {
  310. FormInfo.instance.onChangeTargetValue.emit(
  311. this,
  312. TargetFormArgs(
  313. "Operation_History_True_Detail",
  314. isHidden: true,
  315. ),
  316. );
  317. }
  318. }
  319. }
  320. void changeHeartAbnormal(UpdateFormArgs e) {
  321. onValueChange(e, "Heart_Abnormal_1", "Heart_Abnormal_Abnormality");
  322. }
  323. void changeLungAbnormal(UpdateFormArgs e) {
  324. onValueChange(e, "Lung_Abnormal_1", "Lung_Abnormal_Abnormality");
  325. }
  326. void changeVulvar(UpdateFormArgs e) {
  327. onValueChange(e, "Vulvar_1", "Vulvar_Abnormality");
  328. }
  329. void onVaginalDischargeChange(UpdateFormArgs e) {
  330. UpdateFormType type = e.type;
  331. bool isDisabledValue = false;
  332. if (type == UpdateFormType.Add && e.sourceValue == "Vaginal_Discharge_1") {
  333. ///选中了无,则禁用其他选项
  334. isDisabledValue = true;
  335. } else if (type == UpdateFormType.Remove &&
  336. e.sourceValue == "Vaginal_Discharge_1") {
  337. ///取消选中无,则取消禁用其他选项
  338. isDisabledValue = false;
  339. }
  340. FormInfo.instance.onChangeTargetValue.emit(
  341. this,
  342. TargetFormArgs(
  343. "Vaginal_Discharge_2",
  344. isDisabledValue: isDisabledValue,
  345. ),
  346. );
  347. FormInfo.instance.onChangeTargetValue.emit(
  348. this,
  349. TargetFormArgs(
  350. "Vaginal_Discharge_3",
  351. isDisabledValue: isDisabledValue,
  352. ),
  353. );
  354. FormInfo.instance.onChangeTargetValue.emit(
  355. this,
  356. TargetFormArgs(
  357. "Vaginal_Discharge_4",
  358. isDisabledValue: isDisabledValue,
  359. ),
  360. );
  361. }
  362. void onLastPeriodDateChange(UpdateFormArgs e) {
  363. var targetValue = calculateDueDateString(e.sourceValue);
  364. FormInfo.instance.formValue["EstimatedDeliveryDate"] = targetValue;
  365. FormInfo.instance.onChangeTargetValue.emit(
  366. this,
  367. TargetFormArgs(
  368. "EstimatedDeliveryDate",
  369. isDisabledValue: false,
  370. targetValue: targetValue,
  371. ),
  372. );
  373. }
  374. String calculateDueDateString(String lastMenstrualPeriodStr) {
  375. // 首先将输入字符串转换为DateTime对象
  376. DateTime lastMenstrualPeriod = DateTime.parse(lastMenstrualPeriodStr);
  377. // 计算预产期
  378. DateTime dueDate = DateTime(
  379. lastMenstrualPeriod.year,
  380. lastMenstrualPeriod.month + 9,
  381. lastMenstrualPeriod.day + 6,
  382. );
  383. dueDate = DateTime(
  384. dueDate.year + (dueDate.month > 12 ? 1 : 0), // 如果月份大于12,年份加一
  385. dueDate.month > 12
  386. ? dueDate.month - 12
  387. : dueDate.month, // 如果月份大于12,月份减去12
  388. dueDate.day, // 日子不变
  389. );
  390. dueDate = DateTime(
  391. dueDate.year,
  392. dueDate.month,
  393. dueDate.day > DateTime(dueDate.year, dueDate.month + 1, 0).day
  394. ? DateTime(dueDate.year, dueDate.month + 1, 0).day
  395. : dueDate.day,
  396. );
  397. // 将预产期DateTime对象转换回字符串格式
  398. String dueDateString =
  399. "${dueDate.year}-${dueDate.month.toString().padLeft(2, '0')}-${dueDate.day.toString().padLeft(2, '0')}";
  400. return dueDateString;
  401. }
  402. void onHealthHistoryChange(UpdateFormArgs e) {
  403. UpdateFormType type = e.type;
  404. bool isDisabledValue = false;
  405. if (type == UpdateFormType.Add && e.sourceValue == "Health_History_1") {
  406. ///选中了无,则禁用其他选项
  407. isDisabledValue = true;
  408. } else if (type == UpdateFormType.Remove &&
  409. e.sourceValue == "Health_History_1") {
  410. ///取消选中无,则取消禁用其他选项
  411. isDisabledValue = false;
  412. }
  413. FormInfo.instance.onChangeTargetValue.emit(
  414. this,
  415. TargetFormArgs(
  416. "Health_History_2",
  417. isDisabledValue: isDisabledValue,
  418. ),
  419. );
  420. FormInfo.instance.onChangeTargetValue.emit(
  421. this,
  422. TargetFormArgs(
  423. "Health_History_3",
  424. isDisabledValue: isDisabledValue,
  425. ),
  426. );
  427. FormInfo.instance.onChangeTargetValue.emit(
  428. this,
  429. TargetFormArgs(
  430. "Health_History_4",
  431. isDisabledValue: isDisabledValue,
  432. ),
  433. );
  434. FormInfo.instance.onChangeTargetValue.emit(
  435. this,
  436. TargetFormArgs(
  437. "Health_History_5",
  438. isDisabledValue: isDisabledValue,
  439. ),
  440. );
  441. FormInfo.instance.onChangeTargetValue.emit(
  442. this,
  443. TargetFormArgs(
  444. "Health_History_6",
  445. isDisabledValue: isDisabledValue,
  446. ),
  447. );
  448. FormInfo.instance.onChangeTargetValue.emit(
  449. this,
  450. TargetFormArgs(
  451. "Health_History_7",
  452. isDisabledValue: isDisabledValue,
  453. ),
  454. );
  455. }
  456. }