123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import 'dart:convert';
- import 'package:fis_common/extensions/string.dart';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/utils/datetime.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/managers/interfaces/follow_up.dart';
- import 'package:vitalapp/managers/interfaces/prescription.dart';
- import 'package:vitalapp/pages/check/follow_up/state.dart';
- import 'package:vitalapp/pages/check/models/form.dart';
- import 'package:vitalapp/pages/form/form_info.dart';
- import 'package:vitalapp/store/store.dart';
- class FollowUpController extends GetxController {
- FollowUpController();
- final state = FollowUpState();
- final _followUpManager = Get.find<IFollowUpManager>();
- final _prescriptionManager = Get.find<IPrescriptionManager>();
- late String patientCode = "";
- late String patientName = "";
- _initData() {
- update(["follow_up"]);
- // final p = Get.parameters;
- patientCode = Store.user.currentSelectPatientInfo?.code ?? '';
- patientName = Store.user.currentSelectPatientInfo?.patientName ?? '';
- }
- void onTap() {}
- List<MenuItem> menuList = [
- // MenuItem(label: "肺结核随访服务", value: 'FJHSFFW'),
- // MenuItem(label: "肺结核入户随访", value: 'FJHRHSF'),
- // MenuItem(label: "冠心病", value: 'GXB'),
- // MenuItem(label: "脑卒中", value: 'NCZ'),
- // MenuItem(label: "严重精神障碍随访服务", value: 'YZJSZASFFW'),
- // MenuItem(label: "严重精神障碍个人信息补充", value: 'YZJSZAGRXXBC'),
- MenuItem(label: "2 型糖尿病", value: 'TNB'),
- MenuItem(label: "高血压", value: 'GXY'),
- MenuItem(label: "老年人中医药健康管理服务记录表", value: 'LNRZYYJKGLFWJL'),
- // MenuItem(label: "老年人生活自理能力评估表", value: 'LNRSHZLNLPGB'),
- // MenuItem(label: "产后42天健康检查列表", value: 'YCF_CH42TJKJCLB'),
- // MenuItem(label: "产后访视列表", value: 'YCF_CHFSLB'),
- // MenuItem(label: "2~5次产前随访列表", value: 'YCF_2_5CCQSFLB'),
- // MenuItem(label: "第一次产前检查列表", value: 'YCF_DYCCQJCLB'),
- // MenuItem(label: "基本信息", value: 'YCF_JBXX'),
- // MenuItem(label: "儿童中医药健康管理列表", value: 'ET_ZYYJKGLLB'),
- MenuItem(label: "满月儿童健康检查", value: 'ET_1MSETJKJCLB'),
- MenuItem(label: "3月龄儿童健康检查", value: 'ET_3MSETJKJCLB'),
- MenuItem(label: "6月龄儿童健康检查", value: 'ET_6MSETJKJCLB'),
- MenuItem(label: "8月龄儿童健康检查", value: 'ET_8MSETJKJCLB'),
- MenuItem(label: "12月儿童健康检查", value: 'ET_12MSETJKJCLB'),
- MenuItem(label: "18月儿童健康检查", value: 'ET_18MSETJKJCLB'),
- MenuItem(label: "24月儿童健康检查", value: 'ET_24MSETJKJCLB'),
- MenuItem(label: "30月儿童健康检查", value: 'ET_30MSETJKJCLB'),
- MenuItem(label: "3岁儿童健康检查", value: 'ET_3SETJKJCLB'),
- MenuItem(label: "4岁儿童健康检查", value: 'ET_4SETJKJCLB'),
- MenuItem(label: "5岁儿童健康检查", value: 'ET_5SETJKJCLB'),
- MenuItem(label: "6岁儿童健康检查", value: 'ET_6SETJKJCLB'),
- // MenuItem(label: "1~2岁儿童健康检查列表", value: 'ET_1_2SETJKJCLB'),
- // MenuItem(label: "1岁内儿童健康检查列表", value: 'ET_1SNETJKJCLB'),
- // MenuItem(label: "新生儿访视列表", value: 'ET_XSEFSLB'),
- ];
- // @override
- // void onInit() {
- // super.onInit();
- // }
- ///校验严重精神障碍、糖尿病、高血压、肺结核等处方是否有填充数据
- Future<bool> _checkPrecription(Map<String, dynamic> value) async {
- var keys = FormInfo.instance.formValue.keys.toList();
- int targetLength = 3;
- if (Store.user.signature.isNotNullOrEmpty) {
- targetLength = 4;
- }
- if (value.length == targetLength &&
- keys.contains("PatientName") &&
- keys.contains("PatientGender") &&
- keys.contains("PatientAge")) {
- var age = DataTimeUtils.calculateAge(
- Store.user.currentSelectPatientInfo!.birthday!);
- var currentPatient = Store.user.currentSelectPatientInfo;
- String patientGender = "";
- if (currentPatient?.patientGender == GenderEnum.Male) {
- patientGender = "1";
- } else if (currentPatient?.patientGender == GenderEnum.Female) {
- patientGender = "2";
- }
- if (value["PatientName"] == currentPatient?.patientName &&
- value["PatientAge"] == age &&
- value["PatientGender"] == patientGender) {
- ///经和测试讨论,如果一个表格只存在默认填充的数据,则不提交
- return true;
- }
- }
- return false;
- }
- Future<bool> createFollowUp(
- key, templateCode, data, String prescriptionKey) async {
- bool isCalibrationPrescriptions = [
- "YZJSZASFFW",
- "FollowUpTuberculosisRecord",
- "GXY",
- "TNB"
- ].contains(key);
- ///校验随访和处方数据
- if (data.length < 7) {
- if (!isCalibrationPrescriptions ||
- (await _checkPrecription(FormInfo.instance.formValue))) {
- PromptBox.toast('不能提交空数据');
- return false;
- }
- }
- /// 校验本次随访时间不能晚于下次随访时间
- if (state.followUpTime != null &&
- state.nextFollowUpTime != null &&
- state.followUpTime!.isAfter(state.nextFollowUpTime!)) {
- PromptBox.toast('本次随访时间不能晚于下次随访时间');
- return false;
- }
- List<String> followUpPhotos = [];
- if (state.followUpPhoto?.isNotEmpty ?? false) {
- followUpPhotos = [state.followUpPhoto!];
- }
- var request = CreateFollowUpRequest(
- key: key,
- patientCode: patientCode,
- templateCode: templateCode,
- followUpData: data,
- followUpTime: state.followUpTime,
- nextFollowUpTime: state.nextFollowUpTime,
- followUpMode: state.followUpMode ?? FollowUpModeEnum.Outpatient,
- followUpPhotos: followUpPhotos,
- );
- print(jsonEncode(request.toJson()));
- final result = await _followUpManager.createFollowUp(request);
- if (result.isNotEmpty && prescriptionKey.isNotEmpty) {
- await createPrescription(result, prescriptionKey);
- PromptBox.toast('保存成功');
- }
- return true;
- }
- Future<String> createFollowUpOnly(
- String key, String templateCode, String data) async {
- List<String> followUpPhotos = [];
- if (state.followUpPhoto?.isNotEmpty ?? false) {
- followUpPhotos = [state.followUpPhoto!];
- }
- var request = CreateFollowUpRequest(
- key: key,
- patientCode: patientCode,
- templateCode: templateCode,
- followUpData: data,
- followUpTime: state.followUpTime,
- nextFollowUpTime: state.nextFollowUpTime,
- followUpMode: state.followUpMode ?? FollowUpModeEnum.Outpatient,
- followUpPhotos: followUpPhotos,
- );
- print(jsonEncode(request.toJson()));
- final result = await _followUpManager.createFollowUp(request);
- return result;
- }
- Future<String?> createPrescription(
- String followUpCode, String prescriptionKey) async {
- if (FormInfo.instance.formValue.isEmpty) {
- return null;
- }
- /// 创建处方
- String? prescriptionCode = await _prescriptionManager.createPrescription(
- patientCode: patientCode,
- followUpCode: followUpCode,
- prescriptionKey: prescriptionKey,
- prescriptionData: jsonEncode(FormInfo.instance.formValue),
- );
- FormInfo.instance.formValue.clear();
- return prescriptionCode;
- }
- @override
- void onReady() {
- super.onReady();
- _initData();
- }
- // @override
- // void onClose() {
- // super.onClose();
- // }
- }
|