public async Task <ResultDto <Guid, MedicationCreateStatus> > Create(MedicationEntity request, string externalId)
        {
            try
            {
                var model = _mapper.Map <MedicationEntity, MedicationCreateRequest>(request);

                try
                {
                    var _model = _mapper.Map <MedicationCreateRequest, Medication>(model);
                    _model.ExternalId    = externalId;
                    _model.EffectiveDate = DateTime.UtcNow;

                    //convert frequency string to numbers
                    var(frequncyNum, frequncyTimings) = MedicationHelper.GetMedicationFrequentyInNumber(_model.Frenquency);
                    _model.FrenquencyInDay            = frequncyNum;
                    var result = await _repository.Create(_model);

                    return(result);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(new ResultDto <Guid, MedicationCreateStatus>(MedicationCreateStatus.InternalServerError));
                }
                catch (Exception ex)
                {
                    return(new ResultDto <Guid, MedicationCreateStatus>(MedicationCreateStatus.InternalServerError));
                }
            }
            catch (Exception ex)
            {
                return(new ResultDto <Guid, MedicationCreateStatus>(MedicationCreateStatus.InternalServerError));
            }
        }
        private List <MedicationFollowupDto> GetTimings(MedicationDto medication, MedicationFollowupDto followup, IList <MedicationFollowupDto> followups = null)
        {
            var timingRecords = new List <MedicationFollowupDto>();

            var(intTimings, timingList) = MedicationHelper.GetMedicationFrequentyInNumber(medication.Frenquency);

            if (timingList == null)
            {
                timingRecords.Add(followup);
            }

            foreach (var timingItem in timingList)
            {
                var item = new MedicationFollowupDto
                {
                    MedicationId = medication.Id,
                    //  Status = (int)MedicationFollowupStatus.NOTTAKEN,
                    TakenDate = followup.TakenDate,
                    TakenTime = timingItem
                };
                var takenRecords = followups?.Where(x => x.TakenTime == timingItem).FirstOrDefault();
                if (takenRecords != null)
                {
                    timingRecords.Add(takenRecords);
                }
                else
                {
                    item.Status = (int)MedicationFollowupStatus.NOTTAKEN;
                    timingRecords.Add(item);
                }
            }
            return(timingRecords);
        }