123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- // ignore_for_file: must_be_immutable
- import 'dart:convert';
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/components/no_data_view.dart';
- import 'package:vitalapp/managers/interfaces/prescription.dart';
- import 'package:vitalapp/pages/check/prescription/prescription_form.dart';
- import 'package:vitalapp/pages/check/prescription/prescription_form_keys.dart';
- import 'package:vitalapp/pages/form/form_info.dart';
- import 'package:vitalapp/store/store.dart';
- class ExaminationPrescription extends StatefulWidget {
- ExaminationPrescription({
- super.key,
- required this.physicalExamNumber,
- required this.patientCode,
- required this.prescription,
- required this.prescriptionTitle,
- this.isEdit,
- });
- final String? physicalExamNumber;
- final String? patientCode;
- final bool? isEdit;
- String prescription = '';
- String prescriptionTitle = '';
- @override
- State<ExaminationPrescription> createState() =>
- _ExaminationPrescriptionState();
- }
- class _ExaminationPrescriptionState extends State<ExaminationPrescription> {
- final _prescriptionManager = Get.find<IPrescriptionManager>();
- List<PrescriptionDTO>? prescriptionList;
- String prescriptionCode = "";
- @override
- Widget build(BuildContext context) {
- return _buildExaminationPrescriptionDialog();
- }
- @override
- void initState() {
- _initPrescription();
- super.initState();
- }
- Future<void> _initPrescription() async {
- // 获取处方列表
- if (widget.prescriptionTitle.isEmpty) {
- return;
- }
- prescriptionList = await _prescriptionManager.getPrescriptionPage(
- patientCode: widget.patientCode!,
- physicalExamNumber: widget.physicalExamNumber!,
- );
- String? prescriptionData = prescriptionList
- ?.firstWhereOrNull(
- (element) => element.prescriptionTemplateKey == widget.prescription)
- ?.prescriptionData;
- prescriptionCode = prescriptionList
- ?.firstWhereOrNull((element) =>
- element.prescriptionTemplateKey == widget.prescription)
- ?.code ??
- "";
- if (prescriptionData != null) {
- FormInfo.instance.formValue = jsonDecode(prescriptionData);
- }
- setState(() {});
- }
- Widget _buildExaminationPrescriptionDialog() {
- const designWidth = 1280.0; // 设计尺寸宽度:1280
- final width = Get.width;
- final scale = width / designWidth; // 计算缩放比例
- return VAlertDialog(
- // title: "新增处方",
- width: width * 0.8 / scale,
- content: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- if (widget.prescriptionTitle.isEmpty)
- Container(
- //height: Get.height,
- child: ListView(
- shrinkWrap: true,
- children: [
- Wrap(
- children: PrescriptionFormKeys.AllFormKeys.entries.map(
- (e) {
- return Container(
- margin: EdgeInsets.symmetric(
- vertical: 6,
- horizontal: 10,
- ),
- decoration: BoxDecoration(
- border: Border.all(
- color: widget.prescription == e.key
- ? Colors.blue
- : Colors.black26,
- ),
- borderRadius: const BorderRadius.all(
- Radius.circular(50),
- ),
- color: widget.prescription == e.key
- ? Colors.blue
- : Colors.transparent,
- ),
- child: InkWell(
- onTap: () => selectRaidoChange(e),
- borderRadius: BorderRadius.circular(50),
- child: FittedBox(
- child: Container(
- padding: const EdgeInsets.all(12),
- alignment: Alignment.center,
- child: Text(
- e.value,
- style: TextStyle(
- fontSize: 20,
- color: widget.prescription == e.key
- ? Colors.white
- : Colors.black54,
- ),
- ),
- ),
- ),
- ),
- );
- },
- ).toList(),
- ),
- ],
- ),
- ),
- if (widget.prescriptionTitle.isNotEmpty)
- // 构建处方信息
- Expanded(
- key: UniqueKey(),
- child: Container(
- color: Colors.white,
- child: _buildPrescription(
- widget.prescription,
- widget.prescriptionTitle,
- ),
- ),
- ),
- ],
- ),
- onCanceled: () {
- FormInfo.instance.formValue.clear();
- },
- onConfirm: () async {
- if (widget.isEdit ?? false) {
- bool? result = await _prescriptionManager.updatePrescription(
- patientCode: widget.patientCode!,
- physicalExamNumber: widget.physicalExamNumber,
- prescriptionCode: prescriptionCode,
- prescriptionKey: widget.prescription,
- prescriptionData: jsonEncode(FormInfo.instance.formValue),
- );
- if (result ?? false) {
- Get.back();
- FormInfo.instance.formValue.clear();
- } else {
- PromptBox.toast("更新失败");
- }
- } else if (FormInfo.instance.formValue.isNotEmpty) {
- String? prescriptionCode =
- await _prescriptionManager.createPrescription(
- patientCode: widget.patientCode!,
- physicalExamNumber: widget.physicalExamNumber,
- prescriptionKey: widget.prescription,
- prescriptionData: jsonEncode(FormInfo.instance.formValue),
- );
- Get.back(result: {
- "prescriptionCode": prescriptionCode,
- "prescription": widget.prescription,
- });
- FormInfo.instance.formValue.clear();
- } else {
- Get.back();
- }
- },
- );
- }
- void selectRaidoChange(MapEntry<String, String> e) {
- Store.app.setBusy("加载中");
- widget.prescription = e.key;
- widget.prescriptionTitle = e.value;
- setState(() {});
- Store.app.cancelBusy();
- }
- Widget _buildPrescription(String prescription, String prescriptionTitle) {
- switch (prescription) {
- case '':
- return VNoDataView();
- default:
- return Column(
- children: [
- Container(
- margin: const EdgeInsets.all(10),
- child: Text(
- prescriptionTitle,
- style: const TextStyle(
- fontSize: 30,
- fontWeight: FontWeight.bold,
- ),
- ),
- ),
- Expanded(
- child: PrescriptionForm(
- prescription,
- ),
- ),
- ],
- );
- }
- // 构建处方信息
- }
- }
|