public int UpdatePatientClinicalNotes(PatientClinicalNotes PCN)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork(new GreencardContext()))
     {
         unitOfWork.PatientClinicalNotesRepository.Update(PCN);
         result = unitOfWork.Complete();
         unitOfWork.Dispose();
         return(result);
     }
 }
 public int AddPatientClinicalNotes(PatientClinicalNotes PCN)
 {
     using (UnitOfWork unitOfWork = new UnitOfWork(new GreencardContext()))
     {
         unitOfWork.PatientClinicalNotesRepository.Add(PCN);
         unitOfWork.Complete();
         unitOfWork.Dispose();
         return(PCN.Id);
     }
 }
        public int addPatientClinicalNotes(int patientId, int patientMasterVisitId, int serviceAreaId, int notesCategoryId, string clinicalNotes, int userId)
        {
            try
            {
                int notesId = _patientNotes.checkPatientNotesifExisting(patientId, notesCategoryId);

                if (notesId > 0)
                {
                    var PCN = new PatientClinicalNotes()
                    {
                        PatientId            = patientId,
                        PatientMasterVisitId = patientMasterVisitId,
                        ServiceAreaId        = serviceAreaId,
                        ClinicalNotes        = clinicalNotes,
                        CreatedBy            = userId,
                        //VersionStamp = DateTime.Now,
                        NotesCategoryId = notesCategoryId,
                        Id = notesId
                    };
                    return(_patientNotes.UpdatePatientClinicalNotes(PCN));
                }
                else
                {
                    var PCN = new PatientClinicalNotes()
                    {
                        PatientId            = patientId,
                        PatientMasterVisitId = patientMasterVisitId,
                        ServiceAreaId        = serviceAreaId,
                        ClinicalNotes        = clinicalNotes,
                        CreatedBy            = userId,
                        //VersionStamp = DateTime.UtcNow,
                        NotesCategoryId = notesCategoryId
                    };
                    return(_patientNotes.AddPatientClinicalNotes(PCN));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <Result <MonthlyRefillResponse> > Handle(AddMonthlyRefillCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var clinicalnotes = await _prepUnitOfWork.Repository <PatientClinicalNotes>().Get(x => x.PatientId == request.PatientId && x.ServiceAreaId == request.ServiceAreaId && x.PatientMasterVisitId == request.PatientMasterVisitId && x.DeleteFlag == false).ToListAsync();

                if (request.clinicalNotes.Count > 0)
                {
                    if (clinicalnotes.Count > 0)
                    {
                        foreach (var x  in clinicalnotes)
                        {
                            if (String.IsNullOrEmpty(request.clinicalNotes[0].remark) == true)
                            {
                                x.DeleteFlag = true;
                            }
                            else
                            {
                                x.DeleteFlag    = false;
                                x.ClinicalNotes = request.clinicalNotes[0].remark;
                            }

                            _prepUnitOfWork.Repository <PatientClinicalNotes>().Update(x);
                            await _prepUnitOfWork.SaveAsync();

                            message += "Remarks is updated";
                        }
                    }
                    else
                    {
                        if (request.clinicalNotes.Count > 0)
                        {
                            if (String.IsNullOrEmpty(request.clinicalNotes[0].remark.ToString()) == false)
                            {
                                PatientClinicalNotes cl = new PatientClinicalNotes();

                                cl.ServiceAreaId        = request.ServiceAreaId;
                                cl.ClinicalNotes        = request.clinicalNotes[0].remark;
                                cl.DeleteFlag           = false;
                                cl.PatientId            = request.PatientId;
                                cl.PatientMasterVisitId = request.PatientMasterVisitId;
                                cl.CreatedBy            = request.CreatedBy;
                                cl.CreateDate           = DateTime.Now;

                                await _prepUnitOfWork.Repository <PatientClinicalNotes>().AddAsync(cl);

                                await _prepUnitOfWork.SaveAsync();

                                message += "Remarks is added successfully";
                            }
                        }
                    }
                }
                if (request.Adherence.Count > 0)
                {
                    var AdherenceOutcome = await _prepUnitOfWork.Repository <AdherenceOutcome>().Get(x => x.PatientId == request.PatientId && x.PatientMasterVisitId == request.PatientMasterVisitId && x.AdherenceType == request.Adherence[0].AdherenceType && x.DeleteFlag == false).ToListAsync();


                    if (AdherenceOutcome.Count > 0)
                    {
                        foreach (var x in AdherenceOutcome)
                        {
                            if (x.AdherenceType == request.Adherence[0].AdherenceType && x.Score == request.Adherence[0].Score)
                            {
                                x.DeleteFlag = false;
                                x.CreateBy   = request.CreatedBy;
                                x.CreateDate = DateTime.Now;

                                Id = x.Id;

                                _prepUnitOfWork.Repository <AdherenceOutcome>().Update(x);
                                await _prepUnitOfWork.SaveAsync();

                                message += "Adherence Outcome has been updated";
                            }
                            else
                            {
                                x.DeleteFlag = true;
                                _prepUnitOfWork.Repository <AdherenceOutcome>().Update(x);
                                await _prepUnitOfWork.SaveAsync();


                                AdherenceOutcome adc = new AdherenceOutcome();
                                adc.PatientId            = request.PatientId;
                                adc.PatientMasterVisitId = request.PatientMasterVisitId;
                                adc.Score         = request.Adherence[0].Score;
                                adc.AdherenceType = request.Adherence[0].AdherenceType;
                                adc.CreateBy      = request.CreatedBy;
                                adc.CreateDate    = DateTime.Now;
                                await _prepUnitOfWork.Repository <AdherenceOutcome>().AddAsync(adc);

                                await _prepUnitOfWork.SaveAsync();

                                Id       = adc.Id;
                                message += "Adherence Outcome has been Saved";
                            }
                        }
                    }
                    else
                    {
                        AdherenceOutcome adc = new AdherenceOutcome();
                        adc.PatientId            = request.PatientId;
                        adc.PatientMasterVisitId = request.PatientMasterVisitId;
                        adc.Score         = request.Adherence[0].Score;
                        adc.AdherenceType = request.Adherence[0].AdherenceType;
                        adc.CreateBy      = request.CreatedBy;
                        adc.CreateDate    = DateTime.Now;
                        await _prepUnitOfWork.Repository <AdherenceOutcome>().AddAsync(adc);

                        await _prepUnitOfWork.SaveAsync();

                        Id       = adc.Id;
                        message += "Adherence Outcome has been Saved";
                    }
                }
                else
                {
                    AdherenceOutcome adc = new AdherenceOutcome();
                    adc.PatientId            = request.PatientId;
                    adc.PatientMasterVisitId = request.PatientMasterVisitId;
                    adc.Score         = request.Adherence[0].Score;
                    adc.AdherenceType = request.Adherence[0].AdherenceType;
                    adc.CreateBy      = request.CreatedBy;
                    adc.CreateDate    = DateTime.Now;
                    await _prepUnitOfWork.Repository <AdherenceOutcome>().AddAsync(adc);

                    await _prepUnitOfWork.SaveAsync();

                    Id       = adc.Id;
                    message += "Adherence Outcome has been Saved";
                }


                if (request.screeningdetail.Count > 0)
                {
                    var patientscreeninglist = await _prepUnitOfWork.Repository <PatientScreening>().Get(x => x.PatientId == request.PatientId && x.PatientMasterVisitId == request.PatientMasterVisitId).ToListAsync();

                    if (patientscreeninglist.Count > 0)
                    {
                        foreach (var x  in patientscreeninglist)
                        {
                            x.DeleteFlag = true;
                            _prepUnitOfWork.Repository <PatientScreening>().Update(x);
                            await _prepUnitOfWork.SaveAsync();
                        }

                        foreach (var detail in request.screeningdetail) //.ForEach(async x =>
                        {
                            var find = patientscreeninglist.Find(t => t.ScreeningTypeId == detail.ScreeningTypeId && t.ScreeningValueId == detail.ScreeningValueId);
                            if (find != null)
                            {
                                find.DeleteFlag = false;
                                find.VisitDate  = request.VisitDate;
                                find.CreatedBy  = request.CreatedBy;
                                find.Comment    = detail.Comment;
                                _prepUnitOfWork.Repository <PatientScreening>().Update(find);
                                await _prepUnitOfWork.SaveAsync();
                            }
                            else
                            {
                                PatientScreening sc = new PatientScreening();
                                sc.DeleteFlag           = false;
                                sc.VisitDate            = request.VisitDate;
                                sc.ScreeningTypeId      = detail.ScreeningTypeId;
                                sc.ScreeningValueId     = detail.ScreeningValueId;
                                sc.ScreeningDone        = true;
                                sc.Active               = true;
                                sc.CreateDate           = DateTime.Now;
                                sc.CreatedBy            = request.CreatedBy;
                                sc.Comment              = detail.Comment;
                                sc.PatientId            = request.PatientId;
                                sc.PatientMasterVisitId = request.PatientMasterVisitId;
                                await _prepUnitOfWork.Repository <PatientScreening>().AddAsync(sc);

                                await _prepUnitOfWork.SaveAsync();
                            }
                        }

                        message += "Monthly Refill updated successfully";
                    }
                    else
                    {
                        foreach (var requestdetail in request.screeningdetail)
                        {
                            PatientScreening sc = new PatientScreening();
                            sc.DeleteFlag           = false;
                            sc.VisitDate            = request.VisitDate;
                            sc.ScreeningTypeId      = requestdetail.ScreeningTypeId;
                            sc.ScreeningValueId     = requestdetail.ScreeningValueId;
                            sc.ScreeningDone        = true;
                            sc.Active               = true;
                            sc.CreateDate           = DateTime.Now;
                            sc.CreatedBy            = request.CreatedBy;
                            sc.Comment              = requestdetail.Comment;
                            sc.PatientId            = request.PatientId;
                            sc.PatientMasterVisitId = request.PatientMasterVisitId;
                            await _prepUnitOfWork.Repository <PatientScreening>().AddAsync(sc);

                            await _prepUnitOfWork.SaveAsync();
                        }

                        message += "Monthly refill saved successfully";
                    }
                }

                return(Result <MonthlyRefillResponse> .Valid(new MonthlyRefillResponse()
                {
                    Message = message,
                    Id = Id
                }));
            }
            catch (Exception ex)
            {
                return(Result <MonthlyRefillResponse> .Invalid(ex.Message));
            }
        }
Example #5
0
        public async Task <Result <RiskAssessmentResponse> > Handle(RiskAssessmentVisitDetailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                if (request.PatientMasterVisitId > 0)
                {
                    int PatientMasterVisitId = request.PatientMasterVisitId;



                    if (request.riskAssessments.Count > 0)
                    {
                        foreach (var ra in request.riskAssessments)
                        {
                            var RiskAssessments = await _prepUnitOfWork.Repository <RiskAssessment>().Get(x => x.PatientMasterVisitId == PatientMasterVisitId && x.PatientId == request.PatientId &&
                                                                                                          x.Id == ra.Id).ToListAsync();


                            if (RiskAssessments != null && RiskAssessments.Count > 0)
                            {
                                foreach (var rass in RiskAssessments)
                                {
                                    rass.DeleteFlag          = ra.DeleteFlag;
                                    rass.RiskAssessmentId    = ra.RiskAssessmentid;
                                    rass.RiskAssessmentValue = ra.Value;
                                    rass.AssessmentDate      = ra.Date;
                                    rass.Comment             = ra.Comment;
                                    _prepUnitOfWork.Repository <RiskAssessment>().Update(rass);

                                    await _prepUnitOfWork.SaveAsync();
                                }
                            }
                            else
                            {
                                RiskAssessment riskass = new RiskAssessment();
                                riskass.PatientMasterVisitId = PatientMasterVisitId;
                                riskass.PatientId            = request.PatientId;
                                riskass.RiskAssessmentId     = ra.RiskAssessmentid;
                                riskass.RiskAssessmentValue  = ra.Value;
                                riskass.DeleteFlag           = ra.DeleteFlag;
                                riskass.CreateDate           = DateTime.Now;
                                riskass.Comment        = ra.Comment;
                                riskass.AssessmentDate = ra.Date;
                                await _prepUnitOfWork.Repository <RiskAssessment>().AddAsync(riskass);

                                await _prepUnitOfWork.SaveAsync();
                            }
                        }
                        _prepUnitOfWork.Save();

                        message += "The Risk Assessment Form Has Been Updated";
                    }

                    if (request.ClinicalNotes.Count > 0)
                    {
                        foreach (var clinicalnotes in request.ClinicalNotes)
                        {
                            var clinicalNotes = await _prepUnitOfWork.Repository <PatientClinicalNotes>().Get(x => x.PatientMasterVisitId == PatientMasterVisitId && x.PatientId == request.PatientId &&
                                                                                                              x.Id == clinicalnotes.Id).ToListAsync();

                            if (clinicalNotes != null && clinicalNotes.Count > 0)
                            {
                                foreach (var clinicaln in clinicalNotes)
                                {
                                    clinicaln.ClinicalNotes        = clinicalnotes.Comment;
                                    clinicaln.CreatedBy            = request.UserId;
                                    clinicaln.CreateDate           = DateTime.Now;
                                    clinicaln.DeleteFlag           = clinicalnotes.DeleteFlag;
                                    clinicaln.ServiceAreaId        = clinicaln.ServiceAreaId;
                                    clinicaln.PatientId            = request.PatientId;
                                    clinicaln.PatientMasterVisitId = PatientMasterVisitId;



                                    _prepUnitOfWork.Repository <PatientClinicalNotes>().Update(clinicaln);

                                    await _prepUnitOfWork.SaveAsync();
                                }
                            }
                            else
                            {
                                if (!String.IsNullOrEmpty(clinicalnotes.Comment))
                                {
                                    PatientClinicalNotes pcn = new PatientClinicalNotes();
                                    pcn.ClinicalNotes        = clinicalnotes.Comment;
                                    pcn.CreatedBy            = request.UserId;
                                    pcn.CreateDate           = DateTime.Now;
                                    pcn.DeleteFlag           = clinicalnotes.DeleteFlag;
                                    pcn.ServiceAreaId        = clinicalnotes.ServiceAreaId;
                                    pcn.PatientId            = request.PatientId;
                                    pcn.PatientMasterVisitId = PatientMasterVisitId;

                                    await _prepUnitOfWork.Repository <PatientClinicalNotes>().AddAsync(pcn);

                                    await _prepUnitOfWork.SaveAsync();
                                }
                            }
                            _prepUnitOfWork.Save();
                        }
                    }
                }

                return(Result <RiskAssessmentResponse> .Valid(new RiskAssessmentResponse
                {
                    PatientMasterVisitId = pmvId,
                    Message = message
                }));
            }
            catch (Exception ex)
            {
                {
                    string message = $"An error  has Occured" + ex.Message;


                    return(await Task.FromResult(Result <RiskAssessmentResponse> .Invalid(message)));
                }
            }
        }