Browse Source

查询AI报告

Jeremy 2 years ago
parent
commit
c9a866ab22
1 changed files with 77 additions and 1 deletions
  1. 77 1
      ReportService/Service/ReportService.cs

+ 77 - 1
ReportService/Service/ReportService.cs

@@ -15,6 +15,8 @@ using WingServerCommon.Config;
 using WingInterfaceLibrary.DTO.Share;
 using WingServerCommon.Config.Parameters;
 using ReportService.Posters;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json;
 
 namespace ReportService.Service
 {
@@ -35,6 +37,7 @@ namespace ReportService.Service
         private IEmailService _emailService;
         private ISMSService _smsService;
         private IShareDBService _shareDBService;
+        private IRemedicalService _remedicalService;
         private string _messageUrl = ConfigurationManager.GetParammeter<StringParameter>("Report", "MessageUrl").Value;
         private string _reportUrl = ConfigurationManager.GetParammeter<StringParameter>("Report", "ReportUrl").Value;
         private string _reportMessageTemplateId = ConfigurationManager.GetParammeter<StringParameter>("Report", "ReportMessageTemplateId").Value;
@@ -57,6 +60,7 @@ namespace ReportService.Service
             _emailService = GetProxy<IEmailService>();
             _smsService = GetProxy<ISMSService>();
             _shareDBService = GetProxy<IShareDBService>();
+            _remedicalService = GetProxy<IRemedicalService>();
         }
 
         /// <summary>
@@ -81,7 +85,13 @@ namespace ReportService.Service
             var reportInfo = await _reportDBService.GetReportByCodeAsync(new GetReportByCodeDBRequest { ReportCode = request.ReportCode });
             if (reportInfo.DiagnosisLabels.Contains("VAid"))
             {
-                //var reportElments = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReportElementDTO>>(reportInfo.ReportDatasJson);
+                var reportElments = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ReportElementDTO>>(reportInfo.ReportDatasJson, new ReportElementDTOConverter());
+                var newElements = await _remedicalService.GetReportElementByLanguageAsync(new GetReportElementByLanguageRequest
+                {
+                    ReportElemets = reportElments,
+                    Language = request.Language,
+                });
+                reportInfo.ReportDatasJson = Newtonsoft.Json.JsonConvert.SerializeObject(newElements);
             }
             return reportInfo;
         }
@@ -990,6 +1000,72 @@ namespace ReportService.Service
             }
             return await _reportDBService.CopyThesaurusAsync(request.ThesaurusCode, string.Empty, userInfo.RootOrganizationCode);
         }
+
+    public class ReportElementDTOConverter : JsonCreationConverter<ReportElementDTO>
+    {
+        protected override ReportElementDTO Create(Type objectType, JObject jObject)
+        {
+            if (FieldExists("Value", jObject, out object value))
+            {
+                Console.WriteLine(value.GetType());
+                if (value is JArray)
+                {
+                    return new ReportElementArrayDTO();
+                }
+            }
+            return new ReportElementStringDTO();
+        }
+
+        private bool FieldExists(string fieldName, JObject jObject, out object value)
+        {
+            value = jObject[fieldName];
+            return jObject[fieldName] != null;
+        }
+    }
+
+    public abstract class JsonCreationConverter<T> : JsonConverter
+    {
+        /// <summary>
+        /// Create an instance of objectType, based properties in the JSON object
+        /// </summary>
+        /// <param name="objectType">type of object expected</param>
+        /// <param name="jObject">
+        /// contents of JSON object that will be deserialized
+        /// </param>
+        /// <returns></returns>
+        protected abstract T Create(Type objectType, JObject jObject);
+
+        public override bool CanConvert(Type objectType)
+        {
+            return typeof(T).IsAssignableFrom(objectType);
+        }
+
+        public override bool CanWrite
+        {
+            get { return false; }
+        }
+
+        public override object ReadJson(JsonReader reader,
+                                        Type objectType,
+                                         object existingValue,
+                                         JsonSerializer serializer)
+        {
+            // Load JObject from stream
+            JObject jObject = JObject.Load(reader);
+
+            // Create target object based on JObject
+            T target = Create(objectType, jObject);
+
+            // Populate the object properties
+            serializer.Populate(jObject.CreateReader(), target);
+
+            return target;
+        }
+        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+        {
+            throw new NotImplementedException();
+        }
+    }
     }
 }