Пример #1
0
 static public TestQuantity BuildQuantityFromDataBaseData(string idQuantity)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findDose    = "SELECT * FROM MedicationQuantity WHERE IdMedicationQuantity = '" + idQuantity + "'";
         SqlCommand DoseCommand = new SqlCommand(findDose, connection);
         using (SqlDataReader DoseReader = DoseCommand.ExecuteReader())
         {
             while (DoseReader.Read())
             {
                 Quantity q = new Quantity();
                 if (DoseReader["Quantity"].ToString() != "")
                 {
                     q.Value = Convert.ToDecimal(DoseReader["Quantity"]);
                 }
                 if (DoseReader["IdUnitClassifier"].ToString() != "")
                 {
                     q.IdUnit = Convert.ToInt32(DoseReader["IdUnitClassifier"]);
                 }
                 return(new TestQuantity(q));
             }
         }
     }
     return(null);
 }
Пример #2
0
 static public TestGuardian BuildTestGuardianFromDataBase(string guardianId, string patientId)
 {
     if ((guardianId != "") && (patientId != ""))
     {
         string findIdRealationTypeString =
             "SELECT TOP(1) * FROM mm_Person2Person WHERE IdPerson = '" + patientId + "' AND IdPersonRelated = '" + guardianId + "'";
         using (SqlConnection connection = Global.GetSqlConnection())
         {
             SqlCommand IdInstitution = new SqlCommand(findIdRealationTypeString, connection);
             Guardian   g             = new Guardian();
             using (SqlDataReader IdRelationTypeReader = IdInstitution.ExecuteReader())
             {
                 while (IdRelationTypeReader.Read())
                 {
                     g.IdRelationType = Convert.ToByte(IdRelationTypeReader["IdRelationType"]);
                     if (Convert.ToString(IdRelationTypeReader["UnderlyingDocument"]) != "")
                     {
                         g.UnderlyingDocument = Convert.ToString(IdRelationTypeReader["UnderlyingDocument"]);
                     }
                     else
                     {
                         g.UnderlyingDocument = null;
                     }
                 }
             }
             TestGuardian guard = new TestGuardian(g);
             guard.person = TestPerson.BuildPersonFromDataBaseData(guardianId);
             return(guard);
         }
     }
     return(null);
 }
Пример #3
0
        static public string GetPersonId(string guid, string idlpu, string mis)
        {
            string patientId          = "";
            string findIdPersonString = "";

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string InstId = Global.GetIdInstitution(idlpu);
                findIdPersonString =
                    "SELECT TOP(1) * FROM ExternalId WHERE IdPersonMIS = '" + mis + "' AND IdLpu = '" + InstId + "' AND SystemGuid = '" + guid.ToLower() + "'";
                SqlCommand command = new SqlCommand(findIdPersonString, connection);
                using (SqlDataReader IdPerson = command.ExecuteReader())
                {
                    while (IdPerson.Read())
                    {
                        patientId = IdPerson["IdPerson"].ToString();
                    }
                }
            }
            if (patientId != "")
            {
                return(patientId);
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
 static public TestClinicMainDiagnosis BuildTestClinicMainDiagnosisFromDataBaseDate(string idStep)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findTD    = "SELECT TOP(1) * FROM Diagnosis WHERE IdDiagnosis = (SELECT MAX(IdDiagnosis) FROM Diagnosis WHERE IdStep = '" + idStep + "' AND IdDiagnosisType = '" + TestDiagnosis.IdClinicMainDiagnosis + "' AND IdParentDiagnosis is NULL)";
         SqlCommand TDcommand = new SqlCommand(findTD, connection);
         using (SqlDataReader TDReader = TDcommand.ExecuteReader())
         {
             while (TDReader.Read())
             {
                 if (TDReader["IdParentDiagnosis"].ToString() == "")
                 {
                     ClinicMainDiagnosis     d  = new ClinicMainDiagnosis();
                     TestClinicMainDiagnosis td = new TestClinicMainDiagnosis(d);
                     td._diagnosis  = TestDiagnosis.BuildDiagnosisFromDataBaseDate(idStep, TDReader["IdDiagnosis"].ToString());
                     td.diagnosInfo = TestDiagnosisInfo.BuildDiagnosisFromDataBaseDate(TDReader["IdDiagnosis"].ToString());
                     if (TDReader["IdDiagnosedDoctor"].ToString() != "")
                     {
                         td.doctor = TestDoctor.BuildTestDoctorFromDataBase(TDReader["IdDiagnosedDoctor"].ToString());
                     }
                     return(td);
                 }
             }
         }
     }
     return(null);
 }
Пример #5
0
        static public TestPerson BuildPersonFromDataBaseData(string personId)
        {
            string mis = GetIDMIS(personId);

            if (personId != null)
            {
                using (SqlConnection connection = Global.GetSqlConnection())
                {
                    string     findPatient = "SELECT TOP(1) * FROM Person WHERE IdPerson = '" + personId + "'";
                    SqlCommand person      = new SqlCommand(findPatient, connection);
                    using (SqlDataReader personFromDataBase = person.ExecuteReader())
                    {
                        PersonWithIdentity p = new PersonWithIdentity();
                        while (personFromDataBase.Read())
                        {
                            if (personFromDataBase["BirthDate"].ToString() != "")
                            {
                                p.Birthdate = Convert.ToDateTime(personFromDataBase["BirthDate"]);
                            }
                            p.Sex = Convert.ToByte(personFromDataBase["IdSex"]);
                        }
                        p.IdPersonMis = mis;
                        TestPerson pers = new TestPerson(p);
                        pers.name      = TestHumanName.BuildHumanNameFromDataBaseData(personId);
                        pers.documents = TestIdentityDocument.BuildDocumentsFromDataBaseData(personId);
                        return(pers);
                    }
                }
            }
            return(null);
        }
Пример #6
0
        static public List <TestContact> BuildContactsFromDataBaseData(string idPerson)
        {
            List <TestContact> contacts = new List <TestContact>();

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string     findPatient = "SELECT * FROM Contact WHERE IdPerson = '" + idPerson + "'";
                SqlCommand person      = new SqlCommand(findPatient, connection);
                using (SqlDataReader contactReader = person.ExecuteReader())
                {
                    while (contactReader.Read())
                    {
                        ContactDto cont = new ContactDto();
                        if (contactReader["IdContactType"].ToString() != "")
                        {
                            cont.IdContactType = Convert.ToByte(contactReader["IdContactType"]);
                        }
                        if (contactReader["ContactValue"].ToString() != "")
                        {
                            cont.ContactValue = Convert.ToString(contactReader["ContactValue"]);
                        }
                        TestContact contact = new TestContact(cont);
                        contacts.Add(contact);
                    }
                }
            }
            if (contacts.Count != 0)
            {
                return(contacts);
            }
            else
            {
                return(null);
            }
        }
Пример #7
0
 static public TestHumanName BuildHumanNameFromDataBaseData(string idPerson)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findPerson    = "SELECT TOP(1) * FROM Person WHERE IdPerson = '" + idPerson + "'";
         SqlCommand commandPerson = new SqlCommand(findPerson, connection);
         using (SqlDataReader humanNameReader = commandPerson.ExecuteReader())
         {
             HumanName hn = new HumanName();
             while (humanNameReader.Read())
             {
                 hn.FamilyName = Convert.ToString(humanNameReader["FamilyName"]);
                 hn.GivenName  = Convert.ToString(humanNameReader["GivenName"]);
                 if (Convert.ToString(humanNameReader["MiddleName"]) != "")
                 {
                     hn.MiddleName = Convert.ToString(humanNameReader["MiddleName"]);
                 }
                 else
                 {
                     hn.MiddleName = null;
                 }
                 return(new TestHumanName(hn));
             }
         }
     }
     return(null);
 }
Пример #8
0
 static public string GetIdIdLpu(string idInst)
 {
     if (Data.type == Type.guid)
     {
         return(idInst);
     }
     else
     {
         if (idInst != "")
         {
             string findIdInstitutionalString =
                 "SELECT TOP(1) * FROM Institution WHERE IdInstitution = '" + idInst + "'";
             using (SqlConnection connection = Global.GetSqlConnection())
             {
                 SqlCommand IdInstitution = new SqlCommand(findIdInstitutionalString, connection);
                 using (SqlDataReader IdInstitutional = IdInstitution.ExecuteReader())
                 {
                     while (IdInstitutional.Read())
                     {
                         return(IdInstitutional["IdFedNsi"].ToString());
                     }
                 }
             }
         }
         return("");
     }
 }
Пример #9
0
 static public TestTfomsInfo BuildTfomsInfoFromDataBaseDate(string idStep)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findTFI    = "SELECT TOP(1) * FROM TfomsInfo WHERE IdTfomsInfo = (SELECT MAX(IdTfomsInfo) FROM TfomsInfo WHERE IdStep = '" + idStep + "')";
         SqlCommand TFIcommand = new SqlCommand(findTFI, connection);
         using (SqlDataReader TFIReader = TFIcommand.ExecuteReader())
         {
             while (TFIReader.Read())
             {
                 TfomsInfo t = new TfomsInfo();
                 if (TFIReader["Count"].ToString() != "")
                 {
                     t.Count = Convert.ToInt32(TFIReader["Count"]);
                 }
                 if (TFIReader["IdRTFORMSMedicalStandard"].ToString() != "")
                 {
                     t.IdTfomsType = Convert.ToInt32(TFIReader["IdRTFORMSMedicalStandard"]);
                 }
                 if (TFIReader["Tariff"].ToString() != "")
                 {
                     t.Tariff = Convert.ToDecimal(TFIReader["Tariff"]);
                 }
                 TestTfomsInfo i = new TestTfomsInfo(t);
                 return(i);
             }
         }
     }
     return(null);
 }
Пример #10
0
        public byte[] GetResultDocument(string GUID, string idLpu, string idCaseMis, int documentType)
        {
            ResultDocument a = client.GetResultDocument(GUID, idLpu, idCaseMis, documentType);

            byte[] b = {};
            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string findPatient =
                    "SELECT TOP(1) Attachment FROM MedDocument, Step, \"Case\" WHERE IdMedDocumentType = '" +
                    documentType +
                    "' AND IdCaseMis = '" + idCaseMis + "' AND IdLpu <= '" + Global.GetIdInstitution(idLpu) +
                    "' AND MedDocument.IdStep = Step.IdStep AND Step.IdCase = \"Case\".IdCase ORDER BY IdMedDocument DESC";
                SqlCommand person = new SqlCommand(findPatient, connection);
                using (SqlDataReader documentReader = person.ExecuteReader())
                {
                    // bool a = documentReader.Read();
                    while (documentReader.Read())
                    {
                        b = (byte[])(documentReader["Attachment"]);
                    }
                }
            }
            if (!a.Data.SequenceEqual(b))
            {
                Global.errors1.Add("Несовпадение базового и возвращенного документов");
            }
            return(a.Data);
        }
Пример #11
0
 static public TestJob BuildTestJobFromDataBase(string idPerson)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findPatient = "SELECT TOP(1) * FROM Job WHERE IdJob = (SELECT MAX(IdJob) FROM Job WHERE IdPerson = '" + idPerson + "')";
         SqlCommand person      = new SqlCommand(findPatient, connection);
         using (SqlDataReader jobReader = person.ExecuteReader())
         {
             while (jobReader.Read())
             {
                 JobDto job = new JobDto();
                 job.CompanyName = Convert.ToString(jobReader["CompanyName"]);
                 if (jobReader["DateStart"].ToString() != "")
                 {
                     job.DateStart = Convert.ToDateTime(jobReader["DateStart"]);
                 }
                 else
                 {
                     job.DateStart = null;
                 }
                 if (jobReader["DateEnd"].ToString() != "")
                 {
                     job.DateEnd = Convert.ToDateTime(jobReader["DateEnd"]);
                 }
                 else
                 {
                     job.DateEnd = null;
                 }
                 if (jobReader["Sphere"].ToString() != "")
                 {
                     job.Sphere = Convert.ToString(jobReader["Sphere"]);
                 }
                 else
                 {
                     job.Sphere = null;
                 }
                 if (jobReader["OgrnCode"].ToString() != "")
                 {
                     job.OgrnCode = Convert.ToString(jobReader["OgrnCode"]);
                 }
                 else
                 {
                     job.OgrnCode = null;
                 }
                 if (jobReader["Position"].ToString() != "")
                 {
                     job.Position = Convert.ToString(jobReader["Position"]);
                 }
                 else
                 {
                     job.Position = null;
                 }
                 TestJob j = new TestJob(job);
                 return(j);
             }
         }
     }
     return(null);
 }
Пример #12
0
        static private string GetPatientId(string guid, string idlpu, string mis)
        {
            string patientId                 = "";
            string findIdPersonString        = "";
            string findIdInstitutionalString =
                "SELECT TOP(1) IdInstitution FROM Institution WHERE IdFedNsi = '" + idlpu + "'";

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                if (Data.type == Type.guid)
                {
                    findIdPersonString =
                        "SELECT TOP(1) * FROM ExternalId WHERE IdPersonMIS = '" + mis + "' AND IdLpu = '" + idlpu + "' AND SystemGuid = '" + guid.ToLower() + "'";
                }
                else
                {
                    SqlCommand IdInstitution = new SqlCommand(findIdInstitutionalString, connection);
                    using (SqlDataReader IdInstitutional = IdInstitution.ExecuteReader())
                    {
                        string InstId = "";
                        while (IdInstitutional.Read())
                        {
                            InstId = IdInstitutional["IdInstitution"].ToString();
                        }
                        findIdPersonString =
                            "SELECT TOP(1) * FROM ExternalId WHERE IdPersonMIS = '" + mis + "' AND IdLpu = '" + InstId + "' AND SystemGuid = '" + guid.ToLower() + "'";
                    }
                }
                SqlCommand command = new SqlCommand(findIdPersonString, connection);
                using (SqlDataReader IdPerson = command.ExecuteReader())
                {
                    while (IdPerson.Read())
                    {
                        patientId = IdPerson["IdPerson"].ToString();
                    }
                }
            }
            if (patientId != "")
            {
                return(patientId);
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
        static private string GetIDMIS(string idPerson)
        {
            string mis = "";

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string     findPatient = "SELECT TOP(1) * FROM ExternalId WHERE IdPerson = '" + idPerson + "'";
                SqlCommand person      = new SqlCommand(findPatient, connection);
                using (SqlDataReader patientFromDataBase = person.ExecuteReader())
                {
                    while (patientFromDataBase.Read())
                    {
                        mis = Convert.ToString(patientFromDataBase["IdPersonMIS"]);
                    }
                }
            }
            return(mis);
        }
Пример #14
0
        static public List <TestDiagnosis> BuildDiagnosisFromDataBaseDate(string IdStep, string IdParentDiagnosis = "")
        {
            List <TestDiagnosis> tdList = new List <TestDiagnosis>();

            if (IdStep != "")
            {
                using (SqlConnection connection = Global.GetSqlConnection())
                {
                    string findTD = "";
                    if (IdParentDiagnosis == "")
                    {
                        findTD = "SELECT * FROM Diagnosis WHERE IdStep = '" + IdStep + "' AND IdDiagnosisType <> '" + IdClinicMainDiagnosis + "' AND IdParentDiagnosis IS NULL";
                    }
                    else
                    {
                        findTD = "SELECT * FROM Diagnosis WHERE IdStep = '" + IdStep + "' AND IdDiagnosisType <> '" + IdClinicMainDiagnosis + "' AND IdParentDiagnosis = '" + IdParentDiagnosis + "'";
                    }
                    SqlCommand TDcommand = new SqlCommand(findTD, connection);
                    using (SqlDataReader TDReader = TDcommand.ExecuteReader())
                    {
                        while (TDReader.Read())
                        {
                            Diagnosis     d  = new Diagnosis();
                            TestDiagnosis td = new TestDiagnosis(d);
                            td.info = TestDiagnosisInfo.BuildDiagnosisFromDataBaseDate(TDReader["IdDiagnosis"].ToString());
                            if (TDReader["IdDiagnosedDoctor"].ToString() != "")
                            {
                                td.doctor = TestDoctor.BuildTestDoctorFromDataBase(TDReader["IdDiagnosedDoctor"].ToString());
                            }
                            tdList.Add(td);
                        }
                    }
                }
            }
            if (tdList.Count != 0)
            {
                return(tdList);
            }
            else
            {
                return(null);
            }
        }
Пример #15
0
        static private string[] GetGUIDandIDLPUandIDMIS(string idPerson)
        {
            string guid  = "";
            string idlpu = "";
            string mis   = "";

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string     findPatient = "SELECT TOP(1) * FROM ExternalId WHERE IdPerson = '" + idPerson + "'";
                SqlCommand person      = new SqlCommand(findPatient, connection);
                using (SqlDataReader patientFromDataBase = person.ExecuteReader())
                {
                    while (patientFromDataBase.Read())
                    {
                        guid = Convert.ToString(patientFromDataBase["SystemGuid"]);
                        mis  = Convert.ToString(patientFromDataBase["IdPersonMIS"]);
                        if (Data.type == Type.guid)
                        {
                            idlpu = Convert.ToString(patientFromDataBase["IdLpu"]);
                        }
                        else
                        {
                            idlpu = Global.GetIdIdLpu(Convert.ToString(patientFromDataBase["IdLpu"]));
                            //string findIdInstitutionalString =
                            //    "SELECT TOP(1) IdFedNsi FROM Institution WHERE IdInstitution = '" + lpu + "'";
                            //using (SqlConnection connection2 = Global.GetSqlConnection())
                            //{
                            //    SqlCommand IdInstitution = new SqlCommand(findIdInstitutionalString, connection2);
                            //    using (SqlDataReader IdInstitutional = IdInstitution.ExecuteReader())
                            //    {
                            //        while (IdInstitutional.Read())
                            //        {
                            //            idlpu = Convert.ToString(IdInstitutional["IdFedNsi"]);
                            //        }
                            //    }
                            //}
                        }
                    }
                }
            }
            string[] s = new string[] { guid, idlpu, mis };
            return(s);
        }
Пример #16
0
        static public List <TestRecommendation> BuildSickListFromDataBaseData(string idDispensaryStage1)
        {
            List <TestRecommendation> llr = new List <TestRecommendation>();

            if (idDispensaryStage1 != "")
            {
                using (SqlConnection connection = Global.GetSqlConnection())
                {
                    string     findR    = "SELECT * FROM Recommendation WHERE idDispensaryStage1 = '" + idDispensaryStage1 + "'";
                    SqlCommand Rcommand = new SqlCommand(findR, connection);
                    using (SqlDataReader RReader = Rcommand.ExecuteReader())
                    {
                        while (RReader.Read())
                        {
                            Recommendation r = new Recommendation();
                            if (RReader["Text"].ToString() != "")
                            {
                                r.Text = RReader["Text"].ToString();
                            }
                            if (RReader["Date"].ToString() != "")
                            {
                                r.Date = Convert.ToDateTime(RReader["Date"]);
                            }
                            TestRecommendation tr = new TestRecommendation(r);
                            if (RReader["IdDoctor"].ToString() != "")
                            {
                                tr.doctor = TestDoctor.BuildTestDoctorFromDataBase(RReader["IdDoctor"].ToString());
                            }
                            llr.Add(tr);
                        }
                    }
                }
            }
            if (llr.Count != 0)
            {
                return(llr);
            }
            else
            {
                return(null);
            }
        }
Пример #17
0
 static public TestDoctor BuildTestDoctorFromDataBase(string doctorId)
 {
     if (doctorId != null)
     {
         using (SqlConnection connection = Global.GetSqlConnection())
         {
             string     findDoctor = "SELECT TOP(1) * FROM Doctor, nsi.DoctorSpec WHERE Doctor.IdDoctor = '" + doctorId + "' AND Doctor.IdSpeciality = nsi.DoctorSpec.IdSpeciality";
             SqlCommand doc        = new SqlCommand(findDoctor, connection);
             using (SqlDataReader doctorReader = doc.ExecuteReader())
             {
                 while (doctorReader.Read())
                 {
                     string       IdPerson = Convert.ToString(doctorReader["IdPerson"]);
                     MedicalStaff ms       = new MedicalStaff();
                     ms.IdPosition   = Convert.ToUInt16(doctorReader["IdPosition"]);
                     ms.IdSpeciality = Convert.ToUInt16(doctorReader["Code"]);
                     ms.IdLpu        = Convert.ToString(doctorReader["IdLpu"]);
                     if (Data.type == Type.oid)
                     {
                         string findIdInstitutionalString =
                             "SELECT TOP(1) * FROM Institution WHERE IdInstitution = '" + ms.IdLpu + "'";
                         using (SqlConnection connection2 = Global.GetSqlConnection())
                         {
                             SqlCommand IdInstitution = new SqlCommand(findIdInstitutionalString, connection2);
                             using (SqlDataReader IdInstitutional = IdInstitution.ExecuteReader())
                             {
                                 while (IdInstitutional.Read())
                                 {
                                     ms.IdLpu = IdInstitutional["IdFedNsi"].ToString();
                                 }
                             }
                         }
                     }
                     TestDoctor p = new TestDoctor(ms);
                     p.person = TestPerson.BuildPersonFromDataBaseData(IdPerson);
                     return(p);
                 }
             }
         }
     }
     return(null);
 }
Пример #18
0
 static public TestBirthplace BuildBirthplaceFromDataBaseData(string idPerson)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findIdAdresses = "SELECT TOP(1) * FROM mm_Person2Address WHERE IdAddress = (SELECT MAX(IdAddress) FROM mm_Person2Address WHERE IdPerson = '" + idPerson + "' AND IdAddressType = '" + 3 + "')";
         SqlCommand IdAddresses    = new SqlCommand(findIdAdresses, connection);
         using (SqlDataReader addressesIdReader = IdAddresses.ExecuteReader())
         {
             while (addressesIdReader.Read())
             {
                 string id = (Convert.ToString(addressesIdReader["IdAddress"]));
                 using (SqlConnection connection2 = Global.GetSqlConnection())
                 {
                     string     findIdAdresses2 = "SELECT TOP(1) * FROM Address WHERE IdAddress = '" + id + "'";
                     SqlCommand IdAddresses2    = new SqlCommand(findIdAdresses2, connection2);
                     using (SqlDataReader addressesReader = IdAddresses2.ExecuteReader())
                     {
                         BirthPlaceDto birthp = new BirthPlaceDto();
                         while (addressesReader.Read())
                         {
                             if (addressesReader["Country"].ToString() != "")
                             {
                                 birthp.Country = Convert.ToString(addressesReader["Country"]);
                             }
                             if (addressesReader["Region"].ToString() != "")
                             {
                                 birthp.Region = Convert.ToString(addressesReader["Region"]);
                             }
                             if (addressesReader["CityName"].ToString() != "")
                             {
                                 birthp.City = Convert.ToString(addressesReader["CityName"]);
                             }
                         }
                         return(new TestBirthplace(birthp));
                     }
                 }
             }
         }
     }
     return(null);
 }
Пример #19
0
 static public TestDeathInfo BuildDeathInfoFromDataBaseDate(string IdStep)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findDI    = "SELECT TOP(1) * FROM DeathInfo WHERE IdDeathInfo = (SELECT MAX(IdDeathInfo) FROM DeathInfo WHERE IdStep = '" + IdStep + "')";
         SqlCommand DIcommand = new SqlCommand(findDI, connection);
         using (SqlDataReader DIReader = DIcommand.ExecuteReader())
         {
             while (DIReader.Read())
             {
                 DeathInfo d = new DeathInfo();
                 if (DIReader["DeathMKBCode"].ToString() != "")
                 {
                     d.MkbCode = Convert.ToString(DIReader["DeathMKBCode"]);
                 }
                 return(new TestDeathInfo(d));
             }
         }
     }
     return(null);
 }
Пример #20
0
 static public TestPrivilege BuildTestPrivilegeFromDataBase(string idPerson)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findPatient = "SELECT TOP(1) * FROM Privilege WHERE IdPrivilege = (SELECT MAX(IdPrivilege) FROM Privilege  WHERE IdPerson = '" + idPerson + "')";
         SqlCommand person      = new SqlCommand(findPatient, connection);
         using (SqlDataReader privilegeReader = person.ExecuteReader())
         {
             while (privilegeReader.Read())
             {
                 PrivilegeDto privilege = new PrivilegeDto();
                 privilege.DateStart       = Convert.ToDateTime(privilegeReader["DateStart"]);
                 privilege.DateEnd         = Convert.ToDateTime(privilegeReader["DateEnd"]);
                 privilege.IdPrivilegeType = Convert.ToByte(privilegeReader["IdPrivilegeType"]);
                 TestPrivilege p = new TestPrivilege(privilege);
                 return(p);
             }
         }
     }
     return(null);
 }
Пример #21
0
 static public string GetCaseId(string guid, string idlpu, string mis, string patientId)
 {
     if (patientId.ToString() != "")
     {
         string caseId           = "";
         string findIdCaseString = "";
         using (SqlConnection connection = Global.GetSqlConnection())
         {
             string InstId = Global.GetIdInstitution(idlpu);
             if (mis != "")
             {
                 findIdCaseString =
                     "SELECT TOP(1) * FROM \"Case\" WHERE IdCase = (SELECT MAX(IdCase) FROM \"Case\" WHERE IdCaseMIS = '" + mis + "' AND IdLpu = '" + InstId + "' AND SystemGuid = '" + guid.ToLower() + "' AND IdPerson = '" + patientId + "')";
             }
             else
             {
                 findIdCaseString =
                     "SELECT TOP(1) * FROM \"Case\" WHERE IdCase = (SELECT MAX(IdCase) FROM \"Case\" WHERE IdCaseType = '" + masterCaseId + "' AND IdLpu = '" + InstId + "' AND SystemGuid = '" + guid.ToLower() + "' AND IdPerson = '" + patientId + "')";
             }
             SqlCommand command = new SqlCommand(findIdCaseString, connection);
             using (SqlDataReader IdCaseReader = command.ExecuteReader())
             {
                 while (IdCaseReader.Read())
                 {
                     caseId = IdCaseReader["IdCase"].ToString();
                 }
             }
         }
         if (caseId != "")
         {
             return(caseId);
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
Пример #22
0
 public void DeletePatient()
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string findIdPersonString =
             "SELECT * FROM ExternalId WHERE IdPersonMIS = '" + patient.IdPatientMIS + "'";
         SqlCommand command = new SqlCommand(findIdPersonString, connection);
         using (SqlDataReader MISreader = command.ExecuteReader())
         {
             string patientId = GetPatientId(GUID, IDLPU, patient.IdPatientMIS);
             while ((MISreader.Read()) && (patientId != null))
             {
                 string command2 = "EXEC dbo.Delete_Patient @IdPatientMIS = '" + patient.IdPatientMIS + "'";
                 using (SqlConnection connection2 = Global.GetSqlConnection())
                 {
                     var SqlComm = new SqlCommand(command2, connection2);
                     SqlComm.ExecuteNonQuery();
                 }
                 patientId = GetPatientId(GUID, IDLPU, patient.IdPatientMIS);
             }
         }
     }
 }
Пример #23
0
        static public TestCaseBase BuildBaseCaseFromDataBaseData(string guid, string idlpu, string mis, string idPerson)
        {
            //idPerson = TestPerson.GetPersonId(guid, idlpu, idPerson);
            string caseId = GetCaseId(guid, idlpu, mis, idPerson);

            if (caseId != null)
            {
                using (SqlConnection connection = Global.GetSqlConnection())
                {
                    string     IdDoctor    = "";
                    string     IdGuardian  = "";
                    int        idCaseT     = 0;
                    bool       isCanceld   = false;
                    CaseBase   p           = new CaseBase();
                    string     findCase    = "SELECT TOP(1) * FROM \"Case\" WHERE IdCase = '" + caseId + "'";
                    SqlCommand caseCommand = new SqlCommand(findCase, connection);
                    using (SqlDataReader caseReader = caseCommand.ExecuteReader())
                    {
                        while (caseReader.Read())
                        {
                            if (caseReader["CloseDate"].ToString() != "")
                            {
                                p.CloseDate = Convert.ToDateTime(caseReader["CloseDate"]);
                            }
                            else
                            {
                                p.CloseDate = DateTime.MinValue;
                            }
                            if (caseReader["Comment"].ToString() != "")
                            {
                                p.Comment = Convert.ToString(caseReader["Comment"]);
                            }
                            else
                            {
                                p.Comment = null;
                            }
                            if (caseReader["HistoryNumber"].ToString() != "")
                            {
                                p.HistoryNumber = Convert.ToString(caseReader["HistoryNumber"]);
                            }
                            else
                            {
                                p.HistoryNumber = null;
                            }
                            if (caseReader["IdCaseAidType"].ToString() != "")
                            {
                                p.IdCaseAidType = Convert.ToByte(caseReader["IdCaseAidType"]);
                            }
                            else
                            {
                                p.IdCaseAidType = 0;
                            }
                            if (caseReader["IdCaseMis"].ToString() != "")
                            {
                                p.IdCaseMis = Convert.ToString(caseReader["IdCaseMis"]);
                            }
                            else
                            {
                                p.IdCaseMis = null;
                            }
                            if (caseReader["IdCaseResult"].ToString() != "")
                            {
                                p.IdCaseResult = Convert.ToByte(caseReader["IdCaseResult"]);
                            }
                            else
                            {
                                p.IdCaseResult = 0;
                            }
                            if (caseReader["IdCasePaymentType"].ToString() != "")
                            {
                                p.IdPaymentType = Convert.ToByte(caseReader["IdCasePaymentType"]);
                            }
                            else
                            {
                                p.IdPaymentType = 0;
                            }
                            if (caseReader["OpenDate"].ToString() != "")
                            {
                                p.OpenDate = Convert.ToDateTime(caseReader["OpenDate"]);
                            }
                            else
                            {
                                p.OpenDate = DateTime.MinValue;
                            }
                            if (caseReader["IDDoctor"].ToString() != "")
                            {
                                IdDoctor = Convert.ToString(caseReader["IDDoctor"]);
                            }
                            if (caseReader["IdGuardian"].ToString() != "")
                            {
                                IdGuardian = Convert.ToString(caseReader["IDGuardian"]);
                            }
                            if (caseReader["IdCaseType"].ToString() != "")
                            {
                                idCaseT = Convert.ToInt32(caseReader["IdCaseType"]);
                            }
                            isCanceld = Convert.ToBoolean(caseReader["IsCancelled"]);
                        }
                    }
                    findCase    = "SELECT * FROM mm_AccessRole2Case WHERE IdCase = '" + caseId + "'";
                    caseCommand = new SqlCommand(findCase, connection);
                    using (SqlDataReader caseReader = caseCommand.ExecuteReader())
                    {
                        while (caseReader.Read())
                        {
                            switch (caseReader["IdAccessRole"].ToString())
                            {
                            case "1":
                                p.Confidentiality = Convert.ToByte(caseReader["IdPrivacyLevel"]);
                                break;

                            case "2":
                                p.DoctorConfidentiality = Convert.ToByte(caseReader["IdPrivacyLevel"]);
                                break;

                            case "3":
                                p.CuratorConfidentiality = Convert.ToByte(caseReader["IdPrivacyLevel"]);
                                break;
                            }
                        }
                    }
                    p.IdCaseMis = mis;
                    p.IdLpu     = idlpu;
                    TestCaseBase cb = new TestCaseBase(guid, p);
                    cb.idCaseType = idCaseT;
                    cb.isCanceld  = isCanceld;
                    if (IdDoctor != "")
                    {
                        cb.doctorInCharge = TestDoctor.BuildTestDoctorFromDataBase(IdDoctor);
                    }
                    else
                    {
                        cb.doctorInCharge = null;
                    }
                    if (IdGuardian != "")
                    {
                        cb.guardian = TestGuardian.BuildTestGuardianFromDataBase(IdGuardian, idPerson);
                    }
                    else
                    {
                        cb.guardian = null;
                    }
                    if (idPerson != "")
                    {
                        cb.patient = TestPatient.BuildPatientFromDataBaseData(patientId: idPerson);
                    }
                    else
                    {
                        cb.patient = null;
                    }
                    findCase    = "SELECT * FROM mm_Author2Case WHERE IdCase = '" + caseId + "'";
                    caseCommand = new SqlCommand(findCase, connection);
                    using (SqlDataReader caseReader = caseCommand.ExecuteReader())
                    {
                        while (caseReader.Read())
                        {
                            switch (caseReader["IdAuthorshipType"].ToString())
                            {
                            case "1":
                                cb.autor = TestParticipant.BuildTestParticipantFromDataBase(caseId, Convert.ToString(caseReader["IdDoctor"]), 1);
                                break;

                            case "3":
                                cb.authenticator = TestParticipant.BuildTestParticipantFromDataBase(caseId, Convert.ToString(caseReader["IdDoctor"]), 3);
                                break;

                            case "4":
                                cb.legalAuthenticator = TestParticipant.BuildTestParticipantFromDataBase(caseId, Convert.ToString(caseReader["IdDoctor"]), 4);
                                break;
                            }
                        }
                    }
                    return(cb);
                }
            }
            return(null);
        }
Пример #24
0
        static public List <TestStepBase> BuildTestStepsFromDataBase(string idCase, string stepLpu)
        {
            List <TestStepBase> steps = new List <TestStepBase>();

            if (idCase != string.Empty)
            {
                using (SqlConnection connection = Global.GetSqlConnection())
                {
                    string     findSteps    = "SELECT * FROM Step WHERE IdCase = '" + idCase + "'";
                    SqlCommand stepsCommand = new SqlCommand(findSteps, connection);
                    using (SqlDataReader stepsReader = stepsCommand.ExecuteReader())
                    {
                        while (stepsReader.Read())
                        {
                            StepBase sb = new StepBase();
                            if (stepsReader["Comment"].ToString() != "")
                            {
                                sb.Comment = Convert.ToString(stepsReader["Comment"]);
                            }
                            else
                            {
                                sb.Comment = null;
                            }
                            if (stepsReader["DateEnd"].ToString() != "")
                            {
                                sb.DateEnd = Convert.ToDateTime(stepsReader["DateEnd"]);
                            }
                            else
                            {
                                sb.DateEnd = DateTime.MinValue;
                            }
                            if (stepsReader["DateStart"].ToString() != "")
                            {
                                sb.DateStart = Convert.ToDateTime(stepsReader["DateStart"]);
                            }
                            else
                            {
                                sb.DateStart = DateTime.MinValue;
                            }
                            if (stepsReader["IdPaymentType"].ToString() != "")
                            {
                                sb.IdPaymentType = Convert.ToByte(stepsReader["IdPaymentType"]);
                            }
                            else
                            {
                                sb.IdPaymentType = 0;
                            }
                            if (stepsReader["IdStepMis"].ToString() != "")
                            {
                                sb.IdStepMis = Convert.ToString(stepsReader["IdStepMis"]);
                            }
                            else
                            {
                                sb.IdStepMis = null;
                            }
                            TestStepBase step = new TestStepBase(sb, stepLpu);
                            if (stepsReader["IdDoctor"].ToString() != "")
                            {
                                step.doctor = TestDoctor.BuildTestDoctorFromDataBase(stepsReader["IdDoctor"].ToString());
                            }
                            else
                            {
                                step.doctor = null;
                            }
                            step.idStep = Convert.ToString(stepsReader["IdStep"]);
                            steps.Add(step);
                        }
                    }
                }
            }
            if (steps.Count != 0)
            {
                return(steps);
            }
            else
            {
                return(null);
            }
        }
Пример #25
0
 static public TestDiagnosisInfo BuildDiagnosisFromDataBaseDate(string idDiagnosis)
 {
     using (SqlConnection connection = Global.GetSqlConnection())
     {
         string     findTD    = "SELECT * FROM Diagnosis WHERE IdDiagnosis = '" + idDiagnosis + "'";
         SqlCommand TDcommand = new SqlCommand(findTD, connection);
         using (SqlDataReader TDReader = TDcommand.ExecuteReader())
         {
             while (TDReader.Read())
             {
                 DiagnosisInfo d = new DiagnosisInfo();
                 if (TDReader["Comment"].ToString() != "")
                 {
                     d.Comment = Convert.ToString(TDReader["Comment"]);
                 }
                 if (TDReader["DiagnosedDate"].ToString() != "")
                 {
                     d.DiagnosedDate = Convert.ToDateTime(TDReader["DiagnosedDate"]);
                 }
                 if (TDReader["IdRDiagnosisChangeReason"].ToString() != "")
                 {
                     d.DiagnosisChangeReason = Convert.ToByte(TDReader["IdRDiagnosisChangeReason"]);
                 }
                 if (TDReader["IdDiagnoseStage"].ToString() != "")
                 {
                     d.DiagnosisStage = Convert.ToByte(TDReader["IdDiagnoseStage"]);
                 }
                 if (TDReader["IdDiagnosisType"].ToString() != "")
                 {
                     d.IdDiagnosisType = Convert.ToByte(TDReader["IdDiagnosisType"]);
                 }
                 if (TDReader["IdDiseaseType"].ToString() != "")
                 {
                     d.IdDiseaseType = Convert.ToByte(TDReader["IdDiseaseType"]);
                 }
                 if (TDReader["IdRDispensaryState"].ToString() != "")
                 {
                     d.IdDispensaryState = Convert.ToByte(TDReader["IdRDispensaryState"]);
                 }
                 if (TDReader["IdTraumaType"].ToString() != "")
                 {
                     d.IdTraumaType = Convert.ToByte(TDReader["IdTraumaType"]);
                 }
                 if (TDReader["IdRMedicalStandard"].ToString() != "")
                 {
                     d.MedicalStandard = Convert.ToInt32(TDReader["IdRMedicalStandard"]);
                 }
                 if (TDReader["IdRMESImplementationFeature"].ToString() != "")
                 {
                     d.MESImplementationFeature = Convert.ToByte(TDReader["IdRMESImplementationFeature"]);
                 }
                 if (TDReader["MkbCode"].ToString() != "")
                 {
                     d.MkbCode = Convert.ToString(TDReader["MkbCode"]);
                 }
                 return(new TestDiagnosisInfo(d));
             }
         }
     }
     return(null);
 }
Пример #26
0
        public void GetCasesByPeriod(string GUID, DateTime datestart, DateTime dateend)
        {
            List <TestCaseBase> MyFindedCase = new List <TestCaseBase>();

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                string findCaseString =
                    "SELECT * FROM \"Case\" WHERE OpenDate >= '" + datestart + "' AND OpenDate <= '" + dateend + "' AND CloseDate IS NOT NULL AND IsCancelled = 'False'";
                SqlCommand command = new SqlCommand(findCaseString, connection);
                using (SqlDataReader IdCaseReader = command.ExecuteReader())
                {
                    while (IdCaseReader.Read())
                    {
                        string      guid      = IdCaseReader["SystemGuid"].ToString();
                        string      idCaseMis = IdCaseReader["IdCaseMIS"].ToString();
                        string      idLpu     = Global.GetIdIdLpu(IdCaseReader["IdLpu"].ToString());
                        string      patientId = IdCaseReader["IdPerson"].ToString();
                        TestAmbCase ambCase   = TestAmbCase.BuildAmbCaseFromDataBaseData(guid, idLpu, idCaseMis, patientId);
                        if ((object)ambCase != null)
                        {
                            MyFindedCase.Add(ambCase);
                        }
                        TestStatCase statCase = TestStatCase.BuildAmbCaseFromDataBaseData(guid, idLpu, idCaseMis, patientId);
                        if ((object)statCase != null)
                        {
                            MyFindedCase.Add(statCase);
                        }
                        string idCase = IdCaseReader["IdCase"].ToString();
                    }
                }
            }
            CaseBase[]          cb = client.GetCasesByPeriod(GUID, datestart, dateend);
            List <TestCaseBase> FunctionFindedCase = new List <TestCaseBase>();

            foreach (CaseBase i in cb)
            {
                CaseAmb ca = i as CaseAmb;
                if ((object)ca != null)
                {
                    using (SqlConnection connection = Global.GetSqlConnection())
                    {
                        string findCaseString =
                            "SELECT TOP(1) [SystemGuid] FROM \"ExternalId\" WHERE IdLpu = '" + Global.GetIdInstitution(ca.IdLpu) + "' AND IdPersonMIS = '" + ca.IdPatientMis + "'";
                        SqlCommand command = new SqlCommand(findCaseString, connection);
                        using (SqlDataReader IdCaseReader = command.ExecuteReader())
                        {
                            while (IdCaseReader.Read())
                            {
                                GUID = IdCaseReader["SystemGuid"].ToString();
                            }
                        }
                    }
                    TestAmbCase tac = new TestAmbCase(GUID, (EMKServise.CaseAmb)ConvertCase(ca));
                    //if (!tac.CheckCaseInDataBase())
                    //    Global.errors1.Add("Что-то пошло не так");
                    FunctionFindedCase.Add(tac);
                }
                CaseStat cs = i as CaseStat;
                if ((object)cs != null)
                {
                    using (SqlConnection connection = Global.GetSqlConnection())
                    {
                        string findCaseString =
                            "SELECT TOP(1) [SystemGuid] FROM \"ExternalId\" WHERE IdLpu = '" + Global.GetIdInstitution(cs.IdLpu) + "' AND IdPersonMIS = '" + cs.IdPatientMis + "'";
                        SqlCommand command = new SqlCommand(findCaseString, connection);
                        using (SqlDataReader IdCaseReader = command.ExecuteReader())
                        {
                            while (IdCaseReader.Read())
                            {
                                GUID = IdCaseReader["SystemGuid"].ToString();
                            }
                        }
                    }
                    TestStatCase tsc = new TestStatCase(GUID, (EMKServise.CaseStat)ConvertCase(cs));
                    //if (!tsc.CheckCaseInDataBase())
                    //    Global.errors1.Add("Что-то пошло не так");
                    FunctionFindedCase.Add(tsc);
                }
            }
            if (Global.GetLength(MyFindedCase) > Global.GetLength(FunctionFindedCase))
            {
                Global.errors1.Add("Возвращено меньше, чем в базе");
            }
            if (Global.GetLength(MyFindedCase) < Global.GetLength(FunctionFindedCase))
            {
                Global.errors1.Add("Возвращено больше, чем в базе");
            }
            if (Global.GetLength(MyFindedCase) == Global.GetLength(FunctionFindedCase))
            {
                if (!Global.IsEqual(MyFindedCase.ToArray(), FunctionFindedCase.ToArray()))
                {
                    Global.errors1.AddRange(Global.errors2);
                }
            }
        }
Пример #27
0
        static public List <TestIdentityDocument> BuildDocumentsFromDataBaseData(string idPerson)
        {
            List <TestIdentityDocument> documents = new List <TestIdentityDocument>();

            using (SqlConnection connection = Global.GetSqlConnection())
            {
                foreach (int i in Enum.GetValues(typeof(docs)))
                {
                    string     findPatient = "SELECT TOP(1) * FROM Document WHERE IdDocument = (SELECT MAX(IdDocument) FROM Document WHERE IdPerson = '" + idPerson + "' AND IdDocumentType = '" + i + "')";
                    SqlCommand person      = new SqlCommand(findPatient, connection);
                    using (SqlDataReader documentReader = person.ExecuteReader())
                    {
                        // bool a = documentReader.Read();
                        while (documentReader.Read())
                        {
                            IdentityDocument doc = new IdentityDocument();
                            if (documentReader["DocN"].ToString() != "")
                            {
                                doc.DocN = Convert.ToString(documentReader["DocN"]);
                            }
                            if (documentReader["ProviderName"].ToString() != "")
                            {
                                doc.ProviderName = Convert.ToString(documentReader["ProviderName"]);
                            }
                            if (documentReader["IdDocumentType"].ToString() != "")
                            {
                                doc.IdDocumentType = Convert.ToByte(documentReader["IdDocumentType"]);
                            }
                            if (documentReader["DocS"].ToString() != "")
                            {
                                doc.DocS = Convert.ToString(documentReader["DocS"]);
                            }
                            if (documentReader["IdProvider"].ToString() != "")
                            {
                                doc.IdProvider = Convert.ToInt32(documentReader["IdProvider"]);
                            }
                            if (documentReader["IssuedDate"].ToString() != "")
                            {
                                doc.IssuedDate = Convert.ToDateTime(documentReader["IssuedDate"]);
                            }
                            if (documentReader["ExpiredDate"].ToString() != "")
                            {
                                doc.ExpiredDate = Convert.ToDateTime(documentReader["ExpiredDate"]);
                            }
                            if (documentReader["RegionCode"].ToString() != "")
                            {
                                doc.RegionCode = Convert.ToString(documentReader["RegionCode"]);
                            }
                            TestIdentityDocument document = new TestIdentityDocument(doc);
                            documents.Add(document);
                        }
                    }
                }
            }
            if (documents.Count != 0)
            {
                return(documents);
            }
            else
            {
                return(null);
            }
        }
Пример #28
0
        static public List <TestSickList> BuildSickListFromDataBaseData(string idStep, string patientId)
        {
            List <TestSickList> tsl = new List <TestSickList>();

            if (idStep != "")
            {
                List <TestAttachment> lta = TestAttachment.BuildTestAttacmentFromDataBase(idStep, idSickList);
                if (lta != null)
                {
                    foreach (TestAttachment i in lta)
                    {
                        using (SqlConnection connection = Global.GetSqlConnection())
                        {
                            string     findSL    = "SELECT * FROM SickList WHERE IdMedDocument = '" + i.idMedDocument + "'";
                            SqlCommand SLcommand = new SqlCommand(findSL, connection);
                            using (SqlDataReader SLReader = SLcommand.ExecuteReader())
                            {
                                while (SLReader.Read())
                                {
                                    SickList r = new SickList();
                                    r.SickListInfo = new SickListInfo();
                                    if (SLReader["Number"].ToString() != "")
                                    {
                                        r.SickListInfo.Number = Convert.ToString(SLReader["Number"]);
                                    }
                                    if (SLReader["DateStart"].ToString() != "")
                                    {
                                        r.SickListInfo.DateStart = Convert.ToDateTime(SLReader["DateStart"]);
                                    }
                                    if (SLReader["DateEnd"].ToString() != "")
                                    {
                                        r.SickListInfo.DateEnd = Convert.ToDateTime(SLReader["DateEnd"]);
                                    }
                                    if (SLReader["IdRDisabilityDocStatus"].ToString() != "")
                                    {
                                        r.SickListInfo.DisabilityDocState = Convert.ToByte(SLReader["IdRDisabilityDocStatus"]);
                                    }
                                    if (SLReader["IdRDisabilityDocReason"].ToString() != "")
                                    {
                                        r.SickListInfo.DisabilityDocReason = Convert.ToByte(SLReader["IdRDisabilityDocReason"]);
                                    }
                                    if (SLReader["IsPatient"].ToString() != "")
                                    {
                                        r.SickListInfo.IsPatientTaker = Convert.ToBoolean(SLReader["IsPatient"]);
                                    }
                                    r.CreationDate = i.CreationDate;
                                    r.Header       = i.DocHead;
                                    TestSickList tr = new TestSickList(r);
                                    tr.attachment = i;
                                    tr.doctor     = TestDoctor.BuildTestDoctorFromDataBase(i.IdDoctor);
                                    if (SLReader["IdCareGiver"].ToString() != "")
                                    {
                                        tr.guardian = TestGuardian.BuildTestGuardianFromDataBase(SLReader["IdCareGiver"].ToString(), patientId);
                                    }
                                    tsl.Add(tr);
                                }
                            }
                        }
                    }
                }
            }
            if (tsl.Count != 0)
            {
                return(tsl);
            }
            else
            {
                return(null);
            }
        }
Пример #29
0
        //public TestReferral(ReferralDto r)
        //{
        //    referral = new Referral
        //    {
        //        ReferralInfo = new ReferralInfo
        //        {
        //            IdReferralType = Convert.ToByte(r.IdReferralType),
        //            IdReferralMis = r.IdReferralMis,
        //            IssuedDateTime = r.IssuedDateTime,
        //            //r.IdUrgencyType;
        //            MkbCode = r.MkbCode,
        //            Reason = r.Reason
        //        },
        //        IdSourceLpu = r.IdSourceLpu,
        //        IdTargetLpu = r.IdTargetLpu,
        //        //r.IdLPU;
        //    };
        //    attachment = new TestAttachment(new MedDocument.DocumentAttachment());
        //    doctor = TestDoctor.BuildTestDoctorFromDataBase(r.IdDoctorRef);
        //    departmentHead = TestDoctor.BuildTestDoctorFromDataBase(r.IdRefDepartmentHead);
        //}
        static public List <TestReferral> BuildReferralFromDataBaseData(string idStep)
        {
            List <TestReferral> trl = new List <TestReferral>();

            if (idStep != "")
            {
                List <TestAttachment> lta = TestAttachment.BuildTestAttacmentFromDataBase(idStep, idReferral);
                if (lta != null)
                {
                    foreach (TestAttachment i in lta)
                    {
                        using (SqlConnection connection = Global.GetSqlConnection())
                        {
                            string     findR    = "SELECT * FROM Referral WHERE IdMedDocument = '" + i.idMedDocument + "'";
                            SqlCommand Rcommand = new SqlCommand(findR, connection);
                            using (SqlDataReader RReader = Rcommand.ExecuteReader())
                            {
                                while (RReader.Read())
                                {
                                    Referral r = new Referral();
                                    r.ReferralInfo = new ReferralInfo();
                                    if (RReader["MkbCode"].ToString() != "")
                                    {
                                        r.ReferralInfo.MkbCode = Convert.ToString(RReader["MkbCode"]);
                                    }
                                    if (RReader["IdSourceLpu"].ToString() != "")
                                    {
                                        r.IdSourceLpu = Global.GetIdIdLpu(Convert.ToString(RReader["IdSourceLpu"]));
                                    }
                                    if (RReader["IdTargetLpu"].ToString() != "")
                                    {
                                        r.IdTargetLpu = Global.GetIdIdLpu(Convert.ToString(RReader["IdTargetLpu"]));
                                    }
                                    if (RReader["Reason"].ToString() != "")
                                    {
                                        r.ReferralInfo.Reason = Convert.ToString(RReader["Reason"]);
                                    }
                                    if (RReader["IdReferralMIS"].ToString() != "")
                                    {
                                        r.ReferralInfo.IdReferralMis = Convert.ToString(RReader["IdReferralMIS"]);
                                    }
                                    if (RReader["IdReferralType"].ToString() != "")
                                    {
                                        r.ReferralInfo.IdReferralType = Convert.ToByte(RReader["IdReferralType"]);
                                    }
                                    if (RReader["IssuedDateTime"].ToString() != "")
                                    {
                                        r.ReferralInfo.IssuedDateTime = Convert.ToDateTime(RReader["IssuedDateTime"]);
                                    }
                                    if (RReader["IdHospitalizationOrder"].ToString() != "")
                                    {
                                        r.ReferralInfo.HospitalizationOrder = Convert.ToByte(RReader["IdHospitalizationOrder"]);
                                    }
                                    if (RReader["ReferralId"].ToString() != "")
                                    {
                                        r.ReferralID = Convert.ToString(RReader["ReferralId"]);
                                    }
                                    if (RReader["RelatedId"].ToString() != "")
                                    {
                                        r.RelatedID = Convert.ToString(RReader["RelatedId"]);
                                    }
                                    r.CreationDate = i.CreationDate;
                                    r.Header       = i.DocHead;
                                    //Тут нет ReferalId и referedId
                                    TestReferral tr = new TestReferral(r);
                                    tr.attachment = i;
                                    if (RReader["IdRefDepartmentHead"].ToString() != "")
                                    {
                                        tr.departmentHead = TestDoctor.BuildTestDoctorFromDataBase((RReader["IdRefDepartmentHead"]).ToString());
                                    }
                                    tr.doctor = TestDoctor.BuildTestDoctorFromDataBase(i.IdDoctor);
                                    trl.Add(tr);
                                }
                            }
                        }
                    }
                }
            }
            if (trl.Count != 0)
            {
                return(trl);
            }
            else
            {
                return(null);
            }
        }
Пример #30
0
 static public TestAmbCase BuildAmbCaseFromDataBaseData(string guid, string idlpu, string mis, string patientId)
 {
     if ((guid != string.Empty) && (idlpu != string.Empty) && (mis != string.Empty) && (patientId != string.Empty))
     {
         string caseId = TestCaseBase.GetCaseId(guid, idlpu, mis, patientId);
         if (caseId != null)
         {
             CaseAmb ca = new CaseAmb();
             using (SqlConnection connection = Global.GetSqlConnection())
             {
                 string     findCase    = "SELECT TOP(1) * FROM AmbCase WHERE IdCase = '" + caseId + "'";
                 SqlCommand caseCommand = new SqlCommand(findCase, connection);
                 using (SqlDataReader caseReader = caseCommand.ExecuteReader())
                 {
                     while (caseReader.Read())
                     {
                         if (caseReader["IdCasePurpose"].ToString() != "")
                         {
                             ca.IdCasePurpose = Convert.ToByte(caseReader["IdCasePurpose"]);
                         }
                         if (caseReader["IdAmbResult"].ToString() != "")
                         {
                             ca.IdAmbResult = Convert.ToByte(caseReader["IdAmbResult"]);
                         }
                         if (caseReader["IsActive"].ToString() != "")
                         {
                             ca.IsActive = Convert.ToBoolean(caseReader["IsActive"]);
                         }
                         TestAmbCase ambcase = new TestAmbCase(guid, ca);
                         ambcase.caseBase = TestCaseBase.BuildBaseCaseFromDataBaseData(guid, idlpu, mis, patientId);
                         ambcase.ambSteps = TestAmbStep.BuildAmbTestStepsFromDataBase(caseId, ca.IdLpu);
                         List <TestStepBase> st = TestStepBase.BuildTestStepsFromDataBase(caseId, ca.IdLpu);
                         if (st != null)
                         {
                             foreach (TestStepBase i in st)
                             {
                                 if (Global.IsEqual(i.step.IdStepMis, null))
                                 {
                                     ambcase.defaultStep = i;
                                 }
                             }
                             if (!Global.IsEqual(ambcase.defaultStep, null))
                             {
                                 ambcase.records = new List <TestMedRecord>();
                                 List <TestService> ser = TestService.BuildServiseFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(ser, null))
                                 {
                                     ambcase.records.AddRange(ser);
                                 }
                                 TestTfomsInfo forms = TestTfomsInfo.BuildTfomsInfoFromDataBaseDate(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(forms, null))
                                 {
                                     ambcase.records.Add(forms);
                                 }
                                 TestDeathInfo tdi = TestDeathInfo.BuildDeathInfoFromDataBaseDate(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(tdi, null))
                                 {
                                     ambcase.records.Add(tdi);
                                 }
                                 List <TestDiagnosis> td = TestDiagnosis.BuildDiagnosisFromDataBaseDate(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(td, null))
                                 {
                                     ambcase.records.AddRange(td);
                                 }
                                 TestClinicMainDiagnosis acdm = TestClinicMainDiagnosis.BuildTestClinicMainDiagnosisFromDataBaseDate(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(acdm, null))
                                 {
                                     ambcase.records.Add(acdm);
                                 }
                                 List <TestReferral> trl = TestReferral.BuildReferralFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(trl, null))
                                 {
                                     ambcase.records.AddRange(trl);
                                 }
                                 List <TestSickList> tsl = TestSickList.BuildSickListFromDataBaseData(ambcase.defaultStep.idStep, patientId);
                                 if (!Global.IsEqual(tsl, null))
                                 {
                                     ambcase.records.AddRange(tsl);
                                 }
                                 TestDischargeSummary tds = TestDischargeSummary.BuildSickListFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(tds, null))
                                 {
                                     ambcase.records.Add(tds);
                                 }
                                 List <TestLaboratoryReport> tlr = TestLaboratoryReport.BuildLaboratoryReportFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(tlr, null))
                                 {
                                     ambcase.records.AddRange(tlr);
                                 }
                                 TestConsultNote tcn = TestConsultNote.BuildSickListFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(tcn, null))
                                 {
                                     ambcase.records.Add(tcn);
                                 }
                                 TestDispensaryOne d1 = TestDispensaryOne.BuildSickListFromDataBaseData(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(d1, null))
                                 {
                                     ambcase.records.Add(d1);
                                 }
                                 List <TestAppointedMedication> ap = TestAppointedMedication.BuildAppointedMedicationFromDataBaseDate(ambcase.defaultStep.idStep);
                                 if (!Global.IsEqual(ap, null))
                                 {
                                     ambcase.records.AddRange(ap);
                                 }
                                 if (ambcase.records.Count == 0)
                                 {
                                     ambcase.records = null;
                                 }
                             }
                         }
                         return(ambcase);
                     }
                 }
             }
         }
     }
     return(null);
 }