public override Task <MedicationPlanReply> GetMedicationPlan(MedicationPlanRequest request, ServerCallContext context) { _logger.LogInformation($"Get today's medications for patient with ID " + request.PatientId); var medicationPlans = _medicationPlanService.GetMedicationPlanForPatient(request.PatientId); var today = DateTime.Today; var reply = new MedicationPlanReply(); foreach (MedicationPlanModel medPlan in medicationPlans) { if (DateTime.Compare(medPlan.StartDate, today) <= 0 && DateTime.Compare(medPlan.EndDate, today) >= 0) { foreach (MedicationPlanDetailsModel planDetails in medPlan.MedicationList) { string[] intakeIntervals = planDetails.IntakeInterval.Split(", "); foreach (string interval in intakeIntervals) { string[] intervalHours = interval.Split("-"); var details = new PlanDetails { MedicationId = planDetails.Medication.MedicationId, Name = planDetails.Medication.Name, IntakeIntervalStart = intervalHours[0], IntakeIntervalEnd = intervalHours[1] }; reply.Medication.Add(details); } } } } return(Task.FromResult(reply)); }
public IActionResult GetMedicationPlanForPatient(int patientId) { return(Ok(_medicationPlanService.GetMedicationPlanForPatient(patientId))); }