public PutUpdateInterventionResponse UpdatePatientIntervention(PutUpdateInterventionRequest request) { try { PutUpdateInterventionResponse result = new PutUpdateInterventionResponse(); IGoalRepository repo = Factory.GetRepository(request, RepositoryType.PatientIntervention); if (request.InterventionIdsList != null && request.InterventionIdsList.Count > 0) { List <PatientInterventionData> pid = (List <PatientInterventionData>)repo.Find(request.PatientGoalId); List <string> dbTaskIdList = GetInterventionIds(pid); // update existing intervention entries with a delete List <string> excludes = dbTaskIdList.Except(request.InterventionIdsList).ToList <string>(); excludes.ForEach(ex => { // create delete intervention request to insert DeleteInterventionDataRequest dtr = new DeleteInterventionDataRequest { InterventionId = ex, UserId = request.UserId }; repo.Delete(dtr); }); } if (request.Intervention != null && request.Intervention.Id != "0") { bool status = (bool)repo.Update(request); if (status) { PatientInterventionData data = repo.FindByID(request.Intervention.Id) as PatientInterventionData; result.InterventionData = data; } } return(result); } catch (Exception ex) { throw ex; } }
public PutUpdateInterventionResponse Put(PutUpdateInterventionRequest request) { PutUpdateInterventionResponse response = new PutUpdateInterventionResponse(); try { if (string.IsNullOrEmpty(request.UserId)) { throw new UnauthorizedAccessException("PatientGoalDD:Put()::Unauthorized Access"); } response = Manager.UpdatePatientIntervention(request); response.Version = request.Version; } catch (Exception ex) { CommonFormatter.FormatExceptionResponse(response, base.Response, ex); string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0"; Common.Helper.LogException(int.Parse(aseProcessID), ex); } return(response); }
public object Update(object entity) { bool result = false; PutUpdateInterventionRequest ir = (PutUpdateInterventionRequest)entity; PatientInterventionData pi = ir.Intervention; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { var q = MB.Query <MEPatientIntervention> .EQ(b => b.Id, ObjectId.Parse(pi.Id)); // Set the StatusDate to Now if the status is changed. MEPatientIntervention existingPI = ctx.PatientInterventions.Collection.Find(q).SetFields(MEPatientIntervention.StatusProperty).FirstOrDefault(); if (existingPI != null) { if ((int)existingPI.Status != pi.StatusId) { pi.StatusDate = DateTime.UtcNow; } if ((pi.StatusId == (int)InterventionStatus.Removed || pi.StatusId == (int)InterventionStatus.Completed)) { if (existingPI.Status != (InterventionStatus)pi.StatusId) { pi.ClosedDate = DateTime.UtcNow; } } else { pi.ClosedDate = null; } } var uv = new List <MB.UpdateBuilder>(); uv.Add(MB.Update.Set(MEPatientIntervention.VersionProperty, ir.Version)); uv.Add(MB.Update.Set(MEPatientIntervention.LastUpdatedOnProperty, System.DateTime.UtcNow)); uv.Add(MB.Update.Set(MEPatientIntervention.UpdatedByProperty, ObjectId.Parse(this.UserId))); if (pi.TemplateId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.TemplateIdProperty, ObjectId.Parse(pi.TemplateId))); } if (pi.Description != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DescriptionProperty, pi.Description)); } if (pi.Details != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DetailProperty, pi.Details)); } if (pi.StartDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.StartDateProperty, pi.StartDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.StartDateProperty, BsonNull.Value)); } if (pi.DueDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.DueDateProperty, pi.DueDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.DueDateProperty, BsonNull.Value)); } if (pi.StatusDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.StatusDateProperty, pi.StatusDate)); } if (pi.StatusId != 0) { uv.Add(MB.Update.Set(MEPatientIntervention.StatusProperty, pi.StatusId)); } if (pi.CategoryId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.CategoryProperty, ObjectId.Parse(pi.CategoryId))); } if (pi.AssignedToId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.AssignedToProperty, ObjectId.Parse(pi.AssignedToId))); } if (pi.BarrierIds != null) { uv.Add(MB.Update.SetWrapped <List <ObjectId> >(MEPatientIntervention.BarriersProperty, DTOUtil.ConvertObjectId(pi.BarrierIds))); } if (pi.PatientGoalId != null) { uv.Add(MB.Update.Set(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(pi.PatientGoalId))); } if (pi.ClosedDate != null) { uv.Add(MB.Update.Set(MEPatientIntervention.ClosedDateProperty, pi.ClosedDate)); } else { uv.Add(MB.Update.Set(MEPatientIntervention.ClosedDateProperty, BsonNull.Value)); } uv.Add(MB.Update.Set(MEPatientIntervention.DeleteFlagProperty, pi.DeleteFlag)); DataAuditType type; if (pi.DeleteFlag) { uv.Add(MB.Update.Set(MEPatientIntervention.TTLDateProperty, System.DateTime.UtcNow.AddDays(_expireDays))); type = Common.DataAuditType.Delete; } else { uv.Add(MB.Update.Set(MEPatientIntervention.TTLDateProperty, BsonNull.Value)); type = Common.DataAuditType.Update; } IMongoUpdate update = MB.Update.Combine(uv); ctx.PatientInterventions.Collection.Update(q, update); AuditHelper.LogDataAudit(this.UserId, MongoCollectionName.PatientIntervention.ToString(), pi.Id.ToString(), type, ir.ContractNumber); result = true; } return(result as object); } catch (Exception) { throw; } }