123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 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<IExamManager>();
- final state = ExaminationState();
- String batchNumber;
- _initData() {
- update(["examination"]);
- // getBatchNumber();
- }
- // Future<void> getBatchNumber() async {
- // var cachedBatchNumber = await readCachedBatchNumber();
- // if (cachedBatchNumber != null) {
- // batchNumber = cachedBatchNumber;
- // } else {
- // await saveCachedBatchNumber();
- // }
- // }
- // Future<bool?> saveCachedBatchNumber() async {
- // batchNumber = const Uuid().v4().replaceAll('-', '');
- // TextStorage cachedRecord = TextStorage(
- // fileName: 'batchNumber',
- // directory: "patient/$patientCode",
- // );
- // return cachedRecord.save(batchNumber ?? "");
- // }
- Future<String?> readCachedBatchNumber() async {
- TextStorage cachedRecord = TextStorage(
- fileName: 'batchNumber',
- directory: "patient/$patientCode",
- );
- return cachedRecord.read();
- }
- List<MenuItem> 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<void> 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<bool> 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<void> 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();
- }
- }
|