prescription_form.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:get/get.dart';
  6. import 'package:vitalapp/architecture/utils/datetime.dart';
  7. import 'package:vitalapp/managers/interfaces/template.dart';
  8. import 'package:vitalapp/pages/form/form_info.dart';
  9. import 'package:vitalapp/pages/form/form_view.dart';
  10. import 'package:vitalapp/store/store.dart';
  11. import 'package:fis_common/logger/logger.dart';
  12. import 'prescription_form_keys.dart';
  13. ///处方表
  14. class PrescriptionForm extends StatefulWidget {
  15. final String formKey;
  16. PrescriptionForm(this.formKey);
  17. @override
  18. State<StatefulWidget> createState() {
  19. return PrescriptionFormState();
  20. }
  21. }
  22. class PrescriptionFormState extends State<PrescriptionForm> {
  23. String? _template;
  24. @override
  25. void initState() {
  26. _initCurrentPatientInfo();
  27. Get.find<ITemplateManager>().getTemplateByKey(widget.formKey).then((value) {
  28. setState(() {
  29. _template = value;
  30. });
  31. });
  32. super.initState();
  33. }
  34. @override
  35. void didUpdateWidget(PrescriptionForm oldWidget) {
  36. if (widget.formKey != oldWidget.formKey) {
  37. setState(() {
  38. _template = null;
  39. });
  40. _initCurrentPatientInfo();
  41. Get.find<ITemplateManager>()
  42. .getTemplateByKey(widget.formKey)
  43. .then((value) {
  44. setState(() {
  45. _template = value;
  46. });
  47. });
  48. }
  49. super.didUpdateWidget(oldWidget);
  50. }
  51. @override
  52. Widget build(BuildContext context) {
  53. return _template == null
  54. ? Center(
  55. child: CircularProgressIndicator(),
  56. )
  57. : FormView(_template!);
  58. }
  59. void _initCurrentPatientInfo() {
  60. try {
  61. PatientDTO? currentPatient = Store.user.currentSelectPatientInfo;
  62. if (currentPatient != null) {
  63. if (!FormInfo.instance.formValue.containsKey("PatientName")) {
  64. FormInfo.instance.formValue["PatientName"] =
  65. currentPatient.patientName;
  66. }
  67. if (currentPatient.birthday != null &&
  68. !FormInfo.instance.formValue.containsKey("PatientAge")) {
  69. var age = DataTimeUtils.calculateAge(
  70. Store.user.currentSelectPatientInfo!.birthday!);
  71. FormInfo.instance.formValue["PatientAge"] = age;
  72. }
  73. if (!FormInfo.instance.formValue.containsKey("PatientGender")) {
  74. if (currentPatient.patientGender == GenderEnum.Male) {
  75. FormInfo.instance.formValue["PatientGender"] = "1";
  76. } else if (currentPatient.patientGender == GenderEnum.Female) {
  77. FormInfo.instance.formValue["PatientGender"] = "2";
  78. }
  79. }
  80. }
  81. } catch (e) {
  82. logger.e('PrescriptionForm _initCurrentPatientInfo ex:', e);
  83. }
  84. }
  85. }