Example #1
0
 static public TestPatient BuildPatientFromDataBaseData(string guid = null, string idlpu = null, string mis = null, string patientId = null)
 {
     if (patientId == null)
     {
         patientId = GetPatientId(guid, idlpu, mis);
     }
     else
     {
         string[] s = GetGUIDandIDLPUandIDMIS(patientId);
         guid  = s[0];
         idlpu = s[1];
         mis   = s[2];
     }
     if (patientId != null)
     {
         using (SqlConnection connection = Global.GetSqlConnection())
         {
             string     findPatient = "SELECT TOP(1) * FROM Person, PatientAdditionalInfo WHERE Person.IdPerson = '" + patientId + "' AND Person.IdPerson = PatientAdditionalInfo.IdPerson";
             SqlCommand person      = new SqlCommand(findPatient, connection);
             using (SqlDataReader patientFromDataBase = person.ExecuteReader())
             {
                 while (patientFromDataBase.Read())
                 {
                     PatientDto p = new PatientDto();
                     if (patientFromDataBase["FamilyName"].ToString() != "")
                     {
                         p.FamilyName = Convert.ToString(patientFromDataBase["FamilyName"]);
                     }
                     else
                     {
                         p.FamilyName = null;
                     }
                     if (patientFromDataBase["MiddleName"].ToString() != "")
                     {
                         p.MiddleName = Convert.ToString(patientFromDataBase["MiddleName"]);
                     }
                     else
                     {
                         p.MiddleName = null;
                     }
                     if (patientFromDataBase["GivenName"].ToString() != "")
                     {
                         p.GivenName = Convert.ToString(patientFromDataBase["GivenName"]);
                     }
                     else
                     {
                         p.GivenName = null;
                     }
                     p.BirthDate = Convert.ToDateTime(patientFromDataBase["BirthDate"]);
                     p.Sex       = Convert.ToByte(patientFromDataBase["IdSex"]);
                     p.IsVip     = Convert.ToBoolean(patientFromDataBase["IsVip"]);
                     if (patientFromDataBase["IdSocialStatus"].ToString() != "")
                     {
                         p.SocialStatus = Convert.ToString(patientFromDataBase["IdSocialStatus"]);
                     }
                     else
                     {
                         p.SocialStatus = null;
                     }
                     if (patientFromDataBase["IdSocialGroup"].ToString() != "")
                     {
                         p.SocialGroup = Convert.ToByte(patientFromDataBase["IdSocialGroup"]);
                     }
                     else
                     {
                         p.SocialGroup = null;
                     }
                     if (patientFromDataBase["IdLivingAreaType"].ToString() != "")
                     {
                         p.IdLivingAreaType = Convert.ToByte(patientFromDataBase["IdLivingAreaType"]);
                     }
                     else
                     {
                         p.IdLivingAreaType = null;
                     }
                     if (patientFromDataBase["IdBloodType"].ToString() != "")
                     {
                         p.IdBloodType = Convert.ToByte(patientFromDataBase["IdBloodType"]);
                     }
                     else
                     {
                         p.IdBloodType = null;
                     }
                     if (patientFromDataBase["DeathTime"].ToString() != "")
                     {
                         p.DeathTime = Convert.ToDateTime(patientFromDataBase["DeathTime"]);
                     }
                     else
                     {
                         p.DeathTime = null;
                     }
                     p.IdPatientMIS = mis;
                     p.IdGlobal     = patientId;
                     TestPatient patient = new TestPatient(guid, idlpu, p);
                     patient.documents  = TestDocument.BuildDocumentsFromDataBaseData(patientId);
                     patient.addreses   = TestAddress.BuildAdressesFromDataBaseData(patientId);
                     patient.contacts   = TestContact.BuildContactsFromDataBaseData(patientId);
                     patient.job        = TestJob.BuildTestJobFromDataBase(patientId);
                     patient.privilege  = TestPrivilege.BuildTestPrivilegeFromDataBase(patientId);
                     patient.birthplace = TestBirthplace.BuildBirthplaceFromDataBaseData(patientId);
                     return(patient);
                 }
             }
         }
     }
     return(null);
 }