Exemplo n.º 1
0
        public Qs2000State GetState(TFileData query)
        {
            string    testsFile = GlobalConfigVars.DbPath + "\\" + "Tests.qsd";
            TestsFile test      = ParseTestsFile(testsFile);

            string tfile = GlobalConfigVars.DbPath + "\\" + GetTFile(query.SeqNum);
            TFile  tFile = ParseTFile(tfile);
            string dfile = GlobalConfigVars.DbPath + "\\" + GetDFile(query.SeqNum);
            DFile  dFile = ParseDFile(dfile, tFile.Header.Identity.Name, tFile.Header.Identity.GelSize);
            // 查找配置
            TestProperties tp = test.Tests.Where(t => t.Identity.Equals(tFile.Header.Identity)).First();

            int         idx   = query.Id - 1;
            Qs2000State state = new Qs2000State
            {
                SeqNum      = query.SeqNum.ToString(),
                SampleNum   = query.Id.ToString(),
                SampleId    = tFile.Datas[idx].Patient.Demographic[0],
                ScannedDate = tFile.Datas[idx].ScanDate.ToString("yyyy/MM/dd HH:mm:ss"),
                Scan        = dFile.Scans[idx].DestBytes,
                TestType    = tFile.Header.Identity.Name
            };

            if (!tp.bIFE)
            {
                StdScan scan = dFile.Scans[idx] as StdScan;
                state.Result = new Qs2000Result(scan.Data, scan.Fraction, tp.Fraction);
            }
            return(state);
        }
Exemplo n.º 2
0
        public TestsFile ParseTestsFile(string testsFile)
        {
            TestsFile result = new TestsFile();

            using (var fs = File.OpenRead(testsFile))
            {
                using (var br = new BinaryReader(fs))
                {
                    TestsFileHeader header = new TestsFileHeader();
                    header.RecSizeLabel = ConvertToString(br.ReadBytes(8));
                    header.RecSize      = br.ReadInt32();
                    header.Unknown      = br.ReadInt32();
                    result.Header       = header;

                    result.Tests = new List <TestProperties>();
                    while (fs.Length > fs.Position)
                    {
                        var test = new TestProperties();
                        using (var ms = new MemoryStream(br.ReadBytes(header.RecSize)))
                        {
                            using (var br1 = new BinaryReader(ms))
                            {
                                // 读取TestIdentity
                                var identity = new TestIdentity();
                                // identity.Name = ConvertToString(br1.ReadBytes(21));
                                identity.Name       = ConvertToGBString(br1.ReadBytes(21));
                                identity.Instrument = ConvertToString(br1.ReadBytes(11));
                                identity.GelSize    = br1.ReadInt16();
                                identity.StainType  = br1.ReadInt16();
                                test.Identity       = identity;

                                //
                                test.bIFE            = br1.ReadBoolean();
                                test.Units           = ConvertToString(br1.ReadBytes(11));
                                test.TotalUnits      = ConvertToString(br1.ReadBytes(11));
                                test.AutoEditOptions = br1.ReadByte();
                                test.Precision       = br1.ReadInt16();
                                test.UnitsFullScale  = br1.ReadInt16();
                                test.ImageContrast   = br1.ReadInt16();

                                // 读取DemoIdentity
                                var demos = new List <DemoIdentity>();
                                for (int i = 0; i < 10; i++)
                                {
                                    DemoIdentity d = new DemoIdentity();
                                    d.Label     = ConvertToString(br1.ReadBytes(21));
                                    d.Type      = br1.ReadByte();
                                    d.ASTMField = br1.ReadByte();
                                    demos.Add(d);
                                }
                                test.Demo = demos;

                                // 读取RangeSet
                                var rs = new List <Range>();
                                for (int i = 0; i < 9; i++)
                                {
                                    Range r = new Range();
                                    r.Sex          = ConvertToString(br1.ReadBytes(2));
                                    r.Type         = br1.ReadByte();
                                    r.AgeLow       = br1.ReadByte();
                                    r.AgeLowUnits  = br1.ReadByte();
                                    r.AgeHigh      = br1.ReadByte();
                                    r.AgeHighUnits = br1.ReadByte();
                                    rs.Add(r);
                                }
                                test.RangeSet = rs;

                                br1.ReadByte();

                                // 读取Ratio
                                var ratios = new List <Ratio>();
                                for (int i = 0; i < 2; i++)
                                {
                                    Ratio r = new Ratio();
                                    r.Label  = Encoding.ASCII.GetString(br1.ReadBytes(12));
                                    r.dRange = new List <KeyValuePair <double, double> >();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair <double, double> t = new KeyValuePair <double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        r.dRange.Add(t);
                                    }
                                    ratios.Add(r);
                                }
                                test.Ratio = ratios;

                                // 读取Fraction
                                var fractions = new List <Fraction>();
                                for (int i = 0; i < 10 + 1; i++)
                                {
                                    Fraction f = new Fraction();
                                    f.Label = ConvertToString(br1.ReadBytes(13));
                                    f.Ratio = new List <byte>();
                                    f.Ratio.Add(br1.ReadByte());
                                    f.Ratio.Add(br1.ReadByte());
                                    f.bIstd     = br1.ReadBoolean();
                                    f.dPctRange = new List <KeyValuePair <double, double> >();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair <double, double> t = new KeyValuePair <double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dPctRange.Add(t);
                                    }
                                    f.dUnitsRange = new List <KeyValuePair <double, double> >();
                                    for (int j = 0; j < 9; j++)
                                    {
                                        KeyValuePair <double, double> t = new KeyValuePair <double, double>(br1.ReadDouble(), br1.ReadDouble());
                                        f.dUnitsRange.Add(t);
                                    }
                                    fractions.Add(f);
                                }
                                test.Fraction = fractions;

                                // 不读取了
                                //test.RstrctBandLabel = ConvertToString(br1.ReadBytes(18));
                                //test.Reserved = Encoding.ASCII.GetString(br1.ReadBytes(2));
                                //test.Options = br1.ReadByte();
                            }
                        }
                        result.Tests.Add(test);
                    }
                }
            }
            return(result);
        }