Эх сурвалжийг харах

fixed:0018691: 【web/PC端】所有随访表都不显示题目;所有处方不显示处方题目;体检表不显示内容

loki.wu 10 сар өмнө
parent
commit
15547baf87

+ 10 - 3
lib/managers/template.dart

@@ -2,6 +2,7 @@ import 'dart:convert';
 
 import 'package:fis_common/index.dart';
 import 'package:fis_jsonrpc/rpc.dart';
+import 'package:flutter/foundation.dart';
 import 'package:flutter/services.dart';
 import 'package:vitalapp/architecture/storage/file_storage_native_and_web.dart';
 import 'package:vitalapp/architecture/storage/text_storage.dart';
@@ -166,11 +167,17 @@ class TemplateManager implements ITemplateManager {
 
   @override
   Future<String> getTemplateByKey(String key) async {
+    logger.i("TemplateManager getTemplateByKey:$key");
     var templates = await readTemplateRelation('templateRelation');
-    var templateRelation = jsonDecode(templates!);
-    var templateCode = templateRelation[key] ?? '';
-    var template = await readTemplate(templateCode) ?? '';
+    String template = '';
+    if (templates != null) {
+      var templateRelation = jsonDecode(templates);
+      var templateCode = templateRelation[key] ?? '';
+      template = await readTemplate(templateCode) ?? '';
+    }
     String templateContent = '';
+    logger.i(
+        "TemplateManager getTemplateByKey $key template.isEmpty :${template.isEmpty}");
     if (template.isEmpty) {
       var json = await loadJsonFromAssets(
           'assets/templates/PrescriptionTemplates/${key}.json');

+ 24 - 7
lib/pages/check/maternal_health_management/controller.dart

@@ -1,7 +1,10 @@
 import 'dart:convert';
 
 import 'package:fis_common/index.dart';
+import 'package:fis_common/logger/logger.dart';
 import 'package:fis_jsonrpc/rpc.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/services.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/managers/interfaces/follow_up.dart';
 import 'package:vitalapp/managers/interfaces/prescription.dart';
@@ -314,13 +317,27 @@ class MaternalHealthManagementController extends GetxController {
   }
 
   Future<String> getTemplate(String key) async {
-    var templates =
-        await _templateManager.readTemplateRelation('templateRelation');
-    var templateRelation = jsonDecode(templates!);
-    templateCode = templateRelation[key] ?? '';
-    var template = await _templateManager.readTemplate(templateCode) ?? '';
-    String templateContent =
-        TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
+    String templateContent = '';
+    try {
+      var templates =
+          await _templateManager.readTemplateRelation('templateRelation');
+      if (templates != null) {
+        var templateRelation = jsonDecode(templates!);
+        templateCode = templateRelation[key] ?? '';
+        var template = await _templateManager.readTemplate(templateCode) ?? '';
+        templateContent =
+            TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
+      }
+    } catch (e) {
+      logger.e("getTemplate ex:", e);
+    }
+    if (templateContent.isEmpty) {
+      final json = await rootBundle.loadString("assets/templates/$key.json");
+      if (json.isNotEmpty) {
+        var content = jsonDecode(json);
+        templateContent = jsonEncode(content["Content"]);
+      }
+    }
     return templateContent;
   }
 

+ 22 - 17
lib/pages/check/prescription/prescription_form.dart

@@ -8,7 +8,7 @@ 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';
 
 ///处方表
@@ -65,24 +65,29 @@ class PrescriptionFormState extends State<PrescriptionForm> {
   }
 
   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";
+    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);
     }
   }
 }

+ 12 - 6
lib/pages/check/widgets/configurable_card.dart

@@ -82,6 +82,8 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
   /// 当前最新的模板的键值对
   Map<String, dynamic> templateRelation = {};
 
+  String templateCode = '';
+
   /// 当前模板数据
   List<FormObject> currentTemplate = [];
 
@@ -274,16 +276,20 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
             "ConfigurableCard - fetchTemplate Template not exist key: $key.");
         currentTemplate = [];
         setState(() {});
-        return;
+        if (!FPlatform.isWindows) {
+          return;
+        }
       }
       // if (templateContent.isNullOrEmpty)
       //   template = await _templateManager.readTemplate(templateRelation[key]!);
       // if (templateContent.isNullOrEmpty)
       //   templateContent =
       List<Map<String, dynamic>> list = [];
-      var template =
-          await _templateManager.readTemplate(templateRelation[key]!);
-
+      String? template;
+      if (templateRelation.containsKey(key)) {
+        templateCode = templateRelation[key]!;
+        template = await _templateManager.readTemplate(templateCode);
+      }
       if (template == null) {
         var json = await loadJsonFromAssets('assets/templates/${key}.json');
         list = jsonDecode(json)["Content"].cast<Map<String, dynamic>>();
@@ -369,7 +375,7 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
                     onTap: () {
                       widget.onClickPrescribe?.call(
                         widget.cardKey,
-                        templateRelation[widget.cardKey]!,
+                        templateCode,
                         jsonEncode(formValue),
                       );
                     },
@@ -406,7 +412,7 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
                     }
                     final result = await widget.callBack(
                       widget.cardKey,
-                      templateRelation[widget.cardKey]!,
+                      templateCode,
                       jsonEncode(formValue),
                       prescriptionKey,
                     );

+ 14 - 7
lib/pages/check/widgets/new_configurable_card.dart

@@ -80,6 +80,8 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
   /// 当前最新的模板的键值对
   Map<String, dynamic> templateRelation = {};
 
+  String templateCode = '';
+
   /// 当前模板数据
   List<FormObject> currentTemplate = [];
 
@@ -223,7 +225,7 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
       await widget.callBack(
         //辅助检查
         "FZJC",
-        templateRelation['FZJC']!,
+        templateCode,
         jsonEncode(urinaryItems),
         false,
       );
@@ -232,7 +234,7 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
       await widget.callBack(
         //一般状况
         "ZZYBZK",
-        templateRelation['ZZYBZK']!,
+        templateCode,
         jsonEncode(normalItems),
         false,
       );
@@ -241,7 +243,7 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
       await widget.callBack(
         //脏器及查体
         "ZQCT",
-        templateRelation['ZQCT']!,
+        templateCode,
         jsonEncode(organsItems),
         false,
       );
@@ -251,7 +253,7 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
   Future<void> submit(bool isManual) async {
     await widget.callBack(
       widget.cardKey,
-      templateRelation[widget.cardKey]!,
+      templateCode,
       jsonEncode(formValue),
       isManual,
     );
@@ -380,14 +382,19 @@ class NewConfigurableFormState extends State<NewConfigurableCard> {
             "ConfigurableCard - fetchTemplate Template not exist key: $key.");
         currentTemplate = [];
         setState(() {});
-        return;
+        if (!FPlatform.isWindows) {
+          return;
+        }
       }
       // if (templateContent.isNullOrEmpty)
       //   template = await _templateManager.readTemplate(templateRelation[key]!);
       // if (templateContent.isNullOrEmpty)
       //   templateContent =
-      var template =
-          await _templateManager.readTemplate(templateRelation[key]!);
+      String? template;
+      if (templateRelation.containsKey(key)) {
+        templateCode = templateRelation[key]!;
+        template = await _templateManager.readTemplate(templateCode);
+      }
       List<Map<String, dynamic>> list = [];
       if (template == null) {
         var json = await loadJsonFromAssets('assets/templates/${key}.json');

+ 23 - 7
lib/pages/traditional_chinese_medicine_constitution/widget/tcm_card.dart

@@ -1,8 +1,10 @@
 import 'dart:convert';
 import 'dart:math';
 
+import 'package:fis_common/index.dart';
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/architecture/storage/text_storage.dart';
 import 'package:vitalapp/architecture/utils/prompt_box.dart';
@@ -544,14 +546,23 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
       if (templateRelation[key] == null) {
         currentTemplate = [];
         setState(() {});
-        return;
+        if (!FPlatform.isWindows) {
+          return;
+        }
+      }
+      List<Map<String, dynamic>> list = [];
+      String? template;
+      if (templateRelation.containsKey(key)) {
+        template = await _templateManager.readTemplate(templateRelation[key]!);
+      }
+      if (template == null) {
+        var json = await loadJsonFromAssets('assets/templates/${key}.json');
+        list = jsonDecode(json)["Content"].cast<Map<String, dynamic>>();
+      } else {
+        var templateContent =
+            TemplateDTO.fromJson(jsonDecode(template)).templateContent!;
+        list = jsonDecode(templateContent).cast<Map<String, dynamic>>();
       }
-      var template =
-          await _templateManager.readTemplate(templateRelation[key]!);
-      String templateContent =
-          TemplateDTO.fromJson(jsonDecode(template!)).templateContent!;
-      List<Map<String, dynamic>> list =
-          jsonDecode(templateContent).cast<Map<String, dynamic>>();
       for (var i in list) {
         if (i['children'] != null) {
           List<FormObject> currentChildren = [];
@@ -576,6 +587,11 @@ class _ConfigurableFormState extends State<TCMConstitutionModule> {
     }
   }
 
+  Future<String> loadJsonFromAssets(String filePath) async {
+    String jsonString = await rootBundle.loadString(filePath);
+    return jsonString;
+  }
+
   Widget buildSingleItem(Widget item, int span) {
     return Column(
       children: [