123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/defines.dart';
- import 'package:vitalapp/architecture/network_connectivity.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/global.dart';
- import 'package:vitalapp/managers/interfaces/device.dart';
- import 'package:vitalapp/managers/interfaces/models/device.dart';
- import 'package:vitalapp/managers/interfaces/models/patient_model_dto.dart';
- import 'package:vitalapp/managers/interfaces/patient.dart';
- import 'package:vitalapp/managers/interfaces/permission.dart';
- import 'package:vitalapp/pages/controllers/blue_location_mixin.dart';
- import 'package:vitalapp/pages/controllers/crowd_labels.dart';
- import 'package:vitalapp/pages/facial_recognition/index.dart';
- import 'package:vitalapp/pages/home/controller.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'package:vitalapp/pages/id_card_scan/index.dart';
- import 'package:vitalapp/pages/patient/bluetooth_card_reader/index.dart';
- import 'package:vitalapp/pages/patient/card_reader/index.dart';
- import 'package:vitalapp/pages/patient/create/widgets/face_result_dialog.dart';
- import 'package:vitalapp/store/store.dart';
- import 'package:vnote_device_plugin/consts/types.dart';
- import 'state.dart';
- class PatientListController extends FControllerBase
- with BluetoothAndLocationMixin {
- final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
- final state = PatientListState();
- final _homeController = Get.find<HomeController>();
- final _patientManager = Get.find<IPatientManager>();
- final _deviceManager = Get.find<IDeviceManager>();
- final crowdLabelsController = CrowdLabelsController();
- // enum ContractStateEnum {
- // Unsigned,
- // Cancelled,
- // Expired,
- // Signed,
- // Voided,
- // Refused,
- // }
- final Map<String, String> ContractStateMap = {
- "All": "未选择",
- "Unsigned": "未签约",
- "Cancelled": "已取消",
- "Expired": "已过期",
- "Signed": "已签约",
- "Voided": "已失效",
- "Refused": "已拒绝",
- };
- void patientListGotoDetail(PatientDTO dto) async {
- await _patientManager.switchCurrentPatient(dto);
- _homeController.switchNavByName("/patient/detail");
- logger.i('list切换居民 当前居民是:${dto.patientName} 居民code:${dto.code}');
- }
- Future<DeviceModel?> getDevice(String type) async {
- List<DeviceModel> devices = await _deviceManager.getDeviceList();
- return devices.firstWhereOrNull((element) => element.type == type);
- }
- // TODO 人脸录入 点击人脸识别
- void onFaceIdLoginClicked() async {
- var verifyResult = await _verifyCameraPermissions();
- if (!verifyResult) {
- return;
- }
- final FaceRecognitionResult? result = await Get.to<FaceRecognitionResult>(
- () => const FacialRecognitionPage(
- mode: FacialRecognitionMode.faceRecognition,
- ),
- );
- if (result != null && result.success) {
- final patient = result.patientInfo;
- final hasConfirmed = await FaceResultDialog.show(patient, true);
- if (hasConfirmed &&
- patient.createdOrgCode == Store.user.organizationCode) {
- await _checkinPatient(patient);
- }
- } else {
- print("识别取消");
- }
- }
- /// 切换当前登记居民
- Future<void> _checkinPatient(PatientBaseDTO patient) async {
- final patientDTO = PatientDTO(
- code: patient.cardNo,
- cardNo: patient.cardNo,
- patientName: patient.patientName,
- nationality: patient.nationality,
- patientGender: patient.patientGender,
- birthday: patient.birthday,
- patientAddress: patient.patientAddress,
- );
- await onIdcardInfoIsCreateRecord(patientDTO.code!);
- Get.find<HomeController>().switchNavByName("/patient/detail");
- }
- /// (读卡器读卡)若已建档则跳档案详情页面,若未建档则跳创建档案页面
- void onReadCardClickedToDetail() async {
- final DeviceModel? device = await getDevice(DeviceTypes.IC_READER);
- CardReaderResult? result;
- if (device != null) {
- final envPassed = await checkDeviceConnectEnv();
- if (envPassed) {
- result = await Get.dialog<CardReaderResult>(
- const BluetoothCardReaderDialog(),
- barrierDismissible: false,
- );
- }
- } else {
- result = await Get.dialog<CardReaderResult>(
- const CardReaderDialog(),
- barrierDismissible: false,
- );
- }
- if (result != null && result.success) {
- PromptBox.toast("读取成功");
- PatientBaseDTO patientInfo = PatientBaseDTO();
- patientInfo.cardNo = result.cardNo; // 回填身份证号
- patientInfo.patientName = result.name; // 回填姓名
- patientInfo.patientGender = result.gender; // 回填性别
- patientInfo.nationality = result.nation; // 回填民族
- patientInfo.birthday = result.birthday; // 回填出生日期
- patientInfo.patientAddress = result.address; // 回填户籍地址
- onIdcardInfoIsCreateRecord(patientInfo.cardNo!, patientInfo);
- } else {
- print("读卡取消");
- }
- }
- /// 手动录入 跳转新建档案页面
- void onManualInputPatient() {
- Get.find<HomeController>().switchNavByName(
- "/patient/create",
- );
- }
- /// 扫码和刷卡公用的方法,获取到的身份证信息
- Future<void> onIdcardInfoIsCreateRecord(
- String cardNo, [
- PatientBaseDTO? patientInfo,
- ]) async {
- PatientDTO? patientInfoDto = await _patientManager.getDetail(cardNo);
- if (patientInfoDto != null) {
- await _patientManager.switchCurrentPatient(patientInfoDto);
- logger.i(
- 'create居民 当前居民是:${patientInfoDto.patientName} 居民code:${patientInfoDto.code}');
- }
- switchOrCreatePatient(patientInfoDto, patientInfo);
- }
- /// (拍摄扫描身份证)若已建档则跳档案详情页面,若未建档则跳创建档案页面
- void onIdCardScanClickedToDetail() async {
- var verifyResult = await _verifyCameraPermissions();
- if (!verifyResult) {
- return;
- }
- final IdCardScanResult? result = await Get.to<IdCardScanResult>(
- () => const IdCardScanPage(),
- );
- if (result != null && result.success) {
- PromptBox.toast("身份证信息识别成功");
- PatientBaseDTO patientInfo = result.patientBaseDTO;
- onIdcardInfoIsCreateRecord(patientInfo.cardNo!, patientInfo);
- } else {
- print("识别取消");
- }
- }
- /// 切换居民还是新建居民
- Future<void> switchOrCreatePatient(
- PatientDTO? patientInfoDto, [
- PatientBaseDTO? patientInfo,
- ]) async {
- if (patientInfo != null) {
- if (patientInfoDto != null) {
- final hasConfirmed = await FaceResultDialog.show(patientInfo, true);
- if (!hasConfirmed) {
- return;
- }
- Get.find<HomeController>().switchNavByName("/patient/detail");
- } else {
- final hasConfirmed = await FaceResultDialog.show(patientInfo, false);
- if (!hasConfirmed) {
- return;
- }
- Get.find<HomeController>().switchNavByName(
- "/patient/create",
- patientInfo.toJson(),
- );
- }
- }
- }
- void changeFilterFounder(int value) {
- state.selectBoxFilterFounder = value;
- }
- Future<bool> _verifyCameraPermissions() async {
- IPermissionManager permissionManager = Get.find<IPermissionManager>();
- var isCameraPermissions =
- await permissionManager.requestCameraPermissions();
- if (!isCameraPermissions) {
- await Get.dialog(
- VAlertDialog(
- title: "提示",
- width: 420,
- content: Container(
- height: 32,
- padding: const EdgeInsets.symmetric(horizontal: 24),
- alignment: Alignment.center,
- child: const Text(
- "未授予相机权限,前去设置",
- style: TextStyle(fontSize: 20),
- ),
- ),
- showCancel: false,
- onConfirm: () async {
- Get.back();
- await permissionManager.openAppSettingsAsync();
- },
- ),
- barrierDismissible: false,
- barrierColor: Colors.black.withOpacity(.4),
- );
- }
- return isCameraPermissions;
- }
- @override
- void onReady() {
- netChecker.onlineChangedEvent.addListener(_onlineChanged);
- if (Store.user.roleName == "机构负责人") {
- state.selectBoxFilterFounder = 1;
- }
- reloadList();
- super.onReady();
- }
- void _onlineChanged(_, e) {
- state.isOnline = e;
- }
- /// 重新加载列表
- Future<void> reloadList({bool isFilter = false}) async {
- busy = true;
- state.pageIndex = 0;
- state.dataList = [];
- state.offlineCodes = [];
- if (kIsOnline) {
- if (!kIsWeb) {
- var offlineList = await _patientManager.getPagedOfflineList(
- state.searchString,
- state.startTime.value,
- state.endTime.value?.add(const Duration(days: 1)),
- );
- if (offlineList != null) {
- state.appendDataList(offlineList);
- state.offlineCodes = offlineList.map((e) => e.code!).toList();
- }
- }
- }
- await loadNextPageList(isFilter: isFilter);
- if (kIsOnline) {
- _loadStatistic();
- }
- }
- /// 加载下一页列表
- Future<void> loadNextPageList({bool isFilter = false}) async {
- busy = true;
- final request = PatientPageRequest(
- pageIndex: state.pageIndex + 1,
- pageSize: state.pageSize,
- keyword: state.searchString,
- startTime: state.startTime.value,
- endTime: state.endTime.value?.add(const Duration(days: 1)),
- crowdLabels: crowdLabelsController.state.isAllSelect
- ? [
- "RQFL_ET",
- "RQFL_YF",
- "RQFL_LNR",
- "CJJB_GXY",
- "CJJB_TNB",
- "CJJB_YZJSBZA",
- "CJJB_FJH"
- ]
- : crowdLabelsController.state.selectedCodes.length == 0
- ? null
- : crowdLabelsController.state.selectedCodes,
- createdBySelf: state.selectBoxFilterFounder == 0,
- contractState: state.contractStateSelectedItem,
- );
- final pagedList = await _patientManager.getPagedList(request);
- if (pagedList != null) {
- state.totalCount = pagedList.dataCount;
- if (pagedList.pageData != null) {
- state.pageIndex = state.pageIndex + 1;
- final arr = <PatientModelDTO>[];
- for (var element in pagedList.pageData!) {
- if (!state.offlineCodes.contains(element.code)) {
- var existData =
- state.dataList.firstWhereOrNull((e) => e.code == element.code);
- if (existData == null) {
- arr.add(element);
- }
- }
- }
- state.appendDataList(arr);
- }
- }
- busy = false;
- }
- Future<void> removePatient(String code) async {
- setBusy("正在删除...");
- final result = await _patientManager.removePatient(code);
- cancelBusy();
- if (result) {
- PromptBox.toast("删除成功");
- await Future.delayed(const Duration(milliseconds: 500));
- await reloadList();
- } else {
- PromptBox.toast("删除失败");
- }
- }
- Future<void> _loadStatistic() async {
- final result = await _patientManager.getStatistic(
- state.selectBoxFilterFounder == 0,
- );
- state.statisticTodayCount = result.todayCount;
- state.statisticTotalCount = result.count;
- }
- @override
- void onClose() {
- netChecker.onlineChangedEvent.removeListener(_onlineChanged);
- }
- }
|