Exemplo n.º 1
0
        public async Task <List <Prescription_Model> > GetAllPrescriptions(long patientId)
        {
            List <Prescription_Model> allPrescriptions = new List <Prescription_Model>();

            try
            {
                SqlCommand cmd = new SqlCommand
                {
                    Connection  = cn,
                    CommandType = System.Data.CommandType.Text,
                    CommandText = " SELECT  p.*, min(pa.AlertDateTime) as NextAlert FROM Prescription p " +
                                  " join PrescriptionAlert pa on pa.PrescriptionId = p.PrescriptionId " +
                                  " where p.PatientId = @patientId and p.IsActive = 1 and pa.IsActive = 1" +
                                  " group by p.PrescriptionId, Ndc, PrescriptionName, " +
                                  " PatientId, Color, Dosage, Identifier, Shape, Rxcui, ImageUrl, DoctorNote, " +
                                  " Warning, OriginalNumberOfDoses, CurrentNumberOfDoses, OriginalNumberOfRefills, CurrentNumberOfRefills, p.IsActive," +
                                  " EnteredBy, EnteredDate, ModifiedBy, ModifiedDate"
                };

                cmd.Parameters.AddWithValue("@patientId", patientId);

                await cn.OpenAsync().ConfigureAwait(false);

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        allPrescriptions.Add(DataRowToAllPrescriptionsMapper.Map(reader));
                    }
                }

                return(allPrescriptions);
            }
            catch (Exception ex)
            {
                throw new DatabaseException($"Something went wrong getting all prescriptions for patientId: {patientId}", ex);
            }
            finally
            {
                cn.Close();
            }
        }
Exemplo n.º 2
0
        public async Task <Prescription_Model> GetPrescription(int prescriptionId)
        {
            Prescription_Model model = new Prescription_Model();

            try
            {
                SqlCommand cmd = new SqlCommand
                {
                    Connection  = cn,
                    CommandType = System.Data.CommandType.Text,
                    CommandText = " SELECT p.*, min(pa.AlertDateTime) as NextAlert FROM Prescription p " +
                                  " JOIN PrescriptionAlert pa on pa.PrescriptionId = p.PrescriptionId " +
                                  " WHERE p.PrescriptionId = @PrescriptionId AND pa.IsActive = 1 AND p.IsActive = 1 " +
                                  " group by p.PrescriptionId,Ndc,PrescriptionName,PatientId,Color,Dosage,Identifier,Shape,Rxcui,ImageUrl,DoctorNote, " +
                                  " Warning,OriginalNumberOfDoses,CurrentNumberOfDoses,OriginalNumberOfRefills,CurrentNumberOfRefills,p.IsActive, " +
                                  " EnteredBy,EnteredDate,ModifiedBy,ModifiedDate"
                };
                cmd.Parameters.AddWithValue("@PrescriptionId", prescriptionId);

                await cn.OpenAsync().ConfigureAwait(false);

                using (var reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        model = DataRowToAllPrescriptionsMapper.Map(reader);
                    }
                }
                return(model);
            }
            catch (Exception ex)
            {
                throw new DatabaseException($"Something went wrong getting the prescription info for prescriptionId {prescriptionId}", ex);
            }
            finally
            {
                cn.Close();
            }
        }