123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.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/table/table_column.dart';
- import 'package:vitalapp/managers/interfaces/registration.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/label_temp.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"
- ];
- List<String> examList() {
- List<String> missingData = _allExam
- .where((element) =>
- !(currentResident.finishedExamKeys ?? []).contains(element))
- .toList();
- return missingData;
- }
- 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,
- ),
- );
- }
- 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() {
- var textStyle = TextStyle(
- fontSize: 16,
- overflow: TextOverflow.ellipsis,
- );
- return <TableColumn<ResidentModel>>[
- TableColumn<ResidentModel>(
- headerText: "体检号",
- maxWidth: 150,
- render: (rowData, index) => Container(
- padding: const EdgeInsets.symmetric(vertical: 16),
- child: Text(
- rowData.physicalExamNumber ?? '',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "姓名",
- maxWidth: 100,
- render: (rowData, index) => Text(
- rowData.name ?? '',
- style: textStyle,
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "年龄",
- maxWidth: 80,
- render: (rowData, index) => Text(
- rowData.age != null ? rowData.age.toString() : "",
- style: textStyle,
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "身份证号",
- maxWidth: 200,
- render: (rowData, index) => Text(
- rowData.idNumber,
- style: textStyle,
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "手机号",
- maxWidth: 120,
- render: (rowData, index) => Center(
- child: Text(
- rowData.phone ?? '',
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "体检状态",
- maxWidth: 120,
- render: (rowData, index) => Center(
- child: Text(
- rowData.physicalExamStatus ?? "",
- style: textStyle,
- ),
- ),
- ),
- TableColumn<ResidentModel>(
- headerText: "操作",
- render: (rowData, index) => Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- _buildPrint(rowData),
- _buildEditRegistration(rowData),
- if (kIsWeb) _buildEditingExcepting(rowData),
- if (kIsWeb) _buildShowReport(rowData),
- ],
- ),
- ),
- ];
- }
- /// 打印按钮
- Widget _buildPrint(ResidentModel rowData) {
- return TextButton(
- onPressed: () {
- // if (registrationController.printInfo == null) {
- // PromptBox.toast("打印出错");
- // return;
- // }
- Get.dialog(
- Center(
- child: Stack(
- children: [
- ScreenUtilInit(
- designSize: const Size(360 * 1.2, 240 * 1.2),
- scaleByHeight: true,
- builder: (BuildContext context, Widget? child) {
- return LabelTempWidget(
- registrationController.printInfo ?? PrinterInfo(),
- labelWidth: 360,
- labelHeight: 240,
- residentModel: rowData,
- );
- },
- ),
- Positioned(
- right: 66,
- child: IconButton(
- onPressed: () {
- Get.back();
- },
- icon: Icon(
- Icons.close,
- size: 40,
- ),
- ),
- ),
- ],
- ),
- ),
- );
- },
- child: const Text("打印标签"),
- );
- }
- /// 编辑按钮
- 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("编辑"),
- );
- }
- /// 健康指导
- 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('提交'),
- ),
- ],
- ),
- 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("健康指导"));
- }
- /// 查看报告
- 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("查看报告"),
- );
- }
- }
|