123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824 |
- import 'dart:convert';
- import 'package:fis_common/event/event_type.dart';
- import 'package:fis_common/index.dart';
- import 'package:fis_common/logger/logger.dart';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_easyloading/flutter_easyloading.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/utils/advance_debounce.dart';
- import 'package:vitalapp/architecture/utils/datetime.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/components/appbar.dart';
- import 'package:vitalapp/components/button.dart';
- import 'package:vitalapp/components/scroll_list.dart';
- import 'package:vitalapp/components/table/table_column.dart';
- import 'package:vitalapp/managers/interfaces/diagnosis.dart';
- import 'package:vitalapp/managers/interfaces/models/diagnosis_aggregation_record_model.dart';
- import 'package:vitalapp/managers/interfaces/patient.dart';
- import 'package:vitalapp/managers/interfaces/prescription.dart';
- import 'package:vitalapp/managers/interfaces/registration.dart';
- import 'package:vitalapp/pages/check/examination/controller.dart';
- import 'package:vitalapp/pages/check/examination/view.dart';
- import 'package:vitalapp/pages/check/prescription/examination_prescription.dart';
- import 'package:vitalapp/pages/check/prescription/prescription_form_keys.dart';
- import 'package:vitalapp/pages/medical/controller.dart';
- import 'package:vitalapp/pages/medical/views/exam_medical.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/controller.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/state/list.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/widgets/form/index.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/widgets/report/report_preview.dart';
- import 'package:vitalapp/pages/medical_checkup_station/usb_print/module/printer_info.dart';
- import 'package:vitalapp/pages/medical_checkup_station/usb_print/page/temp/print_preview.dart';
- import 'package:vitalapp/pages/widgets/overflow_tooltip_wrapper.dart';
- import 'package:vitalapp/store/store.dart';
- class RegistrationListController {
- late RegistrationController registrationController;
- RegistrationListController(RegistrationController controller) {
- registrationController = controller;
- }
- final state = ListState();
- final _registrationManager = Get.find<IRegistrationManager>();
- final _prescriptionManager = Get.find<IPrescriptionManager>();
- ResidentModel currentResident = ResidentModel(idNumber: "");
- List<String> _allExam = [
- "HEIBasic",
- "HEIUrinalysis",
- "HEIUltrasonic",
- "HEIBiochemical",
- "HEIBloodRoutine",
- "HEIECG",
- "HEITCMC"
- ];
- Map<String, dynamic> examData = {};
- List<String> noMedicalCheckUpList() {
- List<String> noCheckUpList = _allExam
- .where((element) =>
- !(currentResident.finishedExamKeys ?? []).contains(element))
- .toList();
- return noCheckUpList;
- }
- List<String> medicalCheckUpList() {
- List<String> checkUpList = _allExam
- .where((element) =>
- (currentResident.finishedExamKeys ?? []).contains(element))
- .toList();
- return checkUpList;
- }
- /// 是否有健康检测的页面权限
- bool _hasHealthMonitor() {
- bool hasAuth = false;
- Store.user.menuPermissionList?.forEach((element) {
- if (element.code == "JKJC") {
- hasAuth = true;
- }
- });
- return hasAuth;
- }
- Future<void> getRegisterInfoPage({
- int? pageSize = 10,
- int? pageIndex = 1,
- String? keyword = "",
- }) async {
- registrationController.tableLoading = true;
- registrationController.currPageIndex = pageIndex!;
- var result = await registrationController.registrationManager
- .getRegisterInfoPageAsync(
- pageSize: pageSize,
- pageIndex: pageIndex,
- keyword: keyword,
- startTime: state.startTime,
- endTime: state.endTime,
- );
- List<ResidentModel> _residentList = [];
- if (result?.pageData != null) {
- for (RegisterInfoDTO i in result!.pageData!) {
- String statusStr = '';
- ExamStateEnum status = i.state;
- switch (status) {
- case ExamStateEnum.Unchecked:
- statusStr = "未体检";
- break;
- case ExamStateEnum.Invalid:
- statusStr = "已作废";
- break;
- case ExamStateEnum.Inspected:
- statusStr = "体检中";
- break;
- case ExamStateEnum.Reported:
- statusStr = "已报告";
- break;
- }
- _residentList.add(
- ResidentModel(
- name: i.name ?? '',
- idNumber: i.iDCardNo ?? '',
- code: i.code ?? '',
- homeAddress: i.adress,
- age: getAgeOfIdNumber(i.iDCardNo ?? ''),
- physicalExamNumber: i.physicalExamNumber,
- phone: i.phone,
- finishedExamKeys: i.finishedExamKeys,
- physicalExamStatus: statusStr,
- birthDay: i.birthday?.toLocal(),
- sex: i.sex,
- batchNumber: i.batchNumber,
- resultsAndSuggestions: i.resultsAndSuggestions,
- createdDoctorName: i.createdDoctorName,
- physicalExamTime: i.updateTime,
- ),
- );
- }
- registrationController.appointmentModelListLength = result.totalCount;
- } else {
- registrationController.appointmentModelListLength = 0;
- }
- registrationController.residentList = _residentList;
- registrationController.tableLoading = false;
- registrationController.update(["registration_table"]);
- registrationController.update(["registration_table_pagination"]);
- }
- String getAgeOfIdNumber(String idNumber) {
- if (idNumber.isEmpty) return '';
- final idCardRegex = RegExp(r'^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})(\d|X)$');
- final match = idCardRegex.firstMatch(idNumber);
- if (match != null) {
- final year = int.parse(match.group(2)!);
- final month = int.parse(match.group(3)!);
- final day = int.parse(match.group(4)!);
- final birthDate = DateTime(year, month, day);
- String age = DataTimeUtils.calculateAge(birthDate);
- return age;
- }
- return ''; // 返回一个默认值
- }
- /// 登记列表表头
- List<TableColumn<ResidentModel>> buildTableColumns(
- BuildContext context,
- bool? isVital,
- ) {
- /// 是否是一体机
- bool isIntegralDesk = isVital ?? false;
- var textStyle = TextStyle(
- fontSize: 18,
- overflow: TextOverflow.ellipsis,
- fontFamily: "NotoSansSC",
- );
- return <TableColumn<ResidentModel>>[
- TableColumn<ResidentModel>(
- headerText: "体检号",
- flex: 5,
- render: (rowData, index) => Container(
- padding: const EdgeInsets.symmetric(vertical: kIsWeb ? 10 : 16),
- child: OverflowTooltipWrapper(
- child: Text(
- rowData.physicalExamNumber ?? '',
- style: textStyle,
- ),
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- flex: 3,
- headerText: "姓名",
- render: (rowData, index) => Center(
- child: Text(
- rowData.name ?? '',
- style: textStyle,
- ),
- ),
- ),
- if (isIntegralDesk)
- TableColumn<ResidentModel>(
- headerText: "年龄",
- flex: 3,
- render: (rowData, index) => Center(
- child: Text(
- rowData.age != null ? rowData.age.toString() : "",
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "身份证号",
- flex: 6,
- render: (rowData, index) => Center(
- child: Text(
- rowData.idNumber,
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "手机号",
- flex: 4,
- render: (rowData, index) => Center(
- child: Text(
- rowData.phone == "" ? "-" : rowData.phone ?? '-',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerRender: () {
- return Center(
- child: Padding(
- padding: EdgeInsets.only(right: 15),
- child: Text(
- "体检时间",
- style: TextStyle(
- fontSize: 20,
- ),
- ),
- ),
- );
- },
- flex: 3,
- render: (rowData, index) => Center(
- child: Text(
- rowData.physicalExamTime == null
- ? ""
- : DataTimeUtils.formatDateString(rowData.physicalExamTime!),
- style: textStyle,
- ),
- ),
- ),
- // if (isIntegralDesk)
- TableColumn<ResidentModel>(
- headerText: "责任医生",
- maxWidth: 120,
- flex: 4,
- render: (rowData, index) => Center(
- child: Text(
- rowData.createdDoctorName ?? "",
- style: textStyle,
- ),
- ),
- ),
- // if (!isIntegralDesk)
- // TableColumn<ResidentModel>(
- // headerRender: () {
- // return Center(
- // child: Padding(
- // padding: EdgeInsets.only(right: 15),
- // child: Text(
- // "体检状态",
- // style: TextStyle(
- // fontSize: 20,
- // ),
- // ),
- // ),
- // );
- // },
- // flex: 3,
- // render: (rowData, index) => Center(
- // child: Text(
- // rowData.physicalExamStatus ?? "",
- // style: textStyle,
- // ),
- // ),
- // ),
- TableColumn<ResidentModel>(
- headerText: "操作",
- flex: 7,
- render: (rowData, index) => FittedBox(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (!FPlatform.isPureWeb && !isIntegralDesk) ...[
- _buildPrint(context, rowData),
- ],
- _buildEditRegistration(rowData),
- _buildHealthCheck(rowData, isIntegralDesk),
- _buildEditingExcepting(rowData),
- _buildShowReport(rowData),
- ],
- ),
- ),
- ),
- ];
- }
- /// 打印按钮
- Widget _buildPrint(BuildContext context, ResidentModel rowData) {
- return TextButton(
- onPressed: () async {
- advanceDebounce(() async {
- Store.app.setBusy("加载中...");
- try {
- await registrationController.getExamLabelsByExamNoAsync(rowData);
- } catch (e) {
- print(e);
- }
- Store.app.busy = false;
- Get.dialog(
- Center(
- child: Container(
- width: MediaQuery.of(context).size.width * 0.7,
- height: MediaQuery.of(context).size.height,
- child: Center(
- child: PrintPreview(
- imageList: registrationController.barCodeList,
- printInfo:
- registrationController.printInfo ?? PrinterInfo(),
- ),
- ),
- ),
- ),
- );
- }, "print label", 3000);
- },
- child: const Text(
- "打印标签",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- /// 编辑按钮
- Widget _buildEditRegistration(ResidentModel rowData) {
- return TextButton(
- onPressed: () async {
- final RegistrationInfoModel? patient = RegistrationInfoModel(
- patientName: rowData.name,
- phone: rowData.phone,
- patientAddress: rowData.homeAddress,
- cardNo: rowData.idNumber,
- code: rowData.code,
- birthday: rowData.birthDay,
- patientGender: RegistrationInfoModel.getGenderEnum(rowData.sex),
- );
- final RegistrationInfoModel? result =
- await Get.dialog<RegistrationInfoModel>(
- RegistrationFormDialog(
- patient: patient,
- isEdit: true,
- ),
- barrierDismissible: false,
- );
- registrationController.formController.editResident(result);
- print(result);
- },
- child: const Text(
- "编辑",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- Future<List<PrescriptionDTO>?> getPrescriptionList(
- String patientCode,
- String physicalExamNumber,
- ) async {
- // 获取处方列表
- List<PrescriptionDTO>? prescriptionList =
- await _prescriptionManager.getPrescriptionPage(
- patientCode: patientCode,
- physicalExamNumber: physicalExamNumber,
- );
- return prescriptionList;
- }
- /// 健康指导
- Widget _buildEditingExcepting(ResidentModel rowData) {
- const designWidth = 1280.0; // 设计尺寸宽度:1280
- final width = Get.width;
- final scale = width / designWidth; // 计算缩放比例
- return TextButton(
- onPressed: () async {
- state.resultsAndSuggestions = rowData.resultsAndSuggestions;
- state.prescriptionList = await getPrescriptionList(
- rowData.idNumber,
- rowData.physicalExamNumber ?? '',
- ) ??
- [];
- Get.dialog(
- VAlertDialog(
- width: width / scale * 0.85,
- onConfirm: () async {
- final result =
- await _registrationManager.updateResultsAndSuggestionsAsync(
- rowData.code ?? "", state.resultsAndSuggestions ?? '');
- if (result) {
- rowData.resultsAndSuggestions =
- state.resultsAndSuggestions; // 内存更新
- Get.back(); // Close the dialog
- } else {
- PromptBox.toast("保存失败");
- }
- },
- confirmLabel: "提交",
- content: Container(
- padding: EdgeInsets.all(8.0),
- child: Stack(
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(
- height: 20,
- ),
- Expanded(
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 32),
- child: TextField(
- expands: false,
- maxLines: 10,
- controller: TextEditingController(
- text: rowData.resultsAndSuggestions,
- ),
- decoration: InputDecoration(
- hintText: '请输入健康指导信息...',
- border: OutlineInputBorder(
- borderRadius: BorderRadius.all(
- Radius.circular(8.0),
- ), // 可以调整边框圆角度数
- ),
- contentPadding: EdgeInsets.all(16), // 调整文本内边距
- ),
- onChanged: (value) {
- state.resultsAndSuggestions = value;
- },
- ),
- ),
- ),
- SizedBox(
- height: 20,
- ),
- Container(
- padding: EdgeInsets.only(left: 30),
- width: 280,
- height: 54,
- alignment: Alignment.centerRight,
- child: VButton(
- onTap: () async {
- await Get.dialog(
- ExaminationPrescription(
- physicalExamNumber: rowData.physicalExamNumber,
- patientCode: rowData.idNumber,
- prescription: "",
- prescriptionTitle: "",
- ),
- );
- state.prescriptionList = await getPrescriptionList(
- rowData.idNumber,
- rowData.physicalExamNumber ?? '',
- ) ??
- [];
- },
- label: '开具健康教育处方',
- ),
- ),
- SizedBox(
- height: 10,
- ),
- _buildPrescriptionList(
- rowData.physicalExamNumber ?? '',
- rowData.idNumber,
- ),
- SizedBox(
- height: 20,
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- barrierDismissible:
- false, // Prevent dialog from closing on outside tap
- );
- },
- child: const Text(
- "健康指导",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- Widget _buildPrescriptionList(
- String physicalExamNumber,
- String patientCode,
- ) {
- ScrollController _scrollController = ScrollController();
- return Obx(() {
- if (state.prescriptionList.isNotEmpty)
- return Container(
- alignment: Alignment.centerLeft,
- padding: EdgeInsets.only(left: 30),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(width: 30),
- Container(
- margin: EdgeInsets.only(bottom: 8, top: 8),
- child: Text(
- '处方列表',
- style: TextStyle(
- fontSize: 26,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- SizedBox(width: 16),
- Container(
- height: 95,
- child: AlwaysScrollListView(
- scrollController: _scrollController,
- child: Container(
- padding: EdgeInsets.only(bottom: 8),
- child: ListView(
- controller: _scrollController,
- shrinkWrap: true,
- scrollDirection: Axis.horizontal,
- children: [
- ...state.prescriptionList.map(
- (e) => InkWell(
- radius: 8,
- onTap: () async {
- await Get.dialog(
- ExaminationPrescription(
- physicalExamNumber: physicalExamNumber,
- patientCode: patientCode,
- prescription: e.prescriptionTemplateKey ?? '',
- prescriptionTitle:
- '${PrescriptionFormKeys.AllFormKeys[e.prescriptionTemplateKey ?? '']}',
- isEdit: true,
- ),
- );
- },
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(
- color: Colors.black26,
- ),
- borderRadius: BorderRadius.all(
- Radius.circular(8),
- ),
- ),
- margin: EdgeInsets.all(8),
- padding:
- const EdgeInsets.all(8).copyWith(left: 30),
- child: Container(
- width: 380,
- child: Row(
- children: [
- Expanded(
- child: Text(
- '${PrescriptionFormKeys.AllFormKeys[e.prescriptionTemplateKey ?? '']}',
- style: TextStyle(
- fontSize: 24,
- fontWeight: FontWeight.bold,
- ),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- Container(
- width: 60,
- padding: EdgeInsets.only(
- right: 8,
- ),
- child: IconButton(
- onPressed: () {
- Get.dialog(
- VAlertDialog(
- title: "提示",
- onConfirm: () async {
- bool? result =
- await _prescriptionManager
- .removePrescription(
- prescriptionCode:
- e.code ?? '',
- );
- if (result ?? false) {
- state.prescriptionList =
- await getPrescriptionList(
- patientCode,
- physicalExamNumber,
- ) ??
- [];
- Get.back();
- } else {
- PromptBox.toast("删除失败");
- }
- },
- content: Container(
- alignment: Alignment.center,
- height: 60,
- child: Text(
- "确认是否删除 ${PrescriptionFormKeys.AllFormKeys[e.prescriptionTemplateKey ?? '']}",
- style: TextStyle(
- fontSize: 24,
- ),
- ),
- ),
- ),
- );
- },
- icon: Icon(
- Icons.close,
- size: 40,
- ),
- ),
- )
- ],
- ),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ],
- ),
- );
- return Container();
- });
- }
- /// 查看报告
- Widget _buildShowReport(ResidentModel rowData) {
- return TextButton(
- onPressed: () {
- Debouncer.run(
- () async {
- PromptBox.dismiss();
- Store.app.busy = true;
- List<ReportDTO2>? reportList = await registrationController
- .registrationManager
- .getVitalReportInfoAsync(
- physicalExamNumber: rowData.physicalExamNumber ?? '',
- );
- Store.app.busy = false;
- ReportDTO2? report = reportList
- ?.firstWhereOrNull((element) => element.key == "Part");
- if (report != null) {
- logger.i("show report:${report.code}");
- Get.dialog(
- ReportPreview(
- pdfUrl: report.previewInfo?.fileToken ?? "",
- ),
- );
- } else {
- PromptBox.showToast(
- '暂无报告',
- maskType: EasyLoadingMaskType.none, // 设置为none以允许用户操作其他控件
- );
- }
- },
- duration: Duration(milliseconds: 300),
- );
- },
- child: const Text(
- "查看报告",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- void _examDialog(ResidentModel rowData, bool isIntegralDesk) async {
- final FEventHandler<bool> onSubmitEvent = FEventHandler<bool>();
- /// 需要检测页面回调数据
- Get.put(MedicalController());
- Get.dialog(
- Scaffold(
- body: Stack(
- children: [
- ExaminationPage(
- idCard: rowData.idNumber,
- onSubmitEvent: onSubmitEvent,
- physicalExamNumber: rowData.physicalExamNumber ?? '',
- ),
- Positioned(
- left: 16,
- bottom: 16,
- child: _buildMedicalButton(rowData.idNumber),
- )
- ],
- ),
- appBar: VAppBar(
- titleText: "体检",
- actions: [
- TextButton.icon(
- onPressed: () async {
- onSubmitEvent.emit(this, true);
- },
- label: Text(
- '保存',
- style: TextStyle(fontSize: 20, color: Colors.white),
- ),
- icon: Icon(Icons.save, size: 32, color: Colors.white),
- ),
- const SizedBox(width: 8),
- ],
- iconBack: () {
- onSubmitEvent.emit(this, false);
- Get.delete<MedicalController>();
- },
- ),
- ),
- );
- }
- Widget _buildMedicalButton(String patientCode) {
- if (_hasHealthMonitor()) {
- return Container(
- width: 214,
- margin: EdgeInsets.only(right: 10),
- child: VButton(
- onTap: () async {
- var diagnosis = await Get.find<IDiagnosisManager>()
- .getDiagnosisAggregationPageAsync(patientCode, 1, 10);
- if (diagnosis?.pageData?.isNotEmpty ?? false) {
- try {
- Map<String, dynamic> diagnosisDataValue = {};
- for (DiagnosisAggregationRecordModel data
- in diagnosis!.pageData!) {
- if (data.diagnosisAggregationData?.isNotEmpty ?? false) {
- for (DiagnosisAggregationData diaData
- in data.diagnosisAggregationData!) {
- diagnosisDataValue[diaData.key ?? ''] =
- jsonDecode(diaData.diagnosisData ?? '');
- }
- break;
- }
- }
- var medicalController = Get.find<MedicalController>();
- medicalController.diagnosisDataValue = diagnosisDataValue;
- } catch (e) {}
- }
- Get.dialog<MedicalController>(
- Scaffold(
- body: ExamMedicalPage(
- isHealthCheck: true,
- ),
- appBar: VAppBar(
- titleText: "检测",
- ),
- ),
- );
- },
- child: Text(
- '检测',
- style: TextStyle(fontSize: 26),
- ),
- ),
- );
- }
- return SizedBox();
- }
- /// 体检
- Widget _buildHealthCheck(ResidentModel rowData, bool isIntegralDesk) {
- return TextButton(
- onPressed: () {
- advanceDebounce(
- () async {
- await Get.find<IPatientManager>()
- .switchCurrentPatientByCode(rowData.idNumber);
- if (Get.isRegistered<ExaminationController>()) {
- Get.delete<ExaminationController>();
- }
- Get.put(
- ExaminationController(
- patientCode: rowData.idNumber,
- batchNumber: rowData.batchNumber ?? '',
- ),
- );
- _examDialog(rowData, isIntegralDesk);
- },
- "HealthCheck",
- );
- },
- child: const Text(
- "填表",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- }
|