import 'dart:io'; import 'package:fis_jsonrpc/rpc.dart'; import 'package:get/get.dart'; import 'package:path_provider/path_provider.dart'; import 'package:vitalapp/architecture/storage/text_storage.dart'; import 'package:vitalapp/architecture/utils/prompt_box.dart'; import 'package:vitalapp/global.dart'; import 'package:vitalapp/managers/interfaces/exam.dart'; import 'package:vitalapp/pages/check/examination/state.dart'; import 'package:vitalapp/pages/check/models/form.dart'; class ExaminationController extends GetxController { ExaminationController({ required this.patientCode, required this.batchNumber, }); String patientCode; final _examManager = Get.find(); final state = ExaminationState(); String batchNumber; _initData() { update(["examination"]); // getBatchNumber(); } // Future getBatchNumber() async { // var cachedBatchNumber = await readCachedBatchNumber(); // if (cachedBatchNumber != null) { // batchNumber = cachedBatchNumber; // } else { // await saveCachedBatchNumber(); // } // } // Future saveCachedBatchNumber() async { // batchNumber = const Uuid().v4().replaceAll('-', ''); // TextStorage cachedRecord = TextStorage( // fileName: 'batchNumber', // directory: "patient/$patientCode", // ); // return cachedRecord.save(batchNumber ?? ""); // } Future readCachedBatchNumber() async { TextStorage cachedRecord = TextStorage( fileName: 'batchNumber', directory: "patient/$patientCode", ); return cachedRecord.read(); } List menuList = [ MenuItem(label: "一般状况", value: 'ZZYBZK'), MenuItem(label: "辅助检查", value: 'FZJC'), MenuItem(label: "生活方式", value: 'SHFS'), MenuItem(label: "脏器及查体", value: 'ZQCT'), MenuItem(label: "现存主要健康问题", value: 'XCZYWT'), MenuItem(label: "住院及用药情况", value: 'ZYYYFMYGHYFJZS'), MenuItem(label: "健康评价及指导", value: 'JKPJJZD'), ]; Future createOrUpdateExam(key, templateCode, data, isMuanual) async { if (!kIsOnline) { // TODO: 暂不支持离线体检 PromptBox.toast("请检查网络连接"); return; } TextStorage template = TextStorage( fileName: key, directory: "patient/$patientCode/exam", ); if (!isMuanual) { final cachedData = await template.read(); if (cachedData == data) { // 无改动 return; } } var result = await _examManager.createExam(CreateExamRequest( key: key, patientCode: patientCode, templateCode: templateCode, examData: data, batchNumber: batchNumber, )); if (result ?? false) { try { await template.save(data); PromptBox.toast('保存成功'); } catch (err) { PromptBox.toast('保存失败'); } } } /// 检查数据是否为空 Future checkExamEmpty() async { try { final root = await getExternalStorageDirectory(); final dir = Directory("${root!.path}/patient/$patientCode/exam"); if (await dir.exists()) { final files = dir.listSync(); return files.isEmpty; } else { return true; } } catch (e) { return false; } } // Future deleteCached() async { // saveCachedBatchNumber(); // TextStorage template = TextStorage( // fileName: '', // directory: "patient/$patientCode/exam", // ); // final result = await template.deleteDirectory(); // if (result) { // PromptBox.toast('本轮体检已结束'); // Get.back(); // } // } @override void onReady() { _initData(); super.onReady(); } }