public Procedure GetProcedure(int patientId, params Procedure.LazyComponents[] lazyComponents) { Procedure procedures = new Procedure(); using (SqlConnection conn = new SqlConnection(connString)) { string sql = BuildProcedureSQL(); string from = @"FROM dbo.Procedure_To_Patient AS a"; string where = @" WHERE a.PatientId = @PatientId "; foreach (Procedure.LazyComponents a in lazyComponents) { if (a == Procedure.LazyComponents.LOAD_PROCEDURE_WITH_DETAIL) { sql += @", b.CategoryId as 'b.CategoryId', b.Label as 'b.Label', b.OtherFlag as 'b.OtherFlag', b.Description as 'b.Description', b.Concentration as 'b.Concentration' "; from += @" INNER JOIN dbo.Dropdown_Types as b ON a.ProcedureId = b.Id "; } } sql = sql + from + where; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@PatientId", SqlDbType.Int).Value = patientId; try { conn.Open(); SqlDataReader read = cmd.ExecuteReader(); while (read.Read()) { procedures = new ProcedureCallback().ProcessRow(read, lazyComponents); } } catch (Exception e) { throw e; } finally { conn.Close(); } } return procedures; }
public void CreateProcedure(Procedure proc) { using (SqlConnection conn = new SqlConnection(connString)) { string sql = @"INSERT INTO dbo.Procedure_To_Patient ( PatientId, ProcedureId ) VALUES ( @PatientId, @ProcedureId )"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@PatientId", SqlDbType.Int).Value = proc.PatientId; cmd.Parameters.Add("@ProcedureId", SqlDbType.DateTime).Value = proc.ProcedureInformation.Id; try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception e) { throw e; } finally { conn.Close(); } } }