Example #1
0
        public CreateTreatmentResult Create(ApiTreatmentModel apiTreatment)
        {
            int userId  = int.Parse(Thread.CurrentPrincipal.Identity.Name);
            var patient = _dbContext.PatientProfiles.FirstOrDefault(x => x.PatientId == userId);

            if (patient != null)
            {
                var treatment = new TreatmentModel()
                {
                    Title        = apiTreatment.Title,
                    BodyField    = apiTreatment.BodyField,
                    CreationDate = DateTime.Now,
                    DateOfAppear = apiTreatment.DateOfAppear,
                    Patient      = patient
                };
                _dbContext.Treatments.Add(treatment);
                _dbContext.SaveChanges();
                return(new CreateTreatmentResult()
                {
                    Success = true, TreatmentId = treatment.TreatmentId
                });
            }
            return(new CreateTreatmentResult()
            {
                Success = true,
                Message = "Wrong parent treatment id"
            });
        }
        public bool CreateTreatment(TreatmentModel model)
        {
            Treatment newTreatment = new Treatment
            {
                Comments           = model.Comments,
                Title              = model.Title,
                ReceivedDateTime   = model.ReceivedDateTime,
                Doctor             = model.Doctor,
                Amount             = model.Amount,
                ExpirationDateTime = model.ExpirationDateTime,
                Created            = model.Created,
                Modified           = model.Modified,
                Deleted            = model.Deleted
            };

            using (ISession session = NHibernateSession.OpenSession())
            {
                Dog foundDog = session.Query <Dog>().FirstOrDefault(u => u.DogId == model.Dog.DogId.Value);
                if (foundDog == null)
                {
                    return(false);
                }
                newTreatment.Dog = foundDog;
                using (ITransaction transaction = session.BeginTransaction()) //  Begin a transaction
                {
                    session.Save(newTreatment);                               //  Save the user in session
                    transaction.Commit();                                     //  Commit the changes to the database
                }
            }
            return(true);
        }
Example #3
0
        }//end of search

        public static async Task <bool> AddTreatment(TreatmentModel treatment)
        {
            String SQL = "INSERT INTO Treatment(AdmissionID, Treatment, Medicines, Reports)" +
                         "VALUES('" + treatment.AdmissionID + "','" + treatment.PtntTreatment + "','" + treatment.Medicines + "','" + treatment.Reports + "')";

            using (SqlConnection dbConn = new SqlConnection(connectionString))
            {
                try
                {
                    dbConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = SQL;
                    cmd.Connection  = dbConn;
                    await cmd.ExecuteNonQueryAsync();

                    dbConn.Close();

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(false);
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }//end of add
 public void CopyData(MouseEventArgs e, TreatmentModel model)
 {
     ShowEditData      = true;
     Model             = model;
     Model.TreatmentId = new TreatmentId();
     StateHasChanged();
 }
Example #5
0
        private static void SetTreatmentData()
        {
            try
            {
                TreatmentModel model1 = new TreatmentModel();
                model1.CreateTime    = "2018-03-01 16:48:25";
                model1.DoctorName    = "王华";
                model1.ProjectDesc   = "阴性";
                model1.ProjectName   = "肺衣";
                model1.ProjectResult = "21.79";
                _TreatmentSource.Add(model1);

                TreatmentModel model2 = new TreatmentModel();
                model2.CreateTime    = "2018-03-01 16:48:25";
                model2.DoctorName    = "王华";
                model2.ProjectDesc   = "阴性";
                model2.ProjectName   = "肺衣";
                model2.ProjectResult = "21.79";
                _TreatmentSource.Add(model2);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #6
0
        public Task <Guid> Handle(UpdateTreatmentCommand request, CancellationToken cancellationToken)
        {
            var currentTreatment = _databaseContext.Treatment.FirstOrDefault(x => x.Id == request.Id);

            var treatments = _mapper.Map <List <TreatmentModel> >(_databaseContext.Treatment.ToList());

            Fastenshtein.Levenshtein lev = new Fastenshtein.Levenshtein(request.Description);
            foreach (var treatmentItem in treatments)
            {
                treatmentItem.ClosedDescriptionProbability = lev.DistanceFrom(treatmentItem.Description);
            }

            var treatment = treatments.Where(x => x.ClosedDescriptionProbability <= 7).OrderByDescending(x => x.ClosedDescriptionProbability).FirstOrDefault();

            if (treatment == null)
            {
                treatment = new TreatmentModel()
                {
                    Type = request.Type, Description = request.Description, Name = request.Name,
                };
                _databaseContext.Treatment.Add(treatment);
                _databaseContext.SaveChanges();
            }

            //else
            //    _databaseContext.Relationship.Add(new Relationship()
            //    {
            //        FromType = ObjectType.Treatment,
            //        FromId = treatment.Id,
            //        ToType = ObjectType.TreatmentPayload,
            //        ToId = treatmentPayload.Id
            //    });
            _databaseContext.SaveChanges();
            return(Task.FromResult(treatment.Id));
        }
Example #7
0
        }//end of search

        public static async Task <bool> UpdateTreatment(TreatmentModel treatment)
        {
            String SQL = "UPDATE Treatment SET Treatment = '" + treatment.PtntTreatment + "', " +
                         "Medicines = '" + treatment.Medicines + "',Reports = '" + treatment.Reports + "'   " +
                         "WHERE ID = '" + treatment.ID + "'";

            using (SqlConnection dbConn = new SqlConnection(connectionString))
            {
                try
                {
                    dbConn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = SQL;
                    cmd.Connection  = dbConn;
                    await cmd.ExecuteNonQueryAsync();

                    dbConn.Close();

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    return(false);
                }
                finally
                {
                    dbConn.Close();
                }
            }
        }//end of update
 public void AddData(MouseEventArgs e)
 {
     ShowEditData = true;
     Model        = new TreatmentModel
     {
         Created = DateTime.UtcNow
     };
     StateHasChanged();
 }
Example #9
0
 public TreatmentsEntity(int simulationId, TreatmentModel treatmentModel)
 {
     SIMULATIONID = simulationId;
     TREATMENT    = treatmentModel.Name;
     BUDGET       = treatmentModel.Budgets.Count > 0
         ? string.Join(",", treatmentModel.Budgets)
         : null;
     BEFOREANY  = treatmentModel.Feasibility.YearsBeforeAny;
     BEFORESAME = treatmentModel.Feasibility.YearsBeforeSame;
 }
Example #10
0
        public async Task <IActionResult> CreateAsync(TreatmentModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("/Views/Treatment/AddTreatment.cshtml", model));
            }

            await _treatmentService.AddTreatmentToDiagnose(model);

            return(RedirectToAction("", "DoctorDashboard"));
        }
 public TreatmentsBase()
 {
     Model = new TreatmentModel
     {
         Created = DateTime.UtcNow
     };
     ShowEditData    = false;
     TreatmentModels = new List <TreatmentModel>();
     IncidentTypes   = Enum.GetValues(typeof(IncidentType)).Cast <IncidentType>().Select(x => new IncidentTypeModel()
     {
         Name = x.ToString(), Value = (int)x
     });
 }
Example #12
0
        public TreatmentModel GetTreatmentById(TreatmentId TreatmentId)
        {
            TreatmentModel model = new TreatmentModel();

            using (ISession session = NHibernateSession.OpenSession())  // Open a session to conect to the database
            {
                var dbItem = session.Query <Treatment>().FirstOrDefault(c => c.TreatmentId == TreatmentId.Value);
                if (dbItem != null)
                {
                    model = dbItem.ToTreatmentModel();
                }
            }
            return(model);
        }
        public async Task <TreatmentResponse> SaveAsyncTreatment(TreatmentModel treatment)
        {
            try
            {
                await _treatmentRepository.AddAsyncTreatment(treatment);

                await _unitOfWork.CompleteAsync();

                return(new TreatmentResponse(treatment));
            }
            catch (Exception ex)
            {
                return(new TreatmentResponse($"AnError when saving the Treatment: {ex.Message}"));
            }
        }
Example #14
0
 /// <summary>
 /// The delete treatment.
 /// </summary>
 /// <param name="treatment">
 /// The treatment.
 /// </param>
 private void DeleteTreatment(TreatmentModel treatment)
 {
     using (var api = new BusinessContext())
     {
         try
         {
             var tmpTreatment = api.GetAllTreatmentsById(treatment.Id);
             api.DeleteTreatment(tmpTreatment);
         }
         catch (Exception)
         {
         }
         this.TreatmentTypes.Remove(treatment);
     }
 }
        public async Task <IHttpActionResult> Put(int treatmentId, TreatmentModel treatmentModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Treatment Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    var treatment = await context.Beekeepers
                                    .Where(x => x.ApplicationUserId == _applicationUserId)
                                    .Include(x => x.Apiaries)
                                    .SelectMany(x => x.Apiaries)
                                    .Include(x => x.Hives)
                                    .SelectMany(x => x.Hives)
                                    .Include(x => x.Treatments)
                                    .SelectMany(x => x.Treatments)
                                    .Where(x => x.Id == treatmentId)
                                    .FirstOrDefaultAsync();

                    if (treatment != null)
                    {
                        treatment.Name     = treatmentModel.Name;
                        treatment.Date     = treatmentModel.Date;
                        treatment.Product  = treatmentModel.Product;
                        treatment.Quantity = treatmentModel.Quantity;
                        treatment.Unit     = treatmentModel.Unit;
                        treatment.Note     = treatmentModel.Note;

                        // Save
                        context.SaveChanges();

                        // Return
                        return(StatusCode(HttpStatusCode.NoContent));
                    }

                    // Return
                    return(BadRequest("Treatment could not be found"));
                }
            }
            catch (Exception ex)
            {
                // Return
                return(BadRequest(ex.Message));
            }
        }
Example #16
0
 private bool ValidateSetTreatmentValues(TreatmentModel treatmentModel, ref string errorMessage)
 {
     if (treatmentModel == null)
     {
         errorMessage = "Missing treament model";
         return(false);
     }
     if (Request == null || Request.Headers.IsNullOrEmpty() ||
         !Request.Headers.TryGetValue(PumpSessionHeaderName, out var sessionIdHeader) ||
         !(treatmentModel.SessionId = sessionIdHeader.ToString()).HasValue())
     {
         errorMessage = "Missing session Id";
         return(false);
     }
     return(true);
 }
Example #17
0
        public async Task <IHttpActionResult> AddTreatment(TreatmentModel treatment)
        {
            if (treatment == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (await TreatmentService.AddTreatment(treatment))
            {
                return(Ok("Treatment Saved Successfully!"));
            }
            else
            {
                return(BadRequest("Failed to Save Treatment!"));
            }
        }
Example #18
0
        public async Task <IHttpActionResult> UpdateTreatment(TreatmentModel treatment)
        {
            if (treatment == null)
            {
                return(BadRequest("Please provide valid inputs!"));
            }

            if (await TreatmentService.UpdateTreatment(treatment))
            {
                return(Ok("Treatment Udpated Successfully!"));
            }
            else
            {
                return(BadRequest("Failed to Update Ward!"));
            }
        }//end of update
Example #19
0
        public async Task <IActionResult> SetTreatment([FromBody] TreatmentModel treatmentModel)
        {
            var errorMessage = "";

            if (!ValidateSetTreatmentValues(treatmentModel, ref errorMessage))
            {
                return(BadRequest(new
                {
                    message = errorMessage,
                    data = treatmentModel
                }));
            }
            var cmdRequest = ToCommandRequest("treatment", treatmentModel.SessionId, treatmentModel);

            var srvRes = await _commandService.SendCommand(cmdRequest);

            return(srvRes.ToActionResult());
        }
Example #20
0
        public async Task <IActionResult> AddTreatment(string patientId)
        {
            long diagnoseId = -1;

            var diagnose = await _diagnoseService.GetActiveDiagnose(patientId);

            if (diagnose != null)
            {
                diagnoseId = diagnose.Id;
            }

            var model = new TreatmentModel()
            {
                IsDiagnoseExisting = diagnose != null, PatientId = patientId, DiagnoseId = diagnoseId
            };

            return(View("/Views/Treatment/AddTreatment.cshtml", model));
        }
Example #21
0
        /// <summary>
        /// The save treatment.
        /// </summary>
        /// <param name="treatment">
        /// The treatment.
        /// </param>
        private void SaveTreatment(TreatmentModel treatment)
        {
            using (var api = new BusinessContext())
            {
                try
                {
                    var tmpTreatment = api.GetAllTreatmentsById(treatment.Id);
                    tmpTreatment.TreatmentName = treatment.TreatmentName;

                    api.EditTreatment(tmpTreatment);
                }
                catch (Exception)
                {
                }
                this.Success = "Treatment " + this.TreatmentName + " Saved!";
                int index = this.treatmentTypes.IndexOf(treatment);
                this.treatmentTypes.ReplaceItem(index, treatment);
            }
        }
Example #22
0
        /// <summary>
        /// The add treatment.
        /// </summary>
        /// <param name="treatmentName">
        /// The treatment name.
        /// </param>
        private void AddTreatment(string treatmentName)
        {
            using (var api = new BusinessContext())
            {
                var treatment = new TreatmentModel {
                    TreatmentName = treatmentName
                };
                try
                {
                    api.AddNewTreatment(treatment);
                }
                catch (Exception)
                {
                    Console.WriteLine("api.addNew failed");
                }

                this.Success = "Treatment " + this.TreatmentName + " added";
                this.TreatmentTypes.Add(treatment);
            }
        }
        public async Task <TreatmentResponse> UpdateAsyncTreatment(int id, TreatmentModel treatment)
        {
            var existingTreatment = await _treatmentRepository.FindByIdAsync(id);

            if (existingTreatment == null)
            {
                return(new TreatmentResponse("Treatment not found"));
            }

            try
            {
                _treatmentRepository.UpdateAsyncTreatment(existingTreatment);
                await _unitOfWork.CompleteAsync();

                return(new TreatmentResponse(existingTreatment));
            }
            catch (Exception ex)
            {
                return(new TreatmentResponse($"An error occured when updating Treatment: {ex.Message}"));
            }
        }
Example #24
0
        public IActionResult Index(long diagnoseId, long treatmentId, string patientId, string patientName)
        {
            TreatmentModel treatmentModel;

            if (treatmentId == -1)
            {
                treatmentModel = new TreatmentModel()
                {
                    IsExisting         = false,
                    IsDiagnoseExisting = true,
                    DiagnoseId         = diagnoseId,
                    PatientId          = patientId,
                    PatientName        = patientName
                };
            }
            else
            {
                Treatment treatment = _treatmentService.GetByIdAsync(treatmentId).Result;

                treatmentModel = new TreatmentModel()
                {
                    Id                 = treatmentId,
                    IsExisting         = true,
                    IsDiagnoseExisting = true,
                    DiagnoseId         = diagnoseId,
                    PatientId          = patientId,
                    PatientName        = patientName,
                    End                = treatment.End,
                    Chemeotherapy      = treatment.Chemeotherapy,
                    EndocrineTreatment = treatment.EndocrineTreatment,
                    Radiation          = treatment.Radiation,
                    Surgery            = treatment.Surgery
                };
            }

            return(View("/Views/Treatment/TreatmentView.cshtml", treatmentModel));
        }
        public async Task <IHttpActionResult> Post(int apiaryId, int hiveId, TreatmentModel treatmentModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Treatment Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    if (await _ensurer.EnsureHiveBelongsToApiary(context, apiaryId, hiveId, _applicationUserId))
                    {
                        context.Treatments.Add(new Treatment
                        {
                            Name     = treatmentModel.Name,
                            Date     = treatmentModel.Date,
                            Product  = treatmentModel.Product,
                            Quantity = treatmentModel.Quantity,
                            Unit     = treatmentModel.Unit,
                            Note     = treatmentModel.Note,
                            HiveId   = hiveId
                        });

                        // Save
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // Return
            return(Ok(treatmentModel));
        }
        public async Task AddTreatmentToDiagnose(TreatmentModel model)
        {
            Diagnose diagnose = await _diagnoseContext.Diagnoses
                                .Where(d => d.Id == model.DiagnoseId)
                                .Include(d => d.Treatment)
                                .SingleOrDefaultAsync();

            var newTreatment = new Treatment()
            {
                Beginning          = DateTime.Now,
                End                = model.End.Value,
                Chemeotherapy      = model.Chemeotherapy,
                EndocrineTreatment = model.EndocrineTreatment,
                Radiation          = model.Radiation,
                Surgery            = model.Surgery,
                DiagnoseId         = diagnose.Id
            };

            await _diagnoseContext.Treatments.AddAsync(newTreatment);

            diagnose.Treatment = newTreatment;

            await _diagnoseContext.SaveChangesAsync();
        }
Example #27
0
 public bool UpdateTreatment(TreatmentModel model)
 {
     using (ISession session = NHibernateSession.OpenSession())
     {
         Treatment foundTreatment = session.Query <Treatment>().FirstOrDefault(c => c.TreatmentId == model.TreatmentId.Value);
         if (foundTreatment == null)
         {
             return(false);
         }
         foundTreatment.Modified           = DateTime.UtcNow;
         foundTreatment.Comments           = model.Comments;
         foundTreatment.Title              = model.Title;
         foundTreatment.ReceivedDateTime   = model.ReceivedDateTime;
         foundTreatment.Doctor             = model.Doctor;
         foundTreatment.Amount             = model.Amount;
         foundTreatment.ExpirationDateTime = model.ExpirationDateTime;
         using (ITransaction transaction = session.BeginTransaction()) //  Begin a transaction
         {
             session.Update(foundTreatment);                           //  Save the user in session
             transaction.Commit();                                     //  Commit the changes to the database
         }
     }
     return(true);
 }
Example #28
0
        public async Task CommandController_SetTreatment_NotAcceptable()
        {
            var tm     = new TreatmentModel();
            var srvRes = new ServiceResponse <CommandResponse>
            {
                Message = "some-err",
                Result  = ServiceResponseResult.NotAcceptable
            };

            var cmdSrv = new Mock <ICommandService>();

            cmdSrv.Setup(c => c.SendCommand(It.IsAny <CommandRequest>())).ReturnsAsync(srvRes);

            var controller = new CommandController(cmdSrv.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            controller.ControllerContext.HttpContext.Request.Headers[CommandController.PumpSessionHeaderName] = "some-session-id";
            var res = await controller.SetTreatment(tm);

            var or = res.ShouldBeOfType <ObjectResult>();

            or.StatusCode.ShouldBe((int)HttpStatusCode.NotAcceptable);
        }
 /// <summary>
 /// The edit treatments.
 /// </summary>
 /// <param name="treatments">
 /// The treatments.
 /// </param>
 public void EditTreatment(TreatmentModel treatments)
 {
     Check.Require(treatments.TreatmentName);
     this.context.Entry(treatments).State = EntityState.Modified;
     this.context.SaveChanges();
 }
 public void EditData(MouseEventArgs e, TreatmentModel model)
 {
     ShowEditData = true;
     Model        = model;
     StateHasChanged();
 }