examination_prescription.dart 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // ignore_for_file: must_be_immutable
  2. import 'dart:convert';
  3. import 'package:fis_jsonrpc/rpc.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  7. import 'package:vitalapp/components/alert_dialog.dart';
  8. import 'package:vitalapp/components/no_data_view.dart';
  9. import 'package:vitalapp/managers/interfaces/prescription.dart';
  10. import 'package:vitalapp/pages/check/prescription/prescription_form.dart';
  11. import 'package:vitalapp/pages/check/prescription/prescription_form_keys.dart';
  12. import 'package:vitalapp/pages/form/form_info.dart';
  13. import 'package:vitalapp/store/store.dart';
  14. class ExaminationPrescription extends StatefulWidget {
  15. ExaminationPrescription({
  16. super.key,
  17. required this.physicalExamNumber,
  18. required this.patientCode,
  19. required this.prescription,
  20. required this.prescriptionTitle,
  21. this.isEdit,
  22. });
  23. final String? physicalExamNumber;
  24. final String? patientCode;
  25. final bool? isEdit;
  26. String prescription = '';
  27. String prescriptionTitle = '';
  28. @override
  29. State<ExaminationPrescription> createState() =>
  30. _ExaminationPrescriptionState();
  31. }
  32. class _ExaminationPrescriptionState extends State<ExaminationPrescription> {
  33. final _prescriptionManager = Get.find<IPrescriptionManager>();
  34. List<PrescriptionDTO>? prescriptionList;
  35. String prescriptionCode = "";
  36. @override
  37. Widget build(BuildContext context) {
  38. return _buildExaminationPrescriptionDialog();
  39. }
  40. @override
  41. void initState() {
  42. _initPrescription();
  43. super.initState();
  44. }
  45. Future<void> _initPrescription() async {
  46. // 获取处方列表
  47. if (widget.prescriptionTitle.isEmpty) {
  48. return;
  49. }
  50. prescriptionList = await _prescriptionManager.getPrescriptionPage(
  51. patientCode: widget.patientCode!,
  52. physicalExamNumber: widget.physicalExamNumber!,
  53. );
  54. String? prescriptionData = prescriptionList
  55. ?.firstWhereOrNull(
  56. (element) => element.prescriptionTemplateKey == widget.prescription)
  57. ?.prescriptionData;
  58. prescriptionCode = prescriptionList
  59. ?.firstWhereOrNull((element) =>
  60. element.prescriptionTemplateKey == widget.prescription)
  61. ?.code ??
  62. "";
  63. if (prescriptionData != null) {
  64. FormInfo.instance.formValue = jsonDecode(prescriptionData);
  65. }
  66. setState(() {});
  67. }
  68. Widget _buildExaminationPrescriptionDialog() {
  69. const designWidth = 1280.0; // 设计尺寸宽度:1280
  70. final width = Get.width;
  71. final scale = width / designWidth; // 计算缩放比例
  72. return VAlertDialog(
  73. // title: "新增处方",
  74. width: width * 0.8 / scale,
  75. content: Column(
  76. mainAxisAlignment: MainAxisAlignment.center,
  77. children: [
  78. if (widget.prescriptionTitle.isEmpty)
  79. Container(
  80. //height: Get.height,
  81. child: ListView(
  82. shrinkWrap: true,
  83. children: [
  84. Wrap(
  85. children: PrescriptionFormKeys.AllFormKeys.entries.map(
  86. (e) {
  87. return Container(
  88. margin: EdgeInsets.symmetric(
  89. vertical: 6,
  90. horizontal: 10,
  91. ),
  92. decoration: BoxDecoration(
  93. border: Border.all(
  94. color: widget.prescription == e.key
  95. ? Colors.blue
  96. : Colors.black26,
  97. ),
  98. borderRadius: const BorderRadius.all(
  99. Radius.circular(50),
  100. ),
  101. color: widget.prescription == e.key
  102. ? Colors.blue
  103. : Colors.transparent,
  104. ),
  105. child: InkWell(
  106. onTap: () => selectRaidoChange(e),
  107. borderRadius: BorderRadius.circular(50),
  108. child: FittedBox(
  109. child: Container(
  110. padding: const EdgeInsets.all(12),
  111. alignment: Alignment.center,
  112. child: Text(
  113. e.value,
  114. style: TextStyle(
  115. fontSize: 20,
  116. color: widget.prescription == e.key
  117. ? Colors.white
  118. : Colors.black54,
  119. ),
  120. ),
  121. ),
  122. ),
  123. ),
  124. );
  125. },
  126. ).toList(),
  127. ),
  128. ],
  129. ),
  130. ),
  131. if (widget.prescriptionTitle.isNotEmpty)
  132. // 构建处方信息
  133. Expanded(
  134. key: UniqueKey(),
  135. child: Container(
  136. color: Colors.white,
  137. child: _buildPrescription(
  138. widget.prescription,
  139. widget.prescriptionTitle,
  140. ),
  141. ),
  142. ),
  143. ],
  144. ),
  145. onCanceled: () {
  146. FormInfo.instance.formValue.clear();
  147. },
  148. onConfirm: () async {
  149. if (widget.isEdit ?? false) {
  150. bool? result = await _prescriptionManager.updatePrescription(
  151. patientCode: widget.patientCode!,
  152. physicalExamNumber: widget.physicalExamNumber,
  153. prescriptionCode: prescriptionCode,
  154. prescriptionKey: widget.prescription,
  155. prescriptionData: jsonEncode(FormInfo.instance.formValue),
  156. );
  157. if (result ?? false) {
  158. Get.back();
  159. FormInfo.instance.formValue.clear();
  160. } else {
  161. PromptBox.toast("更新失败");
  162. }
  163. } else if (FormInfo.instance.formValue.isNotEmpty) {
  164. String? prescriptionCode =
  165. await _prescriptionManager.createPrescription(
  166. patientCode: widget.patientCode!,
  167. physicalExamNumber: widget.physicalExamNumber,
  168. prescriptionKey: widget.prescription,
  169. prescriptionData: jsonEncode(FormInfo.instance.formValue),
  170. );
  171. Get.back(result: {
  172. "prescriptionCode": prescriptionCode,
  173. "prescription": widget.prescription,
  174. });
  175. FormInfo.instance.formValue.clear();
  176. } else {
  177. Get.back();
  178. }
  179. },
  180. );
  181. }
  182. void selectRaidoChange(MapEntry<String, String> e) {
  183. Store.app.setBusy("加载中");
  184. widget.prescription = e.key;
  185. widget.prescriptionTitle = e.value;
  186. setState(() {});
  187. Store.app.cancelBusy();
  188. }
  189. Widget _buildPrescription(String prescription, String prescriptionTitle) {
  190. switch (prescription) {
  191. case '':
  192. return VNoDataView();
  193. default:
  194. return Column(
  195. children: [
  196. Container(
  197. margin: const EdgeInsets.all(10),
  198. child: Text(
  199. prescriptionTitle,
  200. style: const TextStyle(
  201. fontSize: 30,
  202. fontWeight: FontWeight.bold,
  203. ),
  204. ),
  205. ),
  206. Expanded(
  207. child: PrescriptionForm(
  208. prescription,
  209. ),
  210. ),
  211. ],
  212. );
  213. }
  214. // 构建处方信息
  215. }
  216. }