public async Task <PrescriptionResponse> Create(PrescriptionRequest prescriptionRequest) { var response = new PrescriptionResponse(); try { TTAC tTAC = new TTAC(_serviceProvider); Prescription prescription = new Prescription(); prescriptionRequest.CopyPropertiesTo(prescription); await _PrescriptionRepository.Add(prescription); TTACPrescriptionRequest tTACPrescriptionRequest = new TTACPrescriptionRequest(); TTACPrescriptionResponse tTACPrescriptionResponse = new TTACPrescriptionResponse(); prescriptionRequest.CopyPropertiesTo(tTACPrescriptionRequest); tTACPrescriptionRequest.Username = Constants.TTAC_UserName; tTACPrescriptionRequest.Password = Constants.TTAC_Password; tTACPrescriptionResponse = await tTAC.CallPrescriptionApi(tTACPrescriptionRequest); response.ErrorCode = tTACPrescriptionResponse.ErrorCode; response.ErrorMessage = tTACPrescriptionResponse.ErrorMessage; response.PrescriptionId = tTACPrescriptionResponse.PrescriptionId; prescription.OutErrorCode = tTACPrescriptionResponse.ErrorCode; prescription.OutErrorMessage = tTACPrescriptionResponse.ErrorMessage; prescription.OutPrescriptionId = tTACPrescriptionResponse.PrescriptionId; await _PrescriptionRepository.Update(prescription); response.HasError = false; return(response); } catch (Exception e) { _logService.LogText("PrescriptionInternalError" + e.Message.ToString()); throw new Exception(e.Message); } }
public IActionResult GetPrescriptions(int id) { using (SqlConnection con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; com.CommandText = "select * from dbo.Medicament, dbo.Prescription_Medicament, dbo.Prescription where dbo.Medicament.IdMedicament = dbo.Prescription_Medicament.IdMedicament and dbo.Prescription_Medicament.IdPrescription = dbo.Prescription.IdPrescription and dbo.Prescription.IdPrescription = @id"; com.Parameters.AddWithValue("id", id); var request = new PrescriptionRequest(); con.Open(); var response = new PrescriptionResponse(); SqlDataReader dr = com.ExecuteReader(); List<String> lista = new List<string>(); while (dr.Read()) { response.IdDoctor = (int)dr["IdDoctor"]; response.Date = (DateTime)dr["Date"]; response.DueDate = (DateTime)dr["DueDate"]; response.IdPatient = (int)dr["IdPatient"]; response.IdPrescription = (int)dr["IdPrescription"]; lista.Add((string)dr["Name"]); } response.Leki = lista; return Ok(response); } return BadRequest("XD"); }
public List <PrescriptionResponse> GetLek(string id) { var result = new List <PrescriptionResponse>(); try { using (SqlConnection con = new SqlConnection(ConnString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; con.Open(); com.CommandText = "select Prescription.IdPrescription, Prescription.Date, Prescription.DueDate, Prescription.IdPatient, Prescription.IdDoctor, Prescription_Medicament.Dose, Prescription_Medicament.Details from Prescription join Prescription_Medicament on Prescription.IdPrescription = Prescription_Medicament.IdPrescription join Medicament on Prescription_Medicament.IdMedicament = Medicament.IdMedicament" + " where Medicament.IdMedicament = @id order by Date desc; "; com.Parameters.AddWithValue("id", id); var dr = com.ExecuteReader(); while (dr.Read()) { var rec = new PrescriptionResponse(); rec.IdPrescription = (int)dr["IdPrescription"]; rec.Date = dr["Date"].ToString(); rec.DueDate = dr["DueDate"].ToString(); rec.IdPatient = (int)dr["IdPatient"]; rec.IdDoctor = (int)dr["IdDoctor"]; rec.Dose = (int)dr["Dose"]; rec.Details = dr["Details"].ToString(); result.Add(rec); } } } catch (SqlException ex) { return(null); } return(result); }