import 'package:fis_jsonrpc/rpc.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:vitalapp/architecture/utils/datetime.dart'; import 'package:vitalapp/managers/interfaces/template.dart'; import 'package:vitalapp/pages/form/form_info.dart'; import 'package:vitalapp/pages/form/form_view.dart'; import 'package:vitalapp/store/store.dart'; import 'prescription_form_keys.dart'; ///处方表 class PrescriptionForm extends StatefulWidget { final String formKey; PrescriptionForm(this.formKey); @override State createState() { return PrescriptionFormState(); } } class PrescriptionFormState extends State { String? _template; @override void initState() { _initCurrentPatientInfo(); Get.find().getTemplateByKey(widget.formKey).then((value) { setState(() { _template = value; }); }); super.initState(); } @override void didUpdateWidget(PrescriptionForm oldWidget) { if (widget.formKey != oldWidget.formKey) { setState(() { _template = null; }); _initCurrentPatientInfo(); Get.find() .getTemplateByKey(widget.formKey) .then((value) { setState(() { _template = value; }); }); } super.didUpdateWidget(oldWidget); } @override Widget build(BuildContext context) { return _template == null ? Center( child: CircularProgressIndicator(), ) : FormView(_template!); } void _initCurrentPatientInfo() { PatientDTO? currentPatient = Store.user.currentSelectPatientInfo; if (currentPatient != null) { if (!FormInfo.instance.formValue.containsKey("PatientName")) { FormInfo.instance.formValue["PatientName"] = currentPatient.patientName; } if (currentPatient.birthday != null && !FormInfo.instance.formValue.containsKey("PatientAge")) { var age = DataTimeUtils.calculateAge( Store.user.currentSelectPatientInfo!.birthday!); FormInfo.instance.formValue["PatientAge"] = age; } if (!FormInfo.instance.formValue.containsKey("PatientGender")) { if (currentPatient.patientGender == GenderEnum.Male) { FormInfo.instance.formValue["PatientGender"] = "1"; } else if (currentPatient.patientGender == GenderEnum.Female) { FormInfo.instance.formValue["PatientGender"] = "2"; } } } } }