prescription_form.dart 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 'prescription_form_keys.dart';
  12. ///处方表
  13. class PrescriptionForm extends StatefulWidget {
  14. final String formKey;
  15. PrescriptionForm(this.formKey);
  16. @override
  17. State<StatefulWidget> createState() {
  18. return PrescriptionFormState();
  19. }
  20. }
  21. class PrescriptionFormState extends State<PrescriptionForm> {
  22. String? _template;
  23. @override
  24. void initState() {
  25. _initCurrentPatientInfo();
  26. Get.find<ITemplateManager>().getTemplateByKey(widget.formKey).then((value) {
  27. setState(() {
  28. _template = value;
  29. });
  30. });
  31. super.initState();
  32. }
  33. @override
  34. void didUpdateWidget(PrescriptionForm oldWidget) {
  35. if (widget.formKey != oldWidget.formKey) {
  36. setState(() {
  37. _template = null;
  38. });
  39. _initCurrentPatientInfo();
  40. Get.find<ITemplateManager>()
  41. .getTemplateByKey(widget.formKey)
  42. .then((value) {
  43. setState(() {
  44. _template = value;
  45. });
  46. });
  47. }
  48. super.didUpdateWidget(oldWidget);
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. return _template == null
  53. ? Center(
  54. child: CircularProgressIndicator(),
  55. )
  56. : FormView(_template!);
  57. }
  58. void _initCurrentPatientInfo() {
  59. PatientDTO? currentPatient = Store.user.currentSelectPatientInfo;
  60. if (currentPatient != null) {
  61. if (!FormInfo.instance.formValue.containsKey("PatientName")) {
  62. FormInfo.instance.formValue["PatientName"] = currentPatient.patientName;
  63. }
  64. if (currentPatient.birthday != null &&
  65. !FormInfo.instance.formValue.containsKey("PatientAge")) {
  66. var age = DataTimeUtils.calculateAge(
  67. Store.user.currentSelectPatientInfo!.birthday!);
  68. FormInfo.instance.formValue["PatientAge"] = age;
  69. }
  70. if (!FormInfo.instance.formValue.containsKey("PatientGender")) {
  71. if (currentPatient.patientGender == GenderEnum.Male) {
  72. FormInfo.instance.formValue["PatientGender"] = "1";
  73. } else if (currentPatient.patientGender == GenderEnum.Female) {
  74. FormInfo.instance.formValue["PatientGender"] = "2";
  75. }
  76. }
  77. }
  78. }
  79. }