public static PatientInterventionData ConvertToInterventionData(PatientIntervention i) { PatientInterventionData data = null; if (i != null) { data = new PatientInterventionData { AssignedToId = i.AssignedToId, BarrierIds = i.BarrierIds, CategoryId = i.CategoryId, Description = i.Description, Id = i.Id, PatientGoalId = i.PatientGoalId, TemplateId = i.TemplateId, StartDate = i.StartDate, DueDate = i.DueDate, StatusId = i.StatusId, StatusDate = i.StatusDate, DeleteFlag = i.DeleteFlag, ClosedDate = i.ClosedDate, Details = i.Details }; } return(data); }
public static PatientIntervention ConvertToIntervention(PatientInterventionData i) { PatientIntervention pi = null; if (i != null) { pi = new PatientIntervention { Id = i.Id, PatientGoalId = i.PatientGoalId, CategoryId = i.CategoryId, StatusId = i.StatusId, AssignedToId = i.AssignedToId, BarrierIds = i.BarrierIds, Description = i.Description, StatusDate = i.StatusDate, StartDate = i.StartDate, DueDate = i.DueDate, ClosedDate = i.ClosedDate, CreatedById = i.CreatedById, GoalName = i.GoalName, DeleteFlag = i.DeleteFlag, TemplateId = i.TemplateId, Details = i.Details }; } return(pi); }
public static bool SavePatientGoalInterventions(PostPatientGoalRequest request) { bool result = false; try { if (request.Goal.Interventions != null && request.Goal.Interventions.Count > 0) { List <PatientInterventionData> pid = new List <PatientInterventionData>(); request.Goal.Interventions.ForEach(i => { PatientInterventionData data = ConvertToInterventionData(i); pid.Add(data); }); pid.ForEach(pi => { result = GoalsEndpointUtil.PostUpdateInterventionRequest(request, pi); }); } else if (request.Goal.Interventions.Count == 0) { // just delete all of them PatientInterventionData pbd = new PatientInterventionData { Id = "0", PatientGoalId = request.PatientGoalId }; result = GoalsEndpointUtil.PostUpdateInterventionRequest(request, pbd); } return(result); } catch (Exception ex) { throw new Exception("AD:SavePatientGoalInterventions()::" + ex.Message, ex.InnerException); } }
public GetPatientInterventionByTemplateIdResponse GetPatientInterventionByTemplateId(GetPatientInterventionByTemplateIdRequest request) { GetPatientInterventionByTemplateIdResponse result = null; try { result = new GetPatientInterventionByTemplateIdResponse(); IGoalRepository repo = Factory.GetRepository(request, RepositoryType.PatientIntervention); PatientInterventionData patientInterventionData = repo.FindByTemplateId(request.GoalId, request.TemplateId) as PatientInterventionData; //if (patientGoalData != null) //{ // //Get all barriers for a given goal // patientGoalData.BarriersData = getBarriersByPatientGoalId(request, patientGoalData.Id); // //Get all tasks for a given goal // patientGoalData.TasksData = getTasksByPatientGoalId(request, patientGoalData.Id); // //Get all interventions for a given goal // patientGoalData.InterventionsData = getInterventionsByPatientGoalId(request, patientGoalData.Id); //} result.InterventionData = patientInterventionData; result.Version = request.Version; return(result); } catch (Exception ex) { throw ex; } }
public IEnumerable <object> Find(string Id) { try { List <PatientInterventionData> interventionsDataList = null; List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(Id))); queries.Add(Query.EQ(MEPatientIntervention.DeleteFlagProperty, false)); queries.Add(Query.EQ(MEPatientIntervention.TTLDateProperty, BsonNull.Value)); IMongoQuery mQuery = Query.And(queries); using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <MEPatientIntervention> meInterventions = ctx.PatientInterventions.Collection.Find(mQuery).ToList(); if (meInterventions != null) { string goalName = string.Empty; string patientId = string.Empty; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(Id))).SetFields(MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { goalName = mePG.Name; patientId = mePG.PatientId.ToString(); } interventionsDataList = new List <PatientInterventionData>(); foreach (MEPatientIntervention b in meInterventions) { PatientInterventionData interventionData = new PatientInterventionData { Id = b.Id.ToString(), Description = b.Description, PatientGoalId = b.PatientGoalId.ToString(), CategoryId = b.CategoryId == null ? null : b.CategoryId.ToString(), AssignedToId = b.AssignedToId == null ? null : b.AssignedToId.ToString(), BarrierIds = Helper.ConvertToStringList(b.BarrierIds), StatusId = ((int)b.Status), StatusDate = b.StatusDate, StartDate = b.StartDate, DueDate = b.DueDate, ClosedDate = b.ClosedDate, CreatedById = b.RecordCreatedBy.ToString(), DeleteFlag = b.DeleteFlag, GoalName = goalName, PatientId = patientId, Details = b.Details }; interventionsDataList.Add(interventionData); } } } return(interventionsDataList); } catch (Exception) { throw; } }
/// <summary> /// Finds existing patient interventions that are in an open state. This is specifically used for spawn logic. /// </summary> /// <param name="patientGoalId">string</param> /// <param name="entityID">string</param> /// <returns>PatientInterventionData</returns> public object FindByTemplateId(string patientGoalId, string entityID) { PatientInterventionData interventionData = null; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery> { Query.EQ(MEPatientIntervention.PatientGoalIdProperty, ObjectId.Parse(patientGoalId)), Query.EQ(MEPatientIntervention.TemplateIdProperty, ObjectId.Parse(entityID)), // Open = 1, Completed = 2, Removed =3 Query.EQ(MEPatientIntervention.StatusProperty, 1), Query.EQ(MEPatientIntervention.DeleteFlagProperty, false), Query.EQ(MEPatientIntervention.TTLDateProperty, BsonNull.Value) }; var mQuery = Query.And(queries); var b = ctx.PatientInterventions.Collection.Find(mQuery).FirstOrDefault(); if (b != null) { interventionData = new PatientInterventionData { Id = b.Id.ToString(), Description = b.Description, PatientGoalId = b.PatientGoalId.ToString(), CategoryId = b.CategoryId == null ? null : b.CategoryId.ToString(), AssignedToId = b.AssignedToId == null ? null : b.AssignedToId.ToString(), BarrierIds = Helper.ConvertToStringList(b.BarrierIds), StatusId = ((int)b.Status), StatusDate = b.StatusDate, StartDate = b.StartDate, DueDate = b.DueDate, ClosedDate = b.ClosedDate, CreatedById = b.RecordCreatedBy.ToString(), DeleteFlag = b.DeleteFlag, Details = b.Details }; var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(interventionData.PatientGoalId))).SetFields(MEPatientGoal.PatientIdProperty, MEPatientGoal.NameProperty).FirstOrDefault(); if (mePG != null) { interventionData.PatientId = mePG.PatientId.ToString(); interventionData.GoalName = mePG.Name; } } } return(interventionData); } catch (Exception) { throw; } }
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 bool PostUpdateInterventionRequest(PostPatientGoalRequest request, PatientInterventionData pi) { try { bool result = false; List <string> interventionsIds = GetInterventionIdsForRequest(request.Goal.Interventions); IRestClient client = new JsonServiceClient(); string url = Common.Helper.BuildURL(string.Format("{0}/{1}/{2}/{3}/Patient/{4}/Goal/{5}/Intervention/{6}/Update", DDPatientGoalsServiceUrl, "NG", request.Version, request.ContractNumber, request.PatientId, request.Goal.Id, pi.Id), request.UserId); PutUpdateInterventionResponse response = client.Put <PutUpdateInterventionResponse>( url, new PutUpdateInterventionRequest { Intervention = pi, UserId = request.UserId, InterventionIdsList = interventionsIds } as object); if (response != null) { result = true; } return(result); } catch (WebServiceException ex) { throw new WebServiceException("AD:PostUpdateInterventionRequest()::" + ex.Message, ex.InnerException); } }
public IEnumerable <object> Search(object request, List <string> patientGoalIds) { List <PatientInterventionData> list = null; GetPatientInterventionsDataRequest dataRequest = (GetPatientInterventionsDataRequest)request; try { using (PatientGoalMongoContext ctx = new PatientGoalMongoContext(_dbName)) { List <IMongoQuery> queries = new List <IMongoQuery>(); queries.Add(Query.EQ(MEPatientIntervention.DeleteFlagProperty, false)); if (!string.IsNullOrEmpty(dataRequest.AssignedToId)) { queries.Add(Query.EQ(MEPatientIntervention.AssignedToProperty, ObjectId.Parse(dataRequest.AssignedToId))); } if (!string.IsNullOrEmpty(dataRequest.CreatedById)) { queries.Add(Query.EQ(MEPatientIntervention.RecordCreatedByProperty, ObjectId.Parse(dataRequest.CreatedById))); } if (dataRequest.StatusIds != null && dataRequest.StatusIds.Count > 0) { queries.Add(Query.In(MEPatientIntervention.StatusProperty, new BsonArray(dataRequest.StatusIds))); } if (patientGoalIds != null && patientGoalIds.Count > 0) { List <BsonValue> bsonList = Helper.ConvertToBsonValueList(patientGoalIds); queries.Add(Query.In(MEPatientIntervention.PatientGoalIdProperty, bsonList)); } IMongoQuery mQuery = Query.And(queries); List <MEPatientIntervention> meInterventions = null; meInterventions = ctx.PatientInterventions.Collection.Find(mQuery).ToList(); if (meInterventions != null && meInterventions.Count > 0) { //We get the Patient Goals for the found interventions List <MEPatientGoal> mePatientGoals = null; mQuery = Query.In(MEPatientGoal.IdProperty, meInterventions.Select(x => BsonValue.Create(x.PatientGoalId)).ToList()); mePatientGoals = ctx.PatientGoals.Collection.Find(mQuery).ToList(); list = new List <PatientInterventionData>(); foreach (MEPatientIntervention b in meInterventions) { PatientInterventionData interventionData = new PatientInterventionData { Id = b.Id.ToString(), Description = b.Description, PatientGoalId = b.PatientGoalId.ToString(), CategoryId = b.CategoryId == null ? null : b.CategoryId.ToString(), AssignedToId = b.AssignedToId == null ? null : b.AssignedToId.ToString(), BarrierIds = Helper.ConvertToStringList(b.BarrierIds), StatusId = ((int)b.Status), StatusDate = b.StatusDate, StartDate = b.StartDate, DueDate = b.DueDate, ClosedDate = b.ClosedDate, CreatedById = b.RecordCreatedBy.ToString(), DeleteFlag = b.DeleteFlag, Details = b.Details }; //var mePG = ctx.PatientGoals.Collection.Find(Query.EQ(MEPatientGoal.IdProperty, ObjectId.Parse(interventionData.PatientGoalId))).SetFields(MEPatientGoal.PatientIdProperty, MEPatientGoal.NameProperty).FirstOrDefault(); var mePG = mePatientGoals.FirstOrDefault(x => x.Id == b.PatientGoalId); if (mePG != null) { interventionData.PatientId = mePG.PatientId.ToString(); interventionData.GoalName = mePG.Name; } list.Add(interventionData); } } } return(list); } catch (Exception) { throw; } }
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; } }
public bool PostUpdateInterventionRequest(PostPatientGoalRequest request, PatientInterventionData pi) { throw new NotImplementedException(); }