123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- import 'package:fis_common/event/event_type.dart';
- 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/utils/datetime.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/appbar.dart';
- import 'package:vitalapp/components/button.dart';
- import 'package:vitalapp/components/table/table_column.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/medical/controller.dart';
- import 'package:vitalapp/pages/medical/view.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/store/store.dart';
- class RegistrationListController {
- late RegistrationController registrationController;
- RegistrationListController(RegistrationController controller) {
- registrationController = controller;
- }
- final state = ListState();
- final _registrationManager = Get.find<IRegistrationManager>();
- ResidentModel currentResident = ResidentModel(idNumber: "");
- List<String> _allExam = [
- "HEIBasic",
- "HEIUrinalysis",
- "HEIUltrasonic",
- "HEIBiochemical",
- "HEIBloodRoutine",
- "HEIECG",
- "HEITCMC"
- ];
- Map<String, dynamic> examData = {};
- List<String> examList() {
- List<String> missingData = _allExam
- .where((element) =>
- !(currentResident.finishedExamKeys ?? []).contains(element))
- .toList();
- return missingData;
- }
- /// 是否有健康检测的页面权限
- 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 = "",
- DateTime? startTime,
- DateTime? endTime,
- }) async {
- registrationController.tableLoading = true;
- registrationController.currPageIndex = pageIndex!;
- var result = await registrationController.registrationManager
- .getRegisterInfoPageAsync(
- pageSize: pageSize,
- pageIndex: pageIndex,
- keyword: keyword,
- startTime: startTime,
- endTime: 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,
- sex: i.sex,
- batchNumber: i.batchNumber,
- ),
- );
- }
- registrationController.appointmentModelListLength = result.totalCount;
- }
- 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) {
- var textStyle = TextStyle(
- fontSize: 18,
- overflow: TextOverflow.ellipsis,
- );
- return <TableColumn<ResidentModel>>[
- TableColumn<ResidentModel>(
- headerText: "体检号",
- flex: 4,
- render: (rowData, index) => Container(
- padding: const EdgeInsets.symmetric(vertical: kIsWeb ? 10 : 16),
- child: Text(
- rowData.physicalExamNumber ?? '',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- flex: 3,
- headerText: "姓名",
- render: (rowData, index) => Center(
- child: Text(
- rowData.name ?? '',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "年龄",
- flex: 2,
- render: (rowData, index) => Center(
- child: Text(
- rowData.age != null ? rowData.age.toString() : "",
- style: textStyle,
- ),
- )),
- TableColumn<ResidentModel>(
- headerText: "身份证号",
- flex: 5,
- render: (rowData, index) => Center(
- child: Text(
- rowData.idNumber,
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "手机号",
- flex: 4,
- render: (rowData, index) => Center(
- child: Text(
- rowData.phone ?? '',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "体检状态",
- // maxWidth: 120,
- flex: 3,
- render: (rowData, index) => Center(
- child: Text(
- rowData.physicalExamStatus ?? "",
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "操作",
- flex: 8,
- render: (rowData, index) => FittedBox(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (!kIsWeb) ...[
- _buildPrint(context, rowData),
- ],
- _buildEditRegistration(rowData),
- if (kIsWeb) _buildEditingExcepting(rowData),
- if (kIsWeb) _buildShowReport(rowData),
- _buildHealthCheck(rowData),
- ],
- ),
- ),
- ),
- ];
- }
- /// 打印按钮
- Widget _buildPrint(BuildContext context, ResidentModel rowData) {
- return TextButton(
- onPressed: () async {
- // if (registrationController.printInfo == null) {
- // PromptBox.toast("打印出错");
- // return;
- // }
- // if (kIsWeb) {
- await registrationController.getExamLabelsByExamNoAsync(rowData);
- // } else {
- 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(),
- ),
- ),
- ),
- ),
- );
- // }
- },
- child: const Text(
- "打印标签",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- /// 编辑按钮
- Widget _buildEditRegistration(ResidentModel rowData) {
- return TextButton(
- onPressed: () async {
- final PatientDTO? patient = PatientDTO(
- patientName: rowData.name,
- phone: rowData.phone,
- patientAddress: rowData.homeAddress,
- cardNo: rowData.idNumber,
- code: rowData.code,
- birthday: rowData.birthDay,
- patientGender: rowData.sex == "男"
- ? GenderEnum.Male
- : rowData.sex == "女"
- ? GenderEnum.Female
- : GenderEnum.Unknown,
- );
- final PatientDTO? result = await Get.dialog<PatientDTO>(
- RegistrationFormDialog(
- patient: patient,
- isEdit: true,
- ),
- barrierDismissible: false,
- );
- registrationController.formController.editResident(result);
- print(result);
- },
- child: const Text(
- "编辑",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- /// 健康指导
- Widget _buildEditingExcepting(ResidentModel rowData) {
- return TextButton(
- onPressed: () {
- Get.dialog(
- Dialog(
- backgroundColor: Colors.white, // 设置对话框背景颜色为白色
- child: Container(
- padding: EdgeInsets.all(16.0),
- child: Stack(
- children: [
- Column(
- children: [
- SizedBox(
- height: 20,
- ),
- Expanded(
- child: TextField(
- expands: true,
- maxLines: null,
- decoration: InputDecoration(
- hintText: '请输入健康指导信息...',
- border: InputBorder.none,
- ),
- onChanged: (value) {
- state.resultsAndSuggestions = value;
- },
- ),
- ),
- ElevatedButton(
- onPressed: () async {
- await _registrationManager
- .updateResultsAndSuggestionsAsync(
- rowData.code ?? "",
- state.resultsAndSuggestions ?? '');
- Get.back(); // Close the dialog
- },
- child: Text(
- '提交',
- style: TextStyle(fontSize: 18),
- ),
- ),
- ],
- ),
- Positioned(
- top: 1.0,
- right: 1.0,
- child: IconButton(
- icon: Icon(Icons.close),
- onPressed: () {
- Get.back();
- },
- ),
- ),
- ],
- ),
- ),
- ),
- barrierDismissible:
- false, // Prevent dialog from closing on outside tap
- );
- },
- child: const Text(
- "健康指导",
- style: TextStyle(fontSize: 18),
- ));
- }
- /// 查看报告
- Widget _buildShowReport(ResidentModel rowData) {
- return TextButton(
- onPressed: () async {
- List<ReportDTO2>? reportList = await registrationController
- .registrationManager
- .getVitalReportInfoAsync(
- physicalExamNumber: rowData.physicalExamNumber ?? '',
- );
- ReportDTO2? report =
- reportList?.firstWhereOrNull((element) => element.key == "Part");
- if (report != null) {
- Get.dialog(
- ReportPreview(
- pdfUrl: report.previewInfo?.fileToken ?? "",
- ),
- );
- } else {
- PromptBox.toast("暂无报告");
- }
- },
- child: const Text(
- "查看报告",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- void _setCurrentSelectPatientInfo(ResidentModel rowData) {
- Store.user.currentSelectPatientInfo = PatientDTO(
- cardNo: rowData.idNumber,
- patientName: rowData.name,
- code: rowData.idNumber,
- patientAddress: rowData.homeAddress,
- );
- }
- void _examDialog(ResidentModel rowData) async {
- final FEventHandler<bool> onSubmitEvent = FEventHandler<bool>();
- /// 需要检测页面回调数据
- Get.put(MedicalController());
- await Get.dialog(
- Scaffold(
- body: Stack(
- children: [
- ExaminationPage(
- idCard: rowData.idNumber,
- onSubmitEvent: onSubmitEvent,
- ),
- Positioned(
- left: 16,
- bottom: 16,
- child: _buildMedicalButton(),
- )
- ],
- ),
- appBar: VAppBar(
- titleText: "体检",
- actions: [
- _buildSaveButton(onSubmitEvent),
- ],
- iconBack: () {
- onSubmitEvent.emit(this, true);
- Get.delete<MedicalController>();
- },
- ),
- ),
- );
- }
- Widget _buildSaveButton(FEventHandler<bool> onSubmitEvent) {
- return Container(
- margin: EdgeInsets.only(right: 10),
- child: ElevatedButton(
- onPressed: () async {
- onSubmitEvent.emit(this, true);
- },
- child: Text('保存'),
- ),
- );
- }
- Widget _buildMedicalButton() {
- if (_hasHealthMonitor()) {
- return Container(
- width: 214,
- margin: EdgeInsets.only(right: 10),
- child: VButton(
- onTap: () {
- Get.dialog<MedicalController>(
- Scaffold(
- body: MedicalPage(
- isHealthCheck: true,
- ),
- appBar: VAppBar(
- titleText: "检测",
- ),
- ),
- );
- },
- child: Text(
- '检测',
- style: TextStyle(fontSize: 26),
- ),
- ),
- );
- }
- return SizedBox();
- }
- /// 体检
- Widget _buildHealthCheck(ResidentModel rowData) {
- return TextButton(
- onPressed: () {
- Get.lazyPut(
- () => ExaminationController(
- patientCode: rowData.idNumber,
- batchNumber: rowData.batchNumber ?? '',
- ),
- );
- _setCurrentSelectPatientInfo(rowData);
- _examDialog(rowData);
- },
- child: const Text(
- "体检表",
- style: TextStyle(fontSize: 18),
- ),
- );
- }
- }
|