public IActionResult GetTreatmentRecordByAppointmenDatetId(int AppointmentDateId)
        {
            ResultModel resultModel        = new ResultModel();
            var         treatmentReocrd    = _treatmentRecordServices.GetTreatmentRecordsByAppointmentDateId(AppointmentDateId);
            var         treatmentRecodData = _reportServices.GetAllTreatmentRecordData(treatmentReocrd.Id);

            var treatmentRecordModel = new TreatmentRecordMasterModel();

            treatmentRecordModel.TreatmentRecordNo = treatmentReocrd.TreatmentRecordNo;
            treatmentRecordModel.Id = treatmentReocrd.Id;
            treatmentRecordModel.AppointmentDateId = treatmentReocrd.AppointmentDateId;
            //Patient Data
            var patientdata = new PatientInfoModel();

            patientdata.DiagnosisId      = treatmentRecodData.PatientVM.DiagnosisId;
            patientdata.HospitalMasterId = treatmentRecodData.PatientVM.HospitalMasterId;
            patientdata.MarkComplete     = treatmentRecodData.PatientVM.MarkComplete;
            patientdata.MR                      = (treatmentRecodData.PatientVM.MR != null)?_encryptionService.DecryptText(treatmentRecodData.PatientVM.MR):null;
            patientdata.NurseMasterId           = treatmentRecodData.PatientVM.NurseMasterId;
            patientdata.PatientInfoId           = treatmentRecodData.PatientVM.Id;
            patientdata.ProcedureId             = treatmentRecodData.PatientVM.ProcedureId;
            patientdata.PatientMasterId         = treatmentRecodData.PatientVM.PatientMasterId;
            patientdata.TreatmentRecordMasterId = treatmentRecodData.PatientVM.TreatmentRecordMasterId;
            patientdata.PatientName             = (treatmentRecodData.PatientVM.PatientName != null)?_encryptionService.DecryptText(treatmentRecodData.PatientVM.PatientName) : null;
            patientdata.ProcedureName           = treatmentRecodData.PatientVM.ProcedureName;
            patientdata.DaignosisName           = treatmentRecodData.PatientVM.DaignosisName;
            patientdata.HospitalName            = (treatmentRecodData.PatientVM.HospitalName != null)?_encryptionService.DecryptText(treatmentRecodData.PatientVM.HospitalName) : null;
            //patientdata.NurseName = treatmentRecodData.PatientVM.NurseName;
            patientdata.NurseName   = _encryptionService.DecryptText(treatmentRecodData.PatientVM.NurseFirstName) + " " + _encryptionService.DecryptText(treatmentRecodData.PatientVM.NurseLastName);
            patientdata.Date        = treatmentRecodData.PatientVM.Date;
            patientdata.Deleted     = treatmentRecodData.PatientVM.Deleted;
            patientdata.LastUpdated = treatmentRecodData.PatientVM.LastUpdated;
            treatmentRecordModel.PatientInfoData = patientdata;

            //Doctor Data
            treatmentRecordModel.DoctorData = new DoctorInfoModel
            {
                Comments               = treatmentRecodData.DoctorsInfo.Comments,
                DoctorName             = treatmentRecodData.DoctorsInfo.DoctorName,
                EducatioPreTreatmentId = treatmentRecodData.DoctorsInfo.EducatioPreTreatmentId,
                Id                      = treatmentRecodData.DoctorsInfo.Id,
                OrdersReviewed          = treatmentRecodData.DoctorsInfo.OrdersReviewed,
                OutPatient              = treatmentRecodData.DoctorsInfo.OutPatient,
                Room                    = treatmentRecodData.DoctorsInfo.Room,
                TreatmentRecordMasterId = treatmentRecodData.DoctorsInfo.TreatmentRecordMasterId,
                MarkComplete            = treatmentRecodData.DoctorsInfo.MarkComplete
            };

            //Machine Data
            treatmentRecordModel.MachineData = new MachineModel
            {
                Id                       = treatmentRecodData.MachineMaster.Id,
                KitTypeSerial            = treatmentRecodData.MachineMaster.KitTypeSerial,
                AlarmCheck               = treatmentRecodData.MachineMaster.AlarmCheck,
                CleanedFrontDoorSensors  = treatmentRecodData.MachineMaster.CleanedFrontDoorSensors,
                CleanedPressurePODSSeals = treatmentRecodData.MachineMaster.CleanedPressurePODSSeals,
                CleanedSensors           = treatmentRecodData.MachineMaster.CleanedSensors,
                CleanedTrackDoors        = treatmentRecodData.MachineMaster.CleanedTrackDoors,
                CorrectiveAction         = treatmentRecodData.MachineMaster.CorrectiveAction,
                EquipmentId              = treatmentRecodData.MachineMaster.EquipmentId,
                EquipSerial              = treatmentRecodData.MachineMaster.EquipSerial,
                ExpDate                  = treatmentRecodData.MachineMaster.ExpDate,
                KitTypeId                = (treatmentRecodData.MachineMaster.KitTypeId != null) ? treatmentRecodData.MachineMaster.KitTypeId : 0,
                MachineClean             = treatmentRecodData.MachineMaster.MachineClean,
                PMDate                   = treatmentRecodData.MachineMaster.PMDate,
                PrimeSuccess             = treatmentRecodData.MachineMaster.PrimeSuccess,
                SafetyChkDate            = treatmentRecodData.MachineMaster.SafetyChkDate,
                TreatmentRecordMasterId  = treatmentRecodData.MachineMaster.TreatmentRecordMasterId,
                MarkComplete             = treatmentRecodData.MachineMaster.MarkComplete,
                EquipmentName            = treatmentRecodData.MachineMaster.EquipmentName
            };
            //Pre treatment Check

            treatmentRecordModel.PreTreatmentCheckData = new PreTreatmentCheckModel
            {
                AlarmTest               = treatmentRecodData.PreTreatmentCheck.AlarmTest,
                BloodConsent            = treatmentRecodData.PreTreatmentCheck.BloodConsent,
                Id                      = treatmentRecodData.PreTreatmentCheck.Id,
                InformedConsent         = treatmentRecodData.PreTreatmentCheck.InformedConsent,
                TreatmentRecordMasterId = treatmentRecodData.PreTreatmentCheck.TreatmentRecordMasterId,
                UniversalPrecautions    = treatmentRecodData.PreTreatmentCheck.UniversalPrecautions,
                MarkComplete            = treatmentRecodData.PreTreatmentCheck.MarkComplete,
                MachinePrimeId          = (treatmentRecodData.PreTreatmentCheck.MachinePrimeId != null) ? treatmentRecodData.PreTreatmentCheck.MachinePrimeId : 0
            };
            //Lab Values
            treatmentRecordModel.LabValueData = new LabValuesModel
            {
                EBV                     = treatmentRecodData.LabValues.EBV,
                ECV10                   = treatmentRecodData.LabValues.ECV10,
                ECV15                   = treatmentRecodData.LabValues.ECV15,
                EPV                     = treatmentRecodData.LabValues.EPV,
                Height                  = treatmentRecodData.LabValues.Height,
                HGB                     = treatmentRecodData.LabValues.HGB,
                HTC                     = treatmentRecodData.LabValues.HTC,
                Id                      = treatmentRecodData.LabValues.Id,
                MarkComplete            = treatmentRecodData.LabValues.MarkComplete,
                TreatmentRecordMasterId = treatmentRecodData.LabValues.TreatmentRecordMasterId
            };
            //Other Lab Values
            var otherLabValues = _treatmentRecordServices.GetOtherLabValueByLabValueId(treatmentRecodData.LabValues.Id);

            if (otherLabValues.Count() != 0)
            {
                foreach (var othervalue in otherLabValues)
                {
                    var otherValuesData = new OtherLabValuesModel
                    {
                        ContentName  = othervalue.ContentName,
                        Id           = othervalue.Id,
                        ContentValue = othervalue.ContentValue,
                        LabValuesId  = othervalue.LabValuesId
                    };
                    treatmentRecordModel.LabValueData.OtherLabValues.Add(otherValuesData);
                }
            }
            //Supplies And Access
            treatmentRecordModel.SuppliesData = new SuppliesAndAccessModel
            {
                ACDLot            = treatmentRecodData.SuppliesVM.ACDLot,
                ACDLotExpDate     = treatmentRecodData.SuppliesVM.ACDLotExpDate,
                ACEInhibitors     = treatmentRecodData.SuppliesVM.ACEInhibitors,
                BloodWarmer       = treatmentRecodData.SuppliesVM.BloodWarmer,
                Comments          = treatmentRecodData.SuppliesVM.Comments,
                CreatedOn         = treatmentRecodData.SuppliesVM.CreatedOn,
                CVC               = treatmentRecodData.SuppliesVM.CVC,
                DateDC            = treatmentRecodData.SuppliesVM.DateDC,
                Deleted           = treatmentRecodData.SuppliesVM.Deleted,
                Id                = treatmentRecodData.SuppliesVM.Id,
                LastDoseDate      = treatmentRecodData.SuppliesVM.LastDoseDate,
                LastUpdated       = treatmentRecodData.SuppliesVM.LastUpdated,
                Locations         = treatmentRecodData.SuppliesVM.Locations,
                MarkComplete      = treatmentRecodData.SuppliesVM.MarkComplete,
                MedsReviewed      = treatmentRecodData.SuppliesVM.MedsReviewed,
                NSPrimeLot        = treatmentRecodData.SuppliesVM.NSPrimeLot,
                NSPrimeLotExpDate = treatmentRecodData.SuppliesVM.NSPrimeLotExpDate,
                Peripheral        = treatmentRecodData.SuppliesVM.Peripheral,
                Rate              = treatmentRecodData.SuppliesVM.Rate,
                Serial            = treatmentRecodData.SuppliesVM.Serial,
                TEMP              = treatmentRecodData.SuppliesVM.TEMP,
                TreatmentRecordId = treatmentRecodData.SuppliesVM.TreatmentRecordId,
                Type              = treatmentRecodData.SuppliesVM.Type,
                Vortex            = treatmentRecodData.SuppliesVM.Vortex
            };
            //Pre treatment Assessment
            treatmentRecordModel.PreTreatmentAssessmentData = new PreTreatmentAssessmentModel
            {
                BleendAutoTextId = treatmentRecodData.PreTreatmentAssessment.BleendAutoTextId,
                CreatedOn        = treatmentRecodData.PreTreatmentAssessment.CreatedOn,
                EdemaAutoTextId  = treatmentRecodData.PreTreatmentAssessment.EdemaAutoTextId,
                Id                      = treatmentRecodData.PreTreatmentAssessment.Id,
                IsAlert                 = treatmentRecodData.PreTreatmentAssessment.IsAlert,
                IsBleeding              = treatmentRecodData.PreTreatmentAssessment.IsBleeding,
                IsComatose              = treatmentRecodData.PreTreatmentAssessment.IsComatose,
                IsDeleted               = treatmentRecodData.PreTreatmentAssessment.IsDeleted,
                IsEasy                  = treatmentRecodData.PreTreatmentAssessment.IsEasy,
                IsEdema                 = treatmentRecodData.PreTreatmentAssessment.IsEdema,
                IsFiO2                  = treatmentRecodData.PreTreatmentAssessment.IsFiO2,
                IsLabored               = treatmentRecodData.PreTreatmentAssessment.IsLabored,
                IsLethargic             = treatmentRecodData.PreTreatmentAssessment.IsLethargic,
                IsMask                  = treatmentRecodData.PreTreatmentAssessment.IsMask,
                IsNC                    = treatmentRecodData.PreTreatmentAssessment.IsNC,
                IsNumbness              = treatmentRecodData.PreTreatmentAssessment.IsNumbness,
                IsRoomAir               = treatmentRecodData.PreTreatmentAssessment.IsRoomAir,
                IsVent                  = treatmentRecodData.PreTreatmentAssessment.IsVent,
                IsWeakness              = treatmentRecodData.PreTreatmentAssessment.IsWeakness,
                LastUpdated             = treatmentRecodData.PreTreatmentAssessment.LastUpdated,
                LocationAutoTextId      = treatmentRecodData.PreTreatmentAssessment.LungSoundsAutoTextId,
                LungSoundsAutoTextId    = treatmentRecodData.PreTreatmentAssessment.LungSoundsAutoTextId,
                MarkComplete            = treatmentRecodData.PreTreatmentAssessment.MarkComplete,
                NumbnessAutoTextId      = treatmentRecodData.PreTreatmentAssessment.NumbnessAutoTextId,
                OrientedX               = treatmentRecodData.PreTreatmentAssessment.OrientedX,
                OSat                    = treatmentRecodData.PreTreatmentAssessment.OSat,
                PainAutoTextId          = treatmentRecodData.PreTreatmentAssessment.PainAutoTextId,
                RythmAutoTextId         = treatmentRecodData.PreTreatmentAssessment.RythmAutoTextId,
                SkinAutoTextId          = treatmentRecodData.PreTreatmentAssessment.SkinAutoTextId,
                TreatmentRecordMasterId = treatmentRecodData.PreTreatmentAssessment.TreatmentRecordMasterId,
                WeaknessAutoTextId      = treatmentRecodData.PreTreatmentAssessment.WeaknessAutoTextId
            };
            //Run Values
            var runvaluesData = _treatmentRecordServices.GetRunValuesByTreatmentRecordId(treatmentReocrd.Id);

            if (runvaluesData.Count() != 0)
            {
                foreach (var runvalue in runvaluesData)
                {
                    var RunValuesModel = new RunValuesModel
                    {
                        ACFlowRate      = runvalue.ACFlowRate,
                        ACFlowVol       = runvalue.ACFlowVol,
                        BP              = runvalue.BP,
                        CollectFlowRate = runvalue.CollectFlowRate,
                        CollectFlowVol  = runvalue.CollectFlowVol,
                        CreatedOn       = runvalue.CreatedOn,
                        Deleted         = runvalue.Deleted,
                        Id              = runvalue.Id,
                        IntelFlowRate   = runvalue.IntelFlowRate,
                        IntelFlowVol    = runvalue.IntelFlowVol,
                        LastUpdated     = runvalue.LastUpdated,
                        LotNo           = runvalue.LotNo,
                        P = runvalue.P,
                        T = runvalue.T,
                        PlasmaFlowRate = runvalue.PlasmaFlowRate,
                        PlasmaFlowVol  = runvalue.PlasmaFlowVol,
                        R = runvalue.R,
                        ReplaceFluidId          = runvalue.ReplaceFluidId,
                        RunTime                 = runvalue.RunTime,
                        TreatmentRecordMasterId = runvalue.TreatmentRecordMasterId,
                        WarmerTemp              = runvalue.WarmerTemp
                    };
                    treatmentRecordModel.RunValues.runValuesList.Add(RunValuesModel);
                }
                treatmentRecordModel.RunValues.MarkComplete = runvaluesData[0].MarkComplete;
            }
            //Final Values

            treatmentRecordModel.FinalValuesData = new FinalValuesAndAccessPostAssessmentModel
            {
                AC = treatmentRecodData.FinalValuesVM.AC,
                BP = treatmentRecodData.FinalValuesVM.BP,
                ChlorhexidineCapApplied = treatmentRecodData.FinalValuesVM.ChlorhexidineCapApplied,
                Collet            = treatmentRecodData.FinalValuesVM.Collet,
                Comments          = treatmentRecodData.FinalValuesVM.Comments,
                CreatedOn         = treatmentRecodData.FinalValuesVM.CreatedOn,
                Deleted           = treatmentRecodData.FinalValuesVM.Deleted,
                FluidBalance      = treatmentRecodData.FinalValuesVM.FluidBalance,
                Heparin           = treatmentRecodData.FinalValuesVM.Heparin,
                Id                = treatmentRecodData.FinalValuesVM.Id,
                Inlet             = treatmentRecodData.FinalValuesVM.Inlet,
                Intact            = treatmentRecodData.FinalValuesVM.Intact,
                LastUpdated       = treatmentRecodData.FinalValuesVM.LastUpdated,
                MarkComplete      = treatmentRecodData.FinalValuesVM.MarkComplete,
                NewDressing       = treatmentRecodData.FinalValuesVM.NewDressing,
                P                 = treatmentRecodData.FinalValuesVM.P,
                Plasma            = treatmentRecodData.FinalValuesVM.Plasma,
                R                 = treatmentRecodData.FinalValuesVM.R,
                Reinforced        = treatmentRecodData.FinalValuesVM.Reinforced,
                Saline            = treatmentRecodData.FinalValuesVM.Saline,
                T                 = treatmentRecodData.FinalValuesVM.T,
                Time              = treatmentRecodData.FinalValuesVM.Time,
                TreatmentRecordId = treatmentRecodData.FinalValuesVM.TreatmentRecordId
            };
            //post treatment
            treatmentRecordModel.PostTreatmentData = new PostTreatmentModel {
                Id = treatmentRecodData.PostTreatmentVM.Id,
                IsBiohazardWasteDisposed         = treatmentRecodData.PostTreatmentVM.IsBiohazardWasteDisposed,
                IsEquipmentCleanedAndDisinfected = treatmentRecodData.PostTreatmentVM.IsEquipmentCleanedAndDisinfected,
                TreatmentRecordId      = treatmentRecodData.PostTreatmentVM.TreatmentRecordId,
                IsPostCVCCarePerPolicy = treatmentRecodData.PostTreatmentVM.IsPostCVCCarePerPolicy,
                IsRinseBackComplete    = treatmentRecodData.PostTreatmentVM.IsRinseBackComplete,
                IsSideRailsUp          = treatmentRecodData.PostTreatmentVM.IsSideRailsUp,
                MarkComplete           = treatmentRecodData.PostTreatmentVM.MarkComplete
            };

            var Medication = _treatmentRecordServices.GetMedicationByPostTreatmentId(treatmentRecordModel.PostTreatmentData.Id);

            if (Medication.Count() != 0)
            {
                foreach (var medicationData in Medication)
                {
                    var medicationdata = new MedicationModel
                    {
                        Comments        = medicationData.Comments,
                        Dosage          = medicationData.Dosage,
                        Id              = medicationData.Id,
                        Name            = medicationData.Name,
                        PostTreatmentId = medicationData.PostTreatmentId,
                        Route           = medicationData.Route
                    };
                }
            }
            //Note and Report
            treatmentRecordModel.NoteAndReportData = new NoteAndReportModel
            {
                CreatedOn = treatmentRecodData.NoteAndReportVM.CreatedOn,
                Deleted   = treatmentRecodData.NoteAndReportVM.Deleted,
                Id        = treatmentRecodData.NoteAndReportVM.Id,
                IsTreatmentCompletedWOIncident = treatmentRecodData.NoteAndReportVM.IsTreatmentCompletedWOIncident,
                LastUpdated             = treatmentRecodData.NoteAndReportVM.LastUpdated,
                MarkComplete            = treatmentRecodData.NoteAndReportVM.MarkComplete,
                Note                    = treatmentRecodData.NoteAndReportVM.Note,
                ReportGivenTo           = treatmentRecodData.NoteAndReportVM.ReportGivenTo,
                TreatmentRecordMasterId = treatmentRecodData.NoteAndReportVM.TreatmentRecordMasterId
            };

            resultModel.Message  = ValidationMessages.Success;
            resultModel.Status   = 1;
            resultModel.Response = treatmentRecordModel;
            return(Ok(resultModel));
        }
        public IActionResult Create(RunValuesListModel modelList)
        {
            ResultModel resultModel = new ResultModel();


            if (modelList.runValuesList.Count() != 0)
            {
                var runvalueListmodel = new List <RunValuesModel>();
                foreach (var data in modelList.runValuesList)
                {
                    try
                    {
                        var runValuesDAta = new RunValues();

                        if (data.Id == 0)
                        {
                            runValuesDAta.ACFlowRate = data.ACFlowRate;

                            runValuesDAta.ACFlowVol = data.ACFlowVol;

                            runValuesDAta.BP = data.BP;


                            runValuesDAta.CollectFlowRate = data.CollectFlowRate;
                            runValuesDAta.CollectFlowVol  = data.CollectFlowVol;
                            runValuesDAta.IntelFlowRate   = data.IntelFlowRate;
                            runValuesDAta.IntelFlowVol    = data.IntelFlowVol;
                            runValuesDAta.MarkComplete    = modelList.MarkComplete;
                            runValuesDAta.LotNo           = data.LotNo;

                            runValuesDAta.TreatmentRecordMasterId = data.TreatmentRecordMasterId;
                            runValuesDAta.P = data.P;

                            runValuesDAta.PlasmaFlowRate = data.PlasmaFlowRate;

                            runValuesDAta.PlasmaFlowVol  = data.PlasmaFlowVol;
                            runValuesDAta.R              = data.R;
                            runValuesDAta.ReplaceFluidId = data.ReplaceFluidId;
                            runValuesDAta.RunTime        = data.RunTime;
                            runValuesDAta.T              = data.T;
                            runValuesDAta.WarmerTemp     = data.WarmerTemp;
                            runValuesDAta.CreatedOn      = DateTime.UtcNow;
                            runValuesDAta.LastUpdated    = DateTime.UtcNow;
                            runValuesDAta.Deleted        = false;

                            _treatmentRecordServices.InsertRunValues(runValuesDAta);
                            //12/10/19 aakansha
                            //model response
                            var responceRunvalues = new RunValuesModel();
                            responceRunvalues.Id = runValuesDAta.Id;
                            responceRunvalues.TreatmentRecordMasterId = runValuesDAta.TreatmentRecordMasterId;
                            responceRunvalues.ReplaceFluidId          = runValuesDAta.ReplaceFluidId;
                            runvalueListmodel.Add(responceRunvalues);
                        }
                        else
                        {
                            runValuesDAta = _treatmentRecordServices.GetRunValuesById(data.Id);

                            runValuesDAta.ACFlowRate = data.ACFlowRate;

                            runValuesDAta.ACFlowVol = data.ACFlowVol;

                            runValuesDAta.BP           = data.BP;
                            runValuesDAta.MarkComplete = modelList.MarkComplete;

                            runValuesDAta.CollectFlowRate = data.CollectFlowRate;
                            runValuesDAta.CollectFlowVol  = data.CollectFlowVol;
                            runValuesDAta.IntelFlowRate   = data.IntelFlowRate;
                            runValuesDAta.IntelFlowVol    = data.IntelFlowVol;

                            runValuesDAta.LotNo = data.LotNo;

                            runValuesDAta.TreatmentRecordMasterId = data.TreatmentRecordMasterId;
                            runValuesDAta.P = data.P;

                            runValuesDAta.PlasmaFlowRate = data.PlasmaFlowRate;

                            runValuesDAta.PlasmaFlowVol  = data.PlasmaFlowVol;
                            runValuesDAta.R              = data.R;
                            runValuesDAta.ReplaceFluidId = data.ReplaceFluidId;
                            runValuesDAta.RunTime        = data.RunTime;
                            runValuesDAta.T              = data.T;
                            runValuesDAta.WarmerTemp     = data.WarmerTemp;
                            runValuesDAta.CreatedOn      = DateTime.UtcNow;
                            runValuesDAta.LastUpdated    = DateTime.UtcNow;
                            runValuesDAta.Deleted        = false;

                            _treatmentRecordServices.UpdateRunValues(runValuesDAta);
                            //12/10/19 aakansha
                            //model response
                            var responceRunvalues = new RunValuesModel();
                            responceRunvalues.Id = runValuesDAta.Id;
                            responceRunvalues.TreatmentRecordMasterId = runValuesDAta.TreatmentRecordMasterId;
                            responceRunvalues.ReplaceFluidId          = runValuesDAta.ReplaceFluidId;
                            runvalueListmodel.Add(responceRunvalues);
                        }
                    }
                    catch (Exception e)
                    {
                        resultModel.Message  = ValidationMessages.Failure;
                        resultModel.Status   = 0;
                        resultModel.Response = null;
                        return(Ok(resultModel));
                    }
                }
                //Bhawana(09/10/2019)
                //Change treatment Record Status
                _reportService.UpdateTreatmentStatusID((int)modelList.runValuesList[0].TreatmentRecordMasterId);
                modelList.runValuesList = runvalueListmodel;


                resultModel.Message  = ValidationMessages.Success;
                resultModel.Status   = 1;
                resultModel.Response = modelList;
                return(Ok(resultModel));
            }
            else
            {
                resultModel.Message  = ValidationMessages.Failure;
                resultModel.Status   = 0;
                resultModel.Response = null;
                return(Ok(resultModel));
            }
        }