123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- import 'package:fis_jsonrpc/rpc.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/global.dart';
- import 'package:vitalapp/managers/interfaces/diagnosis.dart';
- import 'package:vitalapp/managers/interfaces/patient.dart';
- import 'package:vitalapp/pages/controllers/home_nav_mixin.dart';
- import 'package:vitalapp/pages/facial_recognition/index.dart';
- import 'package:vitalapp/store/store.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'state.dart';
- class PatientDetailController extends FControllerBase with HomeNavMixin {
- final state = PatientDetailState();
- final _patientManager = Get.find<IPatientManager>();
- @override
- void onInit() {
- WidgetsBinding.instance.addPostFrameCallback(
- (timeStamp) async {
- await loadData();
- netChecker.onlineChangedEvent.addListener(_onlineChanged);
- },
- );
- super.onInit();
- }
- void _onlineChanged(_, e) {
- state.isOnline = e;
- }
- /// 打开信息页
- void gotoInfo() {
- Get.toNamed(
- "/patient/info",
- parameters: {"code": state.code},
- );
- }
- /// 打开精神障碍信息补充表
- void gotoMentalDisorderInfo() {
- Get.toNamed(
- "/patient/mental_disorder_info",
- parameters: {"code": state.code},
- );
- }
- /// 前往随访页
- void gotoFollowUp() {
- Get.toNamed(
- "/check/follow_up",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 前往随访记录页
- void gotoFollowUpRecord() {
- Get.toNamed(
- "/check/follow_up_record",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 前往高血压记录页面
- void gotoHypertensionRecord() {
- Get.toNamed(
- "/check/follow_up_record/hypertension",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 前往糖尿病记录页面
- void gotoDiabetesRecord() {
- Get.toNamed(
- "/check/follow_up_record/diabetes",
- );
- }
- ///前往严重精神障碍记录页面
- void gotoMentalDisorderRecord() {
- Get.toNamed(
- "/check/follow_up_record/mentalDisorder",
- );
- }
- ///check/follow_up_record/tuberculosis
- ///前往严重精神障碍记录页面
- void gototuberculosisRecord() {
- Get.toNamed(
- "check/follow_up_record/tuberculosis",
- );
- }
- /// 前往健康体检页
- void gotoHealthCheck() {
- Get.toNamed(
- "/check/form",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往签约页
- void gotoContract() {
- Get.toNamed(
- "/contract/package_list",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往转诊页
- void gotoReferral() {
- //
- }
- /// 前往健康检测页
- void gotoExam() {
- //
- Get.toNamed(
- "/medical",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往诊疗记录页
- void gotoExamRecord() {
- //
- Get.toNamed(
- "/medical/records",
- parameters: {"patientCode": state.code},
- );
- }
- ///前往体检记录
- void gotoHealthCheckRecord() {
- if (!kIsOnline) {
- PromptBox.toast("请检查网络连接");
- return;
- }
- Get.toNamed(
- "/check/healthCheckRecord",
- parameters: {"patientCode": state.code},
- );
- }
- /// 前往签约记录页
- void gotoContractRecords() async {
- await Get.toNamed(
- "/contract/contract_records",
- parameters: {"patientCode": state.code},
- );
- loadData();
- }
- ///前往中医体质记录
- void gotoTraditionalChineseMedicineConsitutionRecord() {
- Get.toNamed(
- "/TraditionalChineseMedicineConsitutionRecord",
- parameters: {"key": "LNRZYYJKGLFWJL"},
- );
- }
- ///前往自理能力评估记录页面
- void gotoSelfCareAbilityAssessment() {
- Get.toNamed(
- '/SelfCareAbilityAssessmentRecord',
- parameters: {"Key": "LNRZLNLPG"},
- );
- }
- void gotoMaternalHealthManagement() {
- Get.toNamed(
- '/MaternalHealthManagement',
- parameters: {"Key": "MaternalHealthManagement"},
- );
- }
- void gotoChildHealth() {
- Get.toNamed(
- "/check/follow_up_record/children",
- parameters: {"patientCode": state.code, "patientName": state.name},
- );
- }
- /// 人脸录入
- Future<void> queryIsNeedFaceInput() async {
- var dto = await getPatientDto(Store.user.currentSelectPatientInfo!.cardNo!);
- await onFaceEntryClicked(dto);
- Get.back();
- }
- /// 点击录入人脸
- Future<void> onFaceEntryClicked(PatientDTO? dto) async {
- bool? result = await Get.to<bool>(
- () => FacialRecognitionPage(
- mode: FacialRecognitionMode.faceInput,
- patientInfo: dto,
- ),
- );
- if (result != null && result) {
- await loadData();
- PromptBox.toast('人脸数据存入成功');
- }
- }
- Future<PatientDTO?> getPatientDto(String patientCode) async {
- try {
- final dto = await _patientManager.getDetail(patientCode);
- return dto;
- } catch (e) {
- return null;
- }
- }
- Future<void> updatePatient() async {
- try {
- final dto = await _patientManager.getDetail(state.dto.code!);
- if (dto == null) {
- return;
- }
- UpdatePatientRequest2 request = UpdatePatientRequest2(
- token: Store.user.token,
- code: dto.code,
- patientName: dto.patientName,
- phone: dto.phone,
- emergencyName: dto.emergencyName,
- emergencyPhone: dto.emergencyPhone,
- cardNo: dto.cardNo,
- nationality: dto.nationality,
- birthday: dto.birthday,
- cardType: dto.cardType,
- patientGender: dto.patientGender,
- patientAddress: dto.patientAddress,
- crowdLabels: _patientManager.crowdLabelsConvert(state.labels),
- permanentResidenceAddress: dto.permanentResidenceAddress,
- );
- _patientManager.updatePatientAsync(request);
- } catch (e) {
- logger.e("PatientDetailController updatePatient:${e}");
- }
- }
- Future<void> loadData({String code = ''}) async {
- PatientDTO? dto;
- if (code.isNotEmpty) {
- dto = await getPatientDto(code);
- } else if (Store.user.currentSelectPatientInfo != null &&
- Store.user.currentSelectPatientInfo!.code != null) {
- dto = await getPatientDto(Store.user.currentSelectPatientInfo!.code!);
- // if (kDebugMode && (dto!.crowdLabels?.isEmpty ?? true)) {
- // dto.crowdLabels = ["RQFL_LNR", "CJJB_GXY_Suspected", "CJJB_TNB"];
- // }
- } else if (Store.user.currentSelectPatientInfo != null &&
- Store.user.currentSelectPatientInfo!.cardNo != null) {
- dto = await getPatientDto(Store.user.currentSelectPatientInfo!.cardNo!);
- }
- if (dto != null) {
- state.code = dto.code ?? '';
- dto.birthday = dto.birthday!.toLocal();
- state.updateDto(dto);
- } else if (state.dto.phone == "UNLOAD") {
- state.dto.phone = "";
- state.updateDto(state.dto);
- }
- }
- Future<bool> setCrowdLabelsAsync(
- List<String> carowLabels, List<String> crowdNames) async {
- final result =
- await _patientManager.setCrowdLabelsAsync(state.code, carowLabels);
- if (result) {
- state.updateCrowd(carowLabels, crowdNames);
- }
- return result;
- }
- IDiagnosisManager _diagnosisManager = Get.find<IDiagnosisManager>();
- /// 读取到最近检测记录的数据
- Future<void> onReadLastRecordInfo() async {
- try {
- var lastRecordInfo = await _diagnosisManager.getLastRecordInfo();
- if (lastRecordInfo != null) {
- state.isExistLocalData = lastRecordInfo.isExistLocalData ?? false;
- state.currentDiagnosis = await _diagnosisManager
- .getTableData(lastRecordInfo, isLastRecord: true);
- } else {
- state.currentDiagnosis = [];
- }
- } catch (e) {
- logger.e('PatientDetailController onReadLastRecordInfo.', e);
- }
- }
- @override
- void onClose() {
- netChecker.onlineChangedEvent.removeListener(_onlineChanged);
- }
- }
|