songjun
2024-09-04 cc908053e0b5075fbfd27350b6da4b39bca9e550
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
 
namespace BatchService.Framework.Utility.DatabaseHelper
{
    [Serializable]
    public class LISOutputResultInfo
    {
        public string sampleDate { get; set; }
        public string instrument { get; set; }
        public string sampleNo { get; set; }
        public string patientId { get; set; }
        public string orderNo { get; set; }
        public string barcode { get; set; }
        public string patientName { get; set; }
        public string patientGender { get; set; }
        public string patientAge { get; set; }
        public string patientType { get; set; }
        public string itemCode { get; set; }
        public string itemName { get; set; }
        public string printOrder { get; set; }
        public string result { get; set; }
        public string unit { get; set; }
        public string report_limit { get; set; }
 
        public string Load(string sampleDate, string patientId)
        {
            var connString = ConfigHelper.ReadConnectionConfig("LISDBContext", "");
            DateTime dt1 = DateTime.Parse(sampleDate);
            DateTime dt2 = DateTime.Now;
            string sql = string.Format("select * from tb_current_sample_info where sample_date>'{0}' and sample_date<='{1}' and left(instrument,3)<>'@#@'",
                dt1.ToString("yyyy-MM-dd"),
                dt2.ToString("yyyy-MM-dd"));
            if (!string.IsNullOrEmpty(patientId))
            {
                sql += string.Format(" and patient_id='{0}'", patientId);
            }
            var jsonArray = JsonConvert.DeserializeObject(new LISHelper().ExecuteQueySQL(connString, sql)) as JArray;
 
            List<LISOutputResultInfo> results = new List<LISOutputResultInfo>();
 
            if (jsonArray != null)
            {
                foreach (JObject row in jsonArray)
                {
                    string instrument = StringHelper.GetString(row["INSTRUMENT"]);
                    sampleDate = StringHelper.GetString(row["SAMPLE_DATE"]);
                    string sampleNo = StringHelper.GetString(row["SAMPLE_NO"]);
 
                    var itemResults = JsonConvert.DeserializeObject(new LISHelper().ExecuteSampleQueryAction(
                    ConfigHelper.ReadConnectionConfig("LISDBContext", ""),
                     LISHelper.SampleQueryActionType.ValidatedReulstInfo_TB_LABRESULT,
                     instrument,
                     sampleDate,
                     sampleNo)) as JArray;
                    if (itemResults == null)
                    {
                        continue;
                    }
                    foreach (JObject row_result in itemResults)
                    {
                        LISOutputResultInfo resultInfo = new LISOutputResultInfo();
                        results.Add(resultInfo);
                        resultInfo.barcode = StringHelper.GetString(row["BARCODE"]);
                        resultInfo.instrument = instrument;
                        resultInfo.sampleDate = sampleDate;
                        resultInfo.sampleNo = sampleNo;
                        resultInfo.itemCode = StringHelper.GetString(row_result["item_no"]);
                        resultInfo.itemName = StringHelper.GetString(row_result["item_name"]);
                        resultInfo.orderNo = StringHelper.GetString(row["ORDER_NO"]);
                        resultInfo.patientAge = StringHelper.GetString(row["AGE"]);
                        resultInfo.patientGender = StringHelper.GetString(row["GENDER"]);
                        resultInfo.patientId = StringHelper.GetString(row["PATIENT_ID"]);
                        resultInfo.patientName = StringHelper.GetString(row["PATIENT_NAME"]);
                        resultInfo.patientType = StringHelper.GetString(row["PATIENT_TYPE"]);
                        resultInfo.printOrder = StringHelper.GetString(row_result["print_order"]);
                        resultInfo.report_limit = StringHelper.GetString(row_result["ref"]);
                        resultInfo.result = StringHelper.GetString(row_result["result"]);
                        resultInfo.unit = StringHelper.GetString(row_result["unit"]);
                    }
                }
            }
            return JsonConvert.SerializeObject(results);
        }
    }
}