public ArrayList Find(string guid, string idlpu, TestPatient patient) { string findPatient = ""; if (patient.patient.IdPatientMIS != null) { findPatient = "SELECT * FROM ExternalId WHERE IdPersonMIS = '" + patient.patient.IdPatientMIS + "' AND SystemGuid = '" + guid + "'"; } else { if (patient.patient.Sex == 0) { findPatient = "SELECT * FROM Person WHERE FamilyName = '" + patient.patient.FamilyName + "' AND GivenName ='" + patient.patient.GivenName + "' AND BirthDate ='" + patient.patient.BirthDate + "'"; } else { findPatient = "SELECT * FROM Person WHERE FamilyName = '" + patient.patient.FamilyName + "' AND GivenName ='" + patient.patient.GivenName + "' AND BirthDate ='" + patient.patient.BirthDate + "' AND IdSex ='" + patient.patient.Sex + "'"; } } // ContactPersonDto p = new ContactPersonDto(); ArrayList patients = new ArrayList(); string patientId = ""; using (SqlConnection connection = Global.GetSqlConnection()) { SqlCommand findPatients = new SqlCommand(findPatient, connection); using (SqlDataReader patientsReader = findPatients.ExecuteReader()) { //int i = 0; while (patientsReader.Read()) { patientId = Convert.ToString(patientsReader["IdPerson"]); if (patient.documents != null) { string findDoc = ""; if (patient.documents[0].document.DocS != null) { findDoc = "SELECT * FROM Document WHERE IdPerson = '" + patientId + "' AND DocS ='" + patient.documents[0].document.DocS + "' AND DocN ='" + patient.documents[0].document.DocN + "'"; } else { findDoc = "SELECT * FROM Document WHERE IdPerson = '" + patientId + "' AND DocN ='" + patient.documents[0].document.DocN + "'"; } using (SqlConnection connection2 = Global.GetSqlConnection()) { SqlCommand findPatients2 = new SqlCommand(findDoc, connection2); using (SqlDataReader patientsReader2 = findPatients2.ExecuteReader()) { string addedId = ""; while (patientsReader2.Read()) { if (addedId != patientId) { TestPatient patientFromDb = TestPatient.BuildPatientFromDataBaseData(patientId: patientId); addedId = patientId; patientFromDb.GUID = guid; patientFromDb.IDLPU = idlpu; patients.Add(patientFromDb); } } } } } else { TestPatient patientFromDb2 = TestPatient.BuildPatientFromDataBaseData(patientId: patientId); patients.Add(patientFromDb2); } } } } return(patients); }