123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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 'package:fis_common/logger/logger.dart';
- import 'prescription_form_keys.dart';
- ///处方表
- class PrescriptionForm extends StatefulWidget {
- final String formKey;
- PrescriptionForm(this.formKey);
- @override
- State<StatefulWidget> createState() {
- return PrescriptionFormState();
- }
- }
- class PrescriptionFormState extends State<PrescriptionForm> {
- String? _template;
- @override
- void initState() {
- _initCurrentPatientInfo();
- Get.find<ITemplateManager>().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<ITemplateManager>()
- .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() {
- try {
- 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";
- }
- }
- }
- } catch (e) {
- logger.e('PrescriptionForm _initCurrentPatientInfo ex:', e);
- }
- }
- }
|