123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414 |
- import 'dart:ui';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_printer_plus/flutter_printer_plus.dart'
- if (dart.library.html) "package:vitalapp/pages/medical_checkup_station/usb_print/web/flutter_printer_plus.dart";
- import 'package:get/get.dart';
- import 'package:vitalapp/managers/interfaces/appointment.dart';
- import 'package:vitalapp/managers/interfaces/patient.dart';
- import 'package:vitalapp/managers/interfaces/registration.dart';
- import 'package:vitalapp/pages/controllers/blue_location_mixin.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/controller/form.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/controller/list.dart';
- import 'package:vitalapp/pages/medical_checkup_station/registration/state/list.dart';
- import 'package:vitalapp/pages/medical_checkup_station/usb_print/module/printer_info.dart';
- import 'package:barcode_image/barcode_image.dart';
- import 'package:flutter_svg/flutter_svg.dart';
- /// 登记控制器
- class RegistrationController extends GetxController
- with BluetoothAndLocationMixin {
- late final RegistrationFormController formController;
- late final RegistrationListController listController;
- final appointmentManager = Get.find<IAppointmentManager>();
- final registrationManager = Get.find<IRegistrationManager>();
- final _patientManager = Get.find<IPatientManager>();
- final state = ListState();
- RegistrationController() {
- listController = RegistrationListController(this);
- formController = RegistrationFormController(this);
- }
- /// 登记
- ResidentModel resident = ResidentModel(
- idNumber: '',
- );
- /// 预约列表
- List<ResidentModel> residentList = [];
- /// 预约列表的总数
- int appointmentModelListLength = 0;
- /// 表格loading
- bool tableLoading = true;
- /// 当前表格页数
- int currPageIndex = 1;
- PrinterInfo? printInfo;
- List<Uint8List> barCodeList = [];
- //查询本地USB打印机列表
- Future<List<PrinterInfo>> queryLocalUSBPrinter() {
- return FlutterPrinterFinder.queryUsbPrinter().then(
- (value) => value.map((e) => PrinterInfo.fromUsbDevice(e)).toList(),
- );
- }
- _initData() async {
- var now = DateTime.now();
- listController.state.startTime = new DateTime(now.year, now.month, now.day);
- listController.state.endTime = listController.state.startTime!
- .add(Duration(hours: 23, minutes: 59, seconds: 59));
- await listController.getRegisterInfoPage();
- if (!kIsWeb) {
- List<PrinterInfo>? printerInfoList = await queryLocalUSBPrinter();
- if (printerInfoList.length == 0) {
- return;
- }
- printInfo = printerInfoList.first;
- }
- }
- Future<void> getExamLabelsByExamNoAsync(ResidentModel rowData) async {
- // await drawBarcode(HealthExamLabelDTO(uniquedCode: "123"), rowData);
- // Future.delayed(Duration(milliseconds: 2000));
- var labels = await registrationManager.getExamLabelsByExamNoAsync(
- physicalExamNumber: rowData.physicalExamNumber!);
- barCodeList.clear();
- for (var i = 0; i < labels.eaxmLabels!.length; i++) {
- final element = labels.eaxmLabels![i];
- if (i == 0) {
- var qrCode = await drawQRcode(element, rowData);
- barCodeList.add(qrCode);
- continue;
- }
- var barCode = Uint8List(0);
- barCode = await drawBarcode(element, rowData);
- if (barCode.isNotEmpty) {
- barCodeList.add(barCode);
- }
- }
- }
- Future<Uint8List> drawBarcode(
- HealthExamLabelDTO labelDto, ResidentModel resident) async {
- const size = Size(360, 240);
- final svg = Barcode.code128().toSvg(
- labelDto.uniquedCode!,
- width: 350,
- height: 120,
- fontFamily: "NotoSansSC",
- );
- final PictureInfo pictureInfo =
- await vg.loadPicture(SvgStringLoader(svg), null);
- var a = await _capturePainterToImage(
- InfoPainter(labelDto, resident), BarcodePainter(pictureInfo), size);
- return a!;
- }
- Future<Uint8List> drawQRcode(
- HealthExamLabelDTO labelDto, ResidentModel resident) async {
- const size = Size(360, 240);
- final svg = Barcode.qrCode(
- typeNumber: 1,
- errorCorrectLevel: BarcodeQRCorrectionLevel.low,
- ).toSvg(
- labelDto.uniquedCode!,
- width: 190,
- height: 190,
- fontFamily: "NotoSansSC",
- );
- final PictureInfo pictureInfo =
- await vg.loadPicture(SvgStringLoader(svg), null);
- var a = await _capturePainterToImage(
- QRInfoPainter(labelDto, resident), QrcodePainter(pictureInfo), size);
- return a!;
- }
- /// 将CustomPainter绘制的内容转换为图片
- Future<Uint8List?> _capturePainterToImage(
- CustomPainter painter, CustomPainter codePainter, Size size) async {
- final bounds = Offset.zero & size;
- // final bounds2 = Offset.zero & Size(size.width - 20, size.height - 20);
- final picture = PictureRecorder();
- final pictureCanvas = Canvas(picture);
- // 给Canvas设置绘制范围
- pictureCanvas.clipRect(bounds);
- painter.paint(pictureCanvas, size);
- // 在Canvas上进行绘制
- codePainter.paint(pictureCanvas, size);
- // 结束绘制
- final recordedPicture = picture.endRecording();
- final image =
- await recordedPicture.toImage(size.width.toInt(), size.height.toInt());
- // 转换为字节数组
- final byteData = await image.toByteData(format: ImageByteFormat.png);
- final bytes = byteData?.buffer.asUint8List();
- return bytes;
- }
- void onTap() {}
- @override
- void onReady() {
- _initData();
- super.onReady();
- }
- // void on
- @override
- void onClose() {}
- /// 根据身份证号获取居民信息
- Future<PatientDTO?> getPatientByID(String idNum,
- [bool isValidOperationDoctor = true]) async {
- final patient = await _patientManager.getDetail(
- idNum,
- isValidOperationDoctor: isValidOperationDoctor,
- );
- return patient;
- }
- }
- class InfoPainter extends CustomPainter {
- HealthExamLabelDTO labelDto;
- ResidentModel resident;
- InfoPainter(this.labelDto, this.resident);
- @override
- void paint(Canvas canvas, Size size) {
- canvas.save();
- Paint backgroundPaint = Paint()..color = Colors.white;
- canvas.drawRect(
- Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
- canvas.drawLine(
- Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
- // Simulate drawing the content
- TextSpan titleSpan = TextSpan(
- text: '${labelDto.title ?? ''}',
- style: TextStyle(
- fontSize: 40,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter titleTp = TextPainter(
- text: titleSpan,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- titleTp.layout();
- titleTp.paint(canvas, Offset(10, 8));
- TextSpan subTitleSpanName = TextSpan(
- text: '${resident.name} ',
- style: TextStyle(
- fontSize: 26,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTp1 = TextPainter(
- text: subTitleSpanName,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTp1.layout();
- subTitleTp1.paint(canvas, Offset(10, 65));
- TextSpan subTitleSpanAge = TextSpan(
- text: '${resident.age} 岁',
- style: TextStyle(
- fontSize: 26,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTpAge = TextPainter(
- text: subTitleSpanAge,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTpAge.layout();
- subTitleTpAge.paint(canvas, Offset(150, 65));
- TextSpan subTitleSpanGender = TextSpan(
- text: '${resident.sex}',
- style: TextStyle(
- fontSize: 26,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTpGender = TextPainter(
- text: subTitleSpanGender,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTpGender.layout();
- subTitleTpGender.paint(canvas, Offset(300, 65));
- canvas.restore();
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
- class BarcodePainter extends CustomPainter {
- PictureInfo pictureInfo;
- BarcodePainter(this.pictureInfo);
- @override
- void paint(Canvas canvas, Size size) {
- canvas.save();
- canvas.translate(5, 100);
- canvas.scale(1, 1);
- canvas.drawPicture(pictureInfo.picture);
- canvas.restore(); // 恢复之前保存的绘制状态
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
- class QRInfoPainter extends CustomPainter {
- HealthExamLabelDTO labelDto;
- ResidentModel resident;
- QRInfoPainter(this.labelDto, this.resident);
- @override
- void paint(Canvas canvas, Size size) {
- canvas.save();
- Paint backgroundPaint = Paint()..color = Colors.white;
- canvas.drawRect(
- Rect.fromLTWH(0, 0, size.width, size.height), backgroundPaint);
- // canvas.drawLine(
- // Offset(0, 95), Offset(360, 95), Paint()..color = Colors.black);
- // Simulate drawing the content
- TextSpan titleSpan = TextSpan(
- text: '${labelDto.title ?? ''}',
- style: TextStyle(
- fontSize: 40,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter titleTp = TextPainter(
- text: titleSpan,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- titleTp.layout();
- titleTp.paint(canvas, Offset(10, 8));
- TextSpan subTitleSpanName = TextSpan(
- text: '${resident.name} ',
- style: TextStyle(
- fontSize: 30,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTp1 = TextPainter(
- text: subTitleSpanName,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTp1.layout();
- subTitleTp1.paint(canvas, Offset(10, 70));
- TextSpan subTitleSpanAge = TextSpan(
- text: '${resident.age} 岁',
- style: TextStyle(
- fontSize: 30,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTpAge = TextPainter(
- text: subTitleSpanAge,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTpAge.layout();
- subTitleTpAge.paint(canvas, Offset(10, 120));
- TextSpan subTitleSpanGender = TextSpan(
- text: '${resident.sex}',
- style: TextStyle(
- fontSize: 30,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter subTitleTpGender = TextPainter(
- text: subTitleSpanGender,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- subTitleTpGender.layout();
- subTitleTpGender.paint(canvas, Offset(10, 170));
- TextSpan uniqueCode = TextSpan(
- text: '${labelDto.uniquedCode}',
- style: TextStyle(
- fontSize: 24,
- height: 1,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- ),
- );
- TextPainter uniqueCodePainter = TextPainter(
- text: uniqueCode,
- textAlign: TextAlign.left,
- textDirection: TextDirection.ltr,
- );
- uniqueCodePainter.layout();
- uniqueCodePainter.paint(canvas, Offset(150, 195));
- canvas.restore();
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
- class QrcodePainter extends CustomPainter {
- PictureInfo pictureInfo;
- QrcodePainter(this.pictureInfo);
- @override
- void paint(Canvas canvas, Size size) {
- canvas.save();
- canvas.translate(150, 0);
- canvas.scale(1, 1);
- canvas.drawPicture(pictureInfo.picture);
- canvas.restore(); // 恢复之前保存的绘制状态
- }
- @override
- bool shouldRepaint(covariant CustomPainter oldDelegate) {
- return false;
- }
- }
|