controller.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import 'dart:convert';
  2. import 'package:fis_common/index.dart';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/managers/interfaces/follow_up.dart';
  6. import 'package:vitalapp/managers/interfaces/prescription.dart';
  7. import 'package:vitalapp/managers/interfaces/template.dart';
  8. import 'package:vitalapp/pages/check/prescription/pediatric_prescription_collection.dart';
  9. import 'package:vitalapp/pages/form/form_info.dart';
  10. import 'package:vitalapp/store/store.dart';
  11. import 'forms/antenatal_visit.dart';
  12. import 'forms/checkup_42_days.dart';
  13. import 'forms/first_form.dart';
  14. import 'forms/postpartum_follow_up.dart';
  15. import 'state.dart';
  16. class MaternalHealthManagementController extends GetxController {
  17. MaternalHealthManagementController();
  18. //第 1 次产前检查
  19. final String firstFollowUpkey = "MaternalHealthManagement";
  20. //第 2~5 次产前随访
  21. final String prenatalFollowupKey = "PrenatalFollowupServiceRecord";
  22. //产后访视
  23. final String postnatalVisitKey = "PostnatalVisitRecord";
  24. //产后42天随访
  25. final String postpartumHealthCheckup42DaysKey =
  26. "PostpartumHealthCheckup42Days";
  27. final _followUpManager = Get.find<IFollowUpManager>();
  28. final _templateManager = Get.find<ITemplateManager>();
  29. final _prescriptionManager = Get.find<IPrescriptionManager>();
  30. final state = MaternalHealthManagementState();
  31. List<List> offlineSyncTemp = [];
  32. ///是否处于编辑模式
  33. bool isEdit = false;
  34. ///当前选中的记录Code
  35. String recordCode = "";
  36. ///当前使用的模板Code
  37. String templateCode = "";
  38. FollowUpModeEnum followUpMode = FollowUpModeEnum.Outpatient;
  39. @override
  40. void onReady() {
  41. super.onReady();
  42. _initData();
  43. }
  44. Future<bool> save(String key) async {
  45. List<String> followUpPhotos = [];
  46. DateTime followUpTime = DateTime.now();
  47. String? followUpData;
  48. // if (FormInfo.instance.formValue.isEmpty) {
  49. // PromptBox.toast('不能提交空数据');
  50. // return false;
  51. // }
  52. followUpData = jsonEncode(FormInfo.instance.formValue);
  53. if (FormInfo.instance.formValue.containsKey("Form_Date")) {
  54. followUpTime = DateTime.parse(FormInfo.instance.formValue["Form_Date"]);
  55. }
  56. DateTime? nextFollowUpTime;
  57. if (FormInfo.instance.formValue.containsKey("Next_Follow_Up_Date")) {
  58. nextFollowUpTime =
  59. DateTime.parse(FormInfo.instance.formValue["Next_Follow_Up_Date"]);
  60. }
  61. String patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
  62. bool result = false;
  63. if (isEdit) {
  64. result = await _followUpManager.updateFollowUp(
  65. UpdateFollowUpRequest(
  66. key: key,
  67. followUpData: followUpData,
  68. followUpTime: followUpTime,
  69. nextFollowUpTime: nextFollowUpTime,
  70. followUpMode: followUpMode,
  71. followUpPhotos: followUpPhotos,
  72. code: recordCode,
  73. ),
  74. ) ??
  75. false;
  76. } else {
  77. String createResult = await _followUpManager.createFollowUp(
  78. CreateFollowUpRequest(
  79. key: key,
  80. patientCode: patientCode,
  81. templateCode: templateCode,
  82. followUpData: followUpData,
  83. followUpTime: followUpTime,
  84. nextFollowUpTime: nextFollowUpTime,
  85. followUpMode: followUpMode,
  86. followUpPhotos: followUpPhotos,
  87. ),
  88. );
  89. if (createResult.isNotEmpty) {
  90. recordCode = createResult;
  91. result = true;
  92. }
  93. }
  94. if (result) {
  95. getFollowUpRecordList();
  96. return true;
  97. }
  98. return false;
  99. }
  100. Future<void> getFollowUpRecordList() async {
  101. try {
  102. var patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
  103. var result = await _followUpManager.getFollowUpRecordList(
  104. [
  105. firstFollowUpkey,
  106. prenatalFollowupKey,
  107. postnatalVisitKey,
  108. postpartumHealthCheckup42DaysKey,
  109. ],
  110. patientCode,
  111. );
  112. List<FollowUpRecordDTO> followUpDTOList = [];
  113. followUpDTOList.addAll(result ?? []);
  114. state.followUpDTOList = followUpDTOList;
  115. } catch (e) {
  116. return;
  117. }
  118. }
  119. String getFollowUpValueByKey(FollowUpRecordDataDTO dto) {
  120. var key = dto.key;
  121. if (key == firstFollowUpkey) {
  122. return "第 1 次产前检查";
  123. } else if (key == prenatalFollowupKey) {
  124. Map datas = jsonDecode(dto.followUpData ?? '');
  125. if (datas.containsKey("times")) {
  126. int times = datas["times"] ?? 2;
  127. return "第 ${times} 次产前随访";
  128. }
  129. return "第 2~5 次产前随访";
  130. } else if (key == postnatalVisitKey) {
  131. return "产后访视";
  132. } else if (key == postpartumHealthCheckup42DaysKey) {
  133. return "产后 42 天健康检查";
  134. }
  135. return "";
  136. }
  137. Future<List<String>> sharePrescription(
  138. FollowUpRecordDataDTO dataDTO,
  139. ) async {
  140. List<String> previewUrlList = [];
  141. List<PrescriptionDTO>? prescriptionList =
  142. await getPrescriptionList(dataDTO.code!);
  143. for (PrescriptionDTO prescription in prescriptionList ?? []) {
  144. previewUrlList.add(prescription.previewUrl ?? "");
  145. }
  146. return previewUrlList;
  147. }
  148. Future<List<PrescriptionDTO>?> getPrescriptionList(
  149. String followUpCode) async {
  150. // 获取处方列表
  151. var patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
  152. List<PrescriptionDTO>? prescriptionList =
  153. await _prescriptionManager.getPrescriptionPage(
  154. patientCode: patientCode,
  155. followUpCode: followUpCode,
  156. );
  157. return prescriptionList;
  158. }
  159. ///跳转至随访页面
  160. void toCheckPage(FollowUpRecordDataDTO dataDto) {
  161. if (dataDto.followUpData.isNullOrEmpty) {
  162. return;
  163. }
  164. var datas = jsonDecode(dataDto.followUpData ?? '');
  165. if (datas is Map<String, dynamic>) {
  166. FormInfo.instance.formValue = datas;
  167. var key = dataDto.key;
  168. if (key == firstFollowUpkey) {
  169. Get.to(FirstMaternalHealthManagementForm(
  170. onClickPrescribe: () async {
  171. await Get.to(
  172. PrescriptionCollection(
  173. recordCode,
  174. isChild: false,
  175. ),
  176. );
  177. },
  178. ));
  179. } else if (key == prenatalFollowupKey) {
  180. int times = FormInfo.instance.formValue["times"] ?? 2;
  181. Get.to(AntenatalVisitForm(
  182. times,
  183. onClickPrescribe: () async {
  184. await Get.to(
  185. PrescriptionCollection(
  186. recordCode,
  187. isChild: false,
  188. ),
  189. );
  190. },
  191. ));
  192. } else if (key == postnatalVisitKey) {
  193. Get.to(PostpartumFormView(
  194. onClickPrescribe: () async {
  195. await Get.to(
  196. PrescriptionCollection(
  197. recordCode,
  198. isChild: false,
  199. ),
  200. );
  201. },
  202. ));
  203. } else if (key == postpartumHealthCheckup42DaysKey) {
  204. Get.to(PostpartumHealthCheckup42DaysForm(
  205. onClickPrescribe: () async {
  206. await Get.to(
  207. PrescriptionCollection(
  208. recordCode,
  209. isChild: false,
  210. ),
  211. );
  212. },
  213. ));
  214. }
  215. }
  216. }
  217. Future<String> getTemplate(String key) async {
  218. var templates =
  219. await _templateManager.readTemplateRelation('templateRelation');
  220. var templateRelation = jsonDecode(templates!);
  221. templateCode = templateRelation[key] ?? '';
  222. var template = await _templateManager.readTemplate(templateCode) ?? '';
  223. String templateContent =
  224. TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
  225. return templateContent;
  226. }
  227. void _initData() {
  228. getFollowUpRecordList();
  229. }
  230. }