controller.dart 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. import 'dart:convert';
  2. import 'package:fis_common/extensions/string.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/architecture/utils/datetime.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import 'package:vitalapp/managers/interfaces/follow_up.dart';
  8. import 'package:vitalapp/managers/interfaces/prescription.dart';
  9. import 'package:vitalapp/pages/check/follow_up/state.dart';
  10. import 'package:vitalapp/pages/check/models/form.dart';
  11. import 'package:vitalapp/pages/form/form_info.dart';
  12. import 'package:vitalapp/store/store.dart';
  13. class FollowUpController extends GetxController {
  14. FollowUpController();
  15. final state = FollowUpState();
  16. final _followUpManager = Get.find<IFollowUpManager>();
  17. final _prescriptionManager = Get.find<IPrescriptionManager>();
  18. late String patientCode = "";
  19. late String patientName = "";
  20. _initData() {
  21. update(["follow_up"]);
  22. // final p = Get.parameters;
  23. patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
  24. patientName = Store.user.currentSelectPatientInfo?.patientName ?? '';
  25. }
  26. void onTap() {}
  27. List<MenuItem> menuList = [
  28. // MenuItem(label: "肺结核随访服务", value: 'FJHSFFW'),
  29. // MenuItem(label: "肺结核入户随访", value: 'FJHRHSF'),
  30. // MenuItem(label: "冠心病", value: 'GXB'),
  31. // MenuItem(label: "脑卒中", value: 'NCZ'),
  32. // MenuItem(label: "严重精神障碍随访服务", value: 'YZJSZASFFW'),
  33. // MenuItem(label: "严重精神障碍个人信息补充", value: 'YZJSZAGRXXBC'),
  34. MenuItem(label: "2 型糖尿病", value: 'TNB'),
  35. MenuItem(label: "高血压", value: 'GXY'),
  36. MenuItem(label: "老年人中医药健康管理服务记录表", value: 'LNRZYYJKGLFWJL'),
  37. // MenuItem(label: "老年人生活自理能力评估表", value: 'LNRSHZLNLPGB'),
  38. // MenuItem(label: "产后42天健康检查列表", value: 'YCF_CH42TJKJCLB'),
  39. // MenuItem(label: "产后访视列表", value: 'YCF_CHFSLB'),
  40. // MenuItem(label: "2~5次产前随访列表", value: 'YCF_2_5CCQSFLB'),
  41. // MenuItem(label: "第一次产前检查列表", value: 'YCF_DYCCQJCLB'),
  42. // MenuItem(label: "基本信息", value: 'YCF_JBXX'),
  43. // MenuItem(label: "儿童中医药健康管理列表", value: 'ET_ZYYJKGLLB'),
  44. MenuItem(label: "满月儿童健康检查", value: 'ET_1MSETJKJCLB'),
  45. MenuItem(label: "3月龄儿童健康检查", value: 'ET_3MSETJKJCLB'),
  46. MenuItem(label: "6月龄儿童健康检查", value: 'ET_6MSETJKJCLB'),
  47. MenuItem(label: "8月龄儿童健康检查", value: 'ET_8MSETJKJCLB'),
  48. MenuItem(label: "12月儿童健康检查", value: 'ET_12MSETJKJCLB'),
  49. MenuItem(label: "18月儿童健康检查", value: 'ET_18MSETJKJCLB'),
  50. MenuItem(label: "24月儿童健康检查", value: 'ET_24MSETJKJCLB'),
  51. MenuItem(label: "30月儿童健康检查", value: 'ET_30MSETJKJCLB'),
  52. MenuItem(label: "3岁儿童健康检查", value: 'ET_3SETJKJCLB'),
  53. MenuItem(label: "4岁儿童健康检查", value: 'ET_4SETJKJCLB'),
  54. MenuItem(label: "5岁儿童健康检查", value: 'ET_5SETJKJCLB'),
  55. MenuItem(label: "6岁儿童健康检查", value: 'ET_6SETJKJCLB'),
  56. // MenuItem(label: "1~2岁儿童健康检查列表", value: 'ET_1_2SETJKJCLB'),
  57. // MenuItem(label: "1岁内儿童健康检查列表", value: 'ET_1SNETJKJCLB'),
  58. // MenuItem(label: "新生儿访视列表", value: 'ET_XSEFSLB'),
  59. ];
  60. // @override
  61. // void onInit() {
  62. // super.onInit();
  63. // }
  64. ///校验严重精神障碍、糖尿病、高血压、肺结核等处方是否有填充数据
  65. Future<bool> _checkPrecription(Map<String, dynamic> value) async {
  66. var keys = FormInfo.instance.formValue.keys.toList();
  67. int targetLength = 3;
  68. if (Store.user.signature.isNotNullOrEmpty) {
  69. targetLength = 4;
  70. }
  71. if (value.length == targetLength &&
  72. keys.contains("PatientName") &&
  73. keys.contains("PatientGender") &&
  74. keys.contains("PatientAge")) {
  75. var age = DataTimeUtils.calculateAge(
  76. Store.user.currentSelectPatientInfo!.birthday!);
  77. var currentPatient = Store.user.currentSelectPatientInfo;
  78. String patientGender = "";
  79. if (currentPatient?.patientGender == GenderEnum.Male) {
  80. patientGender = "1";
  81. } else if (currentPatient?.patientGender == GenderEnum.Female) {
  82. patientGender = "2";
  83. }
  84. if (value["PatientName"] == currentPatient?.patientName &&
  85. value["PatientAge"] == age &&
  86. value["PatientGender"] == patientGender) {
  87. ///经和测试讨论,如果一个表格只存在默认填充的数据,则不提交
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. Future<bool> createFollowUp(
  94. key, templateCode, data, String prescriptionKey) async {
  95. bool isCalibrationPrescriptions = [
  96. "YZJSZASFFW",
  97. "FollowUpTuberculosisRecord",
  98. "GXY",
  99. "TNB"
  100. ].contains(key);
  101. ///校验随访和处方数据
  102. if (data.length < 7) {
  103. if (!isCalibrationPrescriptions ||
  104. (await _checkPrecription(FormInfo.instance.formValue))) {
  105. PromptBox.toast('不能提交空数据');
  106. return false;
  107. }
  108. }
  109. /// 校验本次随访时间不能晚于下次随访时间
  110. if (state.followUpTime != null &&
  111. state.nextFollowUpTime != null &&
  112. state.followUpTime!.isAfter(state.nextFollowUpTime!)) {
  113. PromptBox.toast('本次随访时间不能晚于下次随访时间');
  114. return false;
  115. }
  116. List<String> followUpPhotos = [];
  117. if (state.followUpPhoto?.isNotEmpty ?? false) {
  118. followUpPhotos = [state.followUpPhoto!];
  119. }
  120. var request = CreateFollowUpRequest(
  121. key: key,
  122. patientCode: patientCode,
  123. templateCode: templateCode,
  124. followUpData: data,
  125. followUpTime: state.followUpTime,
  126. nextFollowUpTime: state.nextFollowUpTime,
  127. followUpMode: state.followUpMode ?? FollowUpModeEnum.Outpatient,
  128. followUpPhotos: followUpPhotos,
  129. );
  130. print(jsonEncode(request.toJson()));
  131. final result = await _followUpManager.createFollowUp(request);
  132. if (result.isNotEmpty && prescriptionKey.isNotEmpty) {
  133. await createPrescription(result, prescriptionKey);
  134. PromptBox.toast('保存成功');
  135. }
  136. return true;
  137. }
  138. Future<String> createFollowUpOnly(
  139. String key, String templateCode, String data) async {
  140. List<String> followUpPhotos = [];
  141. if (state.followUpPhoto?.isNotEmpty ?? false) {
  142. followUpPhotos = [state.followUpPhoto!];
  143. }
  144. var request = CreateFollowUpRequest(
  145. key: key,
  146. patientCode: patientCode,
  147. templateCode: templateCode,
  148. followUpData: data,
  149. followUpTime: state.followUpTime,
  150. nextFollowUpTime: state.nextFollowUpTime,
  151. followUpMode: state.followUpMode ?? FollowUpModeEnum.Outpatient,
  152. followUpPhotos: followUpPhotos,
  153. );
  154. print(jsonEncode(request.toJson()));
  155. final result = await _followUpManager.createFollowUp(request);
  156. return result;
  157. }
  158. Future<String?> createPrescription(
  159. String followUpCode, String prescriptionKey) async {
  160. if (FormInfo.instance.formValue.isEmpty) {
  161. return null;
  162. }
  163. /// 创建处方
  164. String? prescriptionCode = await _prescriptionManager.createPrescription(
  165. patientCode: patientCode,
  166. followUpCode: followUpCode,
  167. prescriptionKey: prescriptionKey,
  168. prescriptionData: jsonEncode(FormInfo.instance.formValue),
  169. );
  170. FormInfo.instance.formValue.clear();
  171. return prescriptionCode;
  172. }
  173. @override
  174. void onReady() {
  175. super.onReady();
  176. _initData();
  177. }
  178. // @override
  179. // void onClose() {
  180. // super.onClose();
  181. // }
  182. }