示例#1
0
        public string InsertPatientMedFrequency(PostPatientMedFrequencyRequest request)
        {
            string id = null;

            try
            {
                // Before inserting a new one, check if the Frequency lookup already contains that name.
                if (request.PatientMedFrequency != null && !string.IsNullOrEmpty(request.PatientMedFrequency.Name))
                {
                    NGManager         ngManager     = new NGManager();
                    GetLookUpsRequest lookUpRequest = new GetLookUpsRequest
                    {
                        ContractNumber = request.ContractNumber,
                        TypeName       = LookUpType.Frequency.ToString(),
                        UserId         = request.UserId,
                        Version        = request.Version,
                    };
                    List <IdNamePair> lookups = ngManager.GetLookUps(lookUpRequest);
                    var freq = lookups.Find(x => x.Name.ToLower() == request.PatientMedFrequency.Name.ToLower());
                    if (freq != null)
                    {
                        id = freq.Id;
                    }
                }
                if (string.IsNullOrEmpty(id))
                {
                    id = EndpointUtil.InsertPatientMedFrequency(request);
                }
                return(id);
            }
            catch (Exception ex) { throw ex; }
        }
示例#2
0
 public int GetPatientMedSuppsCount(GetPatientMedSuppsCountRequest request)
 {
     try
     {
         return(EndpointUtil.GetPatientMedSuppsCount(request));
     }
     catch (Exception ex) { throw ex; }
 }
示例#3
0
 public void DeletePatientAllergy(DeletePatientAllergyRequest request)
 {
     try
     {
         EndpointUtil.DeletePatientAllergy(request);
     }
     catch (Exception ex) { throw ex; }
 }
示例#4
0
 public void DeletePatientMedSupp(DeletePatientMedSuppRequest request)
 {
     try
     {
         EndpointUtil.DeletePatientMedSupp(request);
     }
     catch (Exception ex) { throw ex; }
 }
示例#5
0
 public void DeleteMedicationMaps(DeleteMedicationMapsRequest request)
 {
     try
     {
         // Call MedicationMap endpoint to delete medicationmaps.
         EndpointUtil.DeleteMedicationMaps(request);
         // Call the Search endpoint to delete Lucene indexes.
         SearchManager.DeleteMedDocuments(request);
     }
     catch (Exception ex) { throw ex; }
 }
示例#6
0
        public List <Contact> GetCareManagers(GetAllCareManagersRequest request)
        {
            List <Contact> contacts = null;

            try
            {
                contacts = EndpointUtil.GetCareManagers(request);
            }
            catch (Exception ex) { throw ex; }
            return(contacts);
        }
示例#7
0
 private string GetQualifiedUrl(string url)
 {
     if (!string.IsNullOrEmpty(url) && !url.StartsWith("http://") && !url.StartsWith("https://") && url.IndexOf("/") > -1)
     {
         var indexOfSlash         = url.IndexOf("/");
         var serviceName          = url.Substring(0, indexOfSlash);
         var qualifiedServiceName = _apiEndPoints.GetServiceProtocol() + EndpointUtil.GetQualifiedServiceName(serviceName);
         return(qualifiedServiceName + url.Substring(indexOfSlash));
     }
     return(url);
 }
示例#8
0
 public DTO.MedicationMap InitializeMedicationMap(PostInitializeMedicationMapRequest request)
 {
     DTO.MedicationMap med = null;
     try
     {
         MedicationMapData data = EndpointUtil.InitializeMedicationMap(request);
         if (data != null)
         {
             med = Mapper.Map <DTO.MedicationMap>(data);
         }
         return(med);
     }
     catch (Exception ex) { throw ex; }
 }
示例#9
0
 public DTO.Allergy InitializeAllergy(PostInitializeAllergyRequest request)
 {
     DTO.Allergy allergy = null;
     try
     {
         AllergyData data = EndpointUtil.InitializeAllergy(request);
         if (data != null)
         {
             allergy = Mapper.Map <DTO.Allergy>(data);
         }
         return(allergy);
     }
     catch (Exception ex) { throw ex; }
 }
示例#10
0
 public List <DTO.Allergy> GetAllergies(GetAllergiesRequest request)
 {
     try
     {
         List <DTO.Allergy> result = new List <DTO.Allergy>();
         var algy = EndpointUtil.GetAllergies(request);
         algy.ForEach(a => result.Add(Mapper.Map <DTO.Allergy>(a)));
         IndexResultSet(result);
         return(result);
     }
     catch (WebServiceException ex)
     {
         throw new WebServiceException("AD:GetAllergies()::" + ex.Message, ex.InnerException);
     }
 }
示例#11
0
        public PatientAllergy InitializePatientAllergy(PostInitializePatientAllergyRequest request)
        {
            PatientAllergy patientAllergy = null;

            try
            {
                PatientAllergyData data = EndpointUtil.InitializePatientAllergy(request);
                if (data != null)
                {
                    patientAllergy = Mapper.Map <PatientAllergy>(data);
                }
                return(patientAllergy);
            }
            catch (Exception ex) { throw ex; }
        }
示例#12
0
        public List <PatientMedSupp> GetPatientMedSupps(GetPatientMedSuppsRequest request)
        {
            List <PatientMedSupp> patientMedSupps = null;

            try
            {
                List <PatientMedSuppData> data = EndpointUtil.GetPatientMedSupps(request);
                if (data != null && data.Count > 0)
                {
                    patientMedSupps = new List <PatientMedSupp>();
                    data.ForEach(a => patientMedSupps.Add(Mapper.Map <PatientMedSupp>(a)));
                }
                return(patientMedSupps);
            }
            catch (Exception ex) { throw ex; }
        }
示例#13
0
        public List <MedicationMap> GetMedicationMaps(GetMedicationMapsRequest request)
        {
            List <MedicationMap> medMaps = null;

            try
            {
                List <MedicationMapData> data = EndpointUtil.SearchMedicationMap(request);
                if (data != null)
                {
                    medMaps = new List <MedicationMap>();
                    data.ForEach(a => medMaps.Add(Mapper.Map <MedicationMap>(a)));
                }
                return(medMaps);
            }
            catch (Exception ex) { throw ex; }
        }
示例#14
0
        public CareTeam GetCareTeam(GetCareTeamRequest request)
        {
            CareTeam careTeam = null;

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (string.IsNullOrEmpty(request.ContactId))
            {
                throw new ArgumentNullException("request.ContactId");
            }
            try
            {
                CareTeamData careTeamData = EndpointUtil.GetCareTeam(request);
                if (careTeamData != null)
                {
                    careTeam = Mapper.Map <CareTeam>(careTeamData);
                    #region Populate Contact object for each care team member.
                    if (careTeam.Members != null && careTeam.Members.Count > 0)
                    {
                        List <string>      contactIds   = careTeam.Members.Select(a => a.ContactId).ToList();
                        List <ContactData> contactsData = EndpointUtil.GetContactsByContactIds(contactIds, request.Version, request.ContractNumber, request.UserId);
                        if (contactsData != null)
                        {
                            foreach (var member in careTeam.Members)
                            {
                                ContactData data = contactsData.FirstOrDefault(c => c.Id == member.ContactId);
                                if (data == null)
                                {
                                    throw new ApplicationException(string.Format("Contact card for a care team member with contact id = {0} was not found", member.ContactId));
                                }
                                else
                                {
                                    member.Contact = Mapper.Map <Contact>(data);
                                }
                            }
                        }
                    }
                    #endregion
                }
                return(careTeam);
            }
            catch (Exception ex) { throw ex; }
        }
示例#15
0
        public DeleteCareTeamMemberResponse DeleteCareTeamMember(DeleteCareTeamMemberRequest request)
        {
            var response = new DeleteCareTeamMemberResponse();

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            try
            {
                var dataResponse = EndpointUtil.DeleteCareTeamMember(request);

                if (dataResponse != null)
                {
                    //TODO: Refactor.
                    var contact = GetContactByContactId(new GetContactByContactIdRequest
                    {
                        ContractNumber = request.ContractNumber,
                        ContactId      = request.ContactId,
                        UserId         = request.UserId,
                        Version        = request.Version
                    });

                    if (contact == null)
                    {
                        throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId));
                    }

                    var cohortRuleCheckData = new CohortRuleCheckData()
                    {
                        ContactId      = request.ContactId,
                        ContractNumber = request.ContractNumber,
                        UserId         = request.UserId,
                        PatientId      = contact.PatientId
                    };
                    CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData);
                }
            }
            catch (WebServiceException wse)
            {
                throw new WebServiceException("AD:DeleteCareTeamMemberResponse()::" + wse.Message, wse.InnerException);
            }

            return(response);
        }
示例#16
0
        public List <PatientMedFrequency> GetPatientMedFrequencies(GetPatientMedFrequenciesRequest request)
        {
            List <PatientMedFrequency> patientMedFreqs = null;

            try
            {
                List <PatientMedFrequencyData> data = EndpointUtil.GetPatientMedFrequencies(request);
                if (data != null && data.Count > 0)
                {
                    patientMedFreqs = new List <PatientMedFrequency>();
                    data.ForEach(a =>
                                 patientMedFreqs.Add(new PatientMedFrequency {
                        Id = a.Id, Name = a.Name
                    }));
                }
                return(patientMedFreqs);
            }
            catch (Exception ex) { throw ex; }
        }
示例#17
0
 public bool PatientToDoExists(PlanElementEventArg arg, string sourceId)
 {
     try
     {
         var todos = EndpointUtil.GetPatientToDos(arg.PatientId, arg.UserId, arg.DomainRequest);
         if (todos == null)
         {
             return(false);
         }
         var existing = todos.FirstOrDefault(r => r.SourceId == sourceId && (r.StatusId == 1 || r.StatusId == 3)); // open = 1, NotMet = 3 status
         if (existing == null)
         {
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw new Exception("AD:ToDoActivationRule:PatientToDoExists()::" + ex.Message, ex.InnerException);
     }
 }
示例#18
0
        public void HandlePatientProblemRegistration(PlanElementEventArg e, string userId, SpawnElement rse)
        {
            try
            {
                // check if problem code is already registered for patient
                var ppd = EndpointUtil.GetPatientProblem(rse.ElementId, e, userId);

                if (ppd != null)
                {
                    var uspc = new UpdateSpawnProblemCode(e, rse, ppd, true)
                    {
                        EndPointUtil = EndpointUtil
                    };
                    var updateSpawnProblemCode = new SpawnElementStrategy(uspc);
                    if (ppd.StateId != 2)
                    {
                        updateSpawnProblemCode.Evoke();
                    }
                }
                else
                {
                    var spc = new RegisterSpawnProblemCode(e, rse)
                    {
                        EndPointUtil = EndpointUtil
                    };
                    var registerSpawnProblemCode = new SpawnElementStrategy(spc);
                    registerSpawnProblemCode.Evoke();
                }

                // register new problem code with cohortpatientview
                PlanUtils.RegisterCohortPatientViewProblemToPatient(rse.ElementId, e.PatientId,
                                                                    e.DomainRequest);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:StepPlanProcessor:HandlePatientProblemRegistration()::" + ex.Message,
                                    ex.InnerException);
            }
        }
示例#19
0
        public List <PatientAllergy> UpdatePatientAllergies(PostPatientAllergiesRequest request)
        {
            List <PatientAllergy> patientAllergies = null;

            try
            {
                // Update Allergy collection for any newly initialized allergies & then register in search index.
                if (request.PatientAllergies != null && request.PatientAllergies.Count > 0)
                {
                    request.PatientAllergies.ForEach(p =>
                    {
                        if (p.IsNewAllergy)
                        {
                            PostAllergyRequest req = new PostAllergyRequest
                            {
                                Allergy = new DTO.Allergy {
                                    Id = p.AllergyId, TypeIds = p.AllergyTypeIds, Name = p.AllergyName
                                },
                                ContractNumber = request.ContractNumber,
                                UserId         = request.UserId,
                                Version        = request.Version
                            };
                            AllergyData allergyData = EndpointUtil.UpdateAllergy(req);
                            DTO.Allergy newAllergy  = Mapper.Map <DTO.Allergy>(allergyData);
                            // Register newly initialized allergies in search index.
                            SearchManager.RegisterAllergyDocumentInSearchIndex(newAllergy, req.ContractNumber, request);
                        }
                    });
                }
                List <PatientAllergyData> data = EndpointUtil.UpdatePatientAllergies(request);
                if (data != null && data.Count > 0)
                {
                    patientAllergies = new List <PatientAllergy>();
                    data.ForEach(a => patientAllergies.Add(Mapper.Map <PatientAllergy>(a)));
                }
                return(patientAllergies);
            }
            catch (Exception ex) { throw ex; }
        }
示例#20
0
        public Contact GetContactByContactId(GetContactByContactIdRequest request)
        {
            Contact contact = null;

            try
            {
                ContactData contactData = EndpointUtil.GetContactByContactId(request);
                if (contactData != null)
                {
                    contact = Mapper.Map <Contact>(contactData);
                    if (!string.IsNullOrEmpty(contactData.PatientId))
                    {
                        contact.IsPatient = true;
                    }

                    if (!string.IsNullOrEmpty(contactData.UserId))
                    {
                        contact.IsUser = true;
                    }
                }
                return(contact);
            }
            catch (Exception ex) { throw ex; }
        }
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Intervention        interventionTemplate        = null;
                Goal                goalTemplate                = null;
                PatientGoal         patientGoal                 = null;
                PatientGoal         newPGoal                    = null;
                PatientIntervention existingPatientIntervention = null;

                try
                {
                    // get template intervention
                    interventionTemplate = EndpointUtil.GetInterventionById(pe.ElementId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetInterventionById()::" + ex.Message, ex.InnerException);
                }

                try
                {
                    // get template goal
                    goalTemplate = EndpointUtil.GetGoalById(interventionTemplate.TemplateGoalId, userId,
                                                            arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetGoalById()::" + ex.Message, ex.InnerException);
                }

                try
                {
                    // find if patientgoal exists
                    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(goalTemplate.Id, arg.PatientId,
                                                                                    userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new Exception("AD:InterventionActivationRule:GetOpenNotMetPatientGoalByTemplateId()::" + ex.Message, ex.InnerException);
                }

                if (patientGoal != null)
                {
                    try
                    {
                        // find if patientintervention exists
                        existingPatientIntervention =
                            EndpointUtil.GetOpenNotMetPatientInterventionByTemplateId(patientGoal.Id,
                                                                                      interventionTemplate.Id, arg.PatientId, userId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(
                                  "AD:InterventionActivationRule:GetOpenNotMetPatientInterventionByTemplateId()::" +
                                  ex.Message, ex.InnerException);
                    }
                }

                PatientIntervention pIntr = existingPatientIntervention;
                PatientGoal         pGoal = patientGoal;
                List <object>       items = null;
                if (InsertInterventionAllowed(pIntr))
                {
                    // check to see that goal exists
                    if (InsertPatientGoalAllowed(patientGoal))
                    {
                        // 1) insert patient goal
                        pGoal = PlanUtils.InsertPatientGoal(arg, goalTemplate);
                    }

                    pIntr = PlanUtils.InsertPatientIntervention(arg, pGoal, interventionTemplate);

                    items = CreateItemsBag(pIntr, pGoal);
                }

                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = items
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:InterventionActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
示例#22
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Schedule todoTemp = null;
                ToDoData todo     = null;

                if (!PatientToDoExists(arg, pe.ElementId))
                {
                    try
                    {
                        // get template todo from schedule endpoint
                        todoTemp = EndpointUtil.GetScheduleToDoById(pe.ElementId, userId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(ex.Message);
                    }

                    var prog = new System.Collections.Generic.List <string>();
                    if (arg.Program != null)
                    {
                        prog.Add(arg.Program.Id);
                    }

                    string patientId = null;
                    if (arg.Program != null)
                    {
                        patientId = arg.Program.PatientId;
                    }

                    try
                    {
                        todo = new ToDoData
                        {
                            SourceId    = todoTemp.Id,
                            Title       = todoTemp.Title,
                            CategoryId  = todoTemp.CategoryId,
                            CreatedById = userId,
                            StatusId    = todoTemp.StatusId,
                            Description = todoTemp.Description,
                            PriorityId  = todoTemp.PriorityId,
                            DueDate     = HandleDueDate(todoTemp.DueDateRange),
                            StartTime   = todoTemp.StartTime,
                            Duration    = todoTemp.Duration,
                            PatientId   = patientId,
                            ProgramIds  = prog,
                            CreatedOn   = DateTime.UtcNow
                        };

                        SetDefaultAssignment(userId, todoTemp, todo);

                        // modified for ENG-709
                        if (todo.StatusId == 2 || todo.StatusId == 4)
                        {
                            todo.ClosedDate = DateTime.UtcNow;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException("ToDoData Hydration Error." + ex.Message);
                    }

                    try
                    {
                        // register new todo
                        var result = EndpointUtil.PutInsertToDo(todo, arg.UserId, arg.DomainRequest);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message, ex.InnerException);
                    }
                }
                var spawnType = new SpawnType {
                    Type = _alertType.ToString()
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:ToDoActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
示例#23
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                Goal        goalTemp    = null;
                PatientGoal patientGoal = null;
                PatientGoal newPGoal    = null;
                ToDoData    todo        = null;

                try
                {
                    // get template Goal from Goal endpoint
                    goalTemp = EndpointUtil.GetGoalById(pe.ElementId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }

                try
                {
                    // get patient Goal from template id
                    // this will only return patientgoals that are open or notmet state
                    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(pe.ElementId, arg.PatientId, userId, arg.DomainRequest);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException(ex.Message);
                }

                try
                {
                    //Open = 1, Met = 2, NotMet =3, Abandoned =4
                    if (patientGoal == null) // || (patientGoal.StatusId == 2 || patientGoal.StatusId == 4))
                    {
                        newPGoal            = Mapper.Map <PatientGoal>(goalTemp);
                        newPGoal.ProgramIds = new List <string> {
                            arg.Program.Id
                        };
                        newPGoal.PatientId  = arg.PatientId;
                        newPGoal.TemplateId = goalTemp.Id;
                        newPGoal.StartDate  = PlanUtils.HandleDueDate(goalTemp.StartDateRange);
                        newPGoal.TargetDate = PlanUtils.HandleDueDate(goalTemp.TargetDateRange);
                        newPGoal.StatusId   = 1;

                        try
                        {
                            // initialize patientgoal and get id
                            var iPG = GoalsEndpointUtil.GetInitialGoalRequest(new GetInitializeGoalRequest
                            {
                                Context        = "NG",
                                ContractNumber = arg.DomainRequest.ContractNumber,
                                PatientId      = arg.PatientId,
                                Token          = arg.DomainRequest.Token,
                                UserId         = arg.DomainRequest.UserId,
                                Version        = arg.DomainRequest.Version
                            });

                            // update patientgoal
                            if (iPG == null)
                            {
                                throw new ArgumentException("Failed to Initialize patient goal");
                            }

                            newPGoal.Id = iPG.Id;

                            GoalsEndpointUtil.PostUpdateGoalRequest(new PostPatientGoalRequest
                            {
                                ContractNumber = arg.DomainRequest.ContractNumber,
                                Goal           = newPGoal,
                                PatientGoalId  = iPG.Id,
                                PatientId      = arg.PatientId,
                                Token          = arg.DomainRequest.Token,
                                UserId         = arg.DomainRequest.UserId,
                                Version        = arg.DomainRequest.Version
                            });
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message, ex.InnerException);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("PatientGoal Hydration Error." + ex.Message);
                }


                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = new List <object> {
                        newPGoal
                    }
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:ToDoActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
示例#24
0
        public override SpawnType Execute(string userId, PlanElementEventArg arg, SpawnElement pe, ProgramAttributeData pad)
        {
            try
            {
                #region

                //Goal goalTemp = null;
                //Intervention interventionTemp = null;
                //PatientIntervention patientInt = null;
                //PatientIntervention newPInt = null;
                //ToDoData todo = null;

                //try
                //{
                //    // get patientintervention template by id
                //    interventionTemp = EndpointUtil.GetGoalById(pe.ElementId, userId, arg.DomainRequest);
                //}
                //catch(Exception ex)
                //{
                //    throw new ArgumentException(ex.Message);
                //}

                //try
                //{
                //    // get template Goal from Goal endpoint
                //    patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(pe.ElementId, arg.PatientId, userId, arg.DomainRequest);
                //}
                //catch (Exception ex)
                //{
                //    throw new ArgumentException(ex.Message);
                //}

                //try
                //{
                //    //Open = 1, Met = 2, NotMet =3, Abandoned =4
                //    if (patientGoal == null || (patientGoal.StatusId == 2 || patientGoal.StatusId == 4))
                //    {
                //        newPGoal = Mapper.Map<PatientGoal>(goalTemp);
                //        newPGoal.ProgramIds = new List<string> {arg.Program.Id};
                //        newPGoal.PatientId = arg.PatientId;
                //        newPGoal.StatusId = 1;

                //        try
                //        {
                //            // register new patientobservation
                //            // initialize patientgoal and get id
                //            var iPG = GoalsEndpointUtil.GetInitialGoalRequest(new GetInitializeGoalRequest
                //            {
                //                Context = "NG",
                //                ContractNumber = arg.DomainRequest.ContractNumber,
                //                PatientId = arg.PatientId,
                //                Token = arg.DomainRequest.Token,
                //                UserId = arg.DomainRequest.UserId,
                //                Version = arg.DomainRequest.Version
                //            });

                //            // update patientgoal
                //            if (iPG == null)
                //                throw new ArgumentException("Failed to Initialize patient goal");

                //            newPGoal.Id = iPG.Id;

                //            GoalsEndpointUtil.PostUpdateGoalRequest(new PostPatientGoalRequest
                //            {
                //                ContractNumber = arg.DomainRequest.ContractNumber,
                //                Goal = newPGoal,
                //                PatientGoalId = iPG.Id,
                //                PatientId = arg.PatientId,
                //                Token = arg.DomainRequest.Token,
                //                UserId = arg.DomainRequest.UserId,
                //                Version = arg.DomainRequest.Version
                //            });
                //        }
                //        catch (Exception ex)
                //        {
                //            throw new Exception(ex.Message, ex.InnerException);
                //        }
                //    }
                //}
                //catch (Exception ex)
                //{
                //    throw new ArgumentException("PatientGoal Hydration Error." + ex.Message);
                //}

                #endregion

                Task        taskTemplate        = null;
                Goal        goalTemplate        = null;
                PatientGoal patientGoal         = null;
                PatientGoal newPGoal            = null;
                PatientTask existingPatientTask = null;

                // get template intervention
                taskTemplate = EndpointUtil.GetTaskById(pe.ElementId, userId, arg.DomainRequest);

                // get template goal
                goalTemplate = EndpointUtil.GetGoalById(taskTemplate.TemplateGoalId, userId, arg.DomainRequest);

                // find if patientgoal exists
                patientGoal = EndpointUtil.GetOpenNotMetPatientGoalByTemplateId(goalTemplate.Id, arg.PatientId, userId, arg.DomainRequest);

                if (patientGoal != null)
                {
                    // find if patientintervention exists
                    existingPatientTask = EndpointUtil.GetOpenNotMetPatientTaskByTemplateId(patientGoal.Id,
                                                                                            taskTemplate.Id, arg.PatientId, userId, arg.DomainRequest);
                }

                PatientTask   pTsk  = existingPatientTask;
                PatientGoal   pGoal = patientGoal;
                List <object> items = null;
                if (InsertTaskAllowed(existingPatientTask))
                {
                    // check to see that goal exists
                    if (InsertPatientGoalAllowed(patientGoal))
                    {
                        // 1) insert patient goal
                        pGoal = PlanUtils.InsertPatientGoal(arg, goalTemplate);
                    }
                    // insert patient intervention
                    pTsk  = PlanUtils.InsertPatientTask(arg, pGoal, taskTemplate);
                    items = CreateItemsBag(pTsk, pGoal);
                }

                var spawnType = new SpawnType {
                    Type = _alertType.ToString(), Tag = items
                };
                return(spawnType);
            }
            catch (Exception ex)
            {
                throw new Exception("AD:TaskActivationRule:Execute()::" + ex.Message, ex.InnerException);
            }
        }
示例#25
0
 protected static Endpoint GetUniqueEndpoint()
 {
     return(EndpointUtil.GetUniqueEndpoint());
 }
示例#26
0
        public SaveCareTeamResponse SaveCareTeam(SaveCareTeamRequest request)
        {
            var response = new SaveCareTeamResponse();

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (request.CareTeam == null)
            {
                throw new ArgumentNullException("request.CareTeam");
            }

            //if(request.CareTeam.Members.IsNullOrEmpty())
            //     throw new ApplicationException(string.Format("CareTeam should have atleast one or more members."));

            if (string.IsNullOrEmpty(request.ContactId))
            {
                throw new ArgumentException(string.Format("ContactId is null or empty"), "request");
            }

            foreach (var member in request.CareTeam.Members)
            {
                ValidateCareTeamMemberFields(member);

                if (!string.IsNullOrEmpty(member.RoleId) && !string.IsNullOrEmpty(member.CustomRoleName))
                {
                    member.RoleId = null;
                }
            }

            //TODO: Refactor.
            var contact = GetContactByContactId(new GetContactByContactIdRequest
            {
                ContractNumber = request.ContractNumber,
                ContactId      = request.ContactId,
                UserId         = request.UserId,
                Version        = request.Version
            });

            if (contact == null)
            {
                throw new ApplicationException(string.Format("Contact with id: {0} does not exist.", request.ContactId));
            }

            if (!contact.IsPatient)
            {
                throw new ApplicationException(string.Format("Contact with id: {0} is not a patient.", request.ContactId));
            }


            if (CohortRuleUtil.HasMultipleActiveCorePCM(request.CareTeam))
            {
                throw new ApplicationException("The Care team cannot have multiple Active, Core PCMs");
            }

            if (CohortRuleUtil.HasMultipleActiveCorePCP(request.CareTeam))
            {
                throw new ApplicationException("The Care team cannot have multiple Active, Core PCPs");
            }

            try
            {
                var domainResponse = EndpointUtil.SaveCareTeam(request);

                if (domainResponse != null)
                {
                    response.CareTeam = Mapper.Map <CareTeam>(domainResponse.CareTeamData);


                    #region Populate Contact object for each care team member.
                    if (response.CareTeam != null)
                    {
                        if (!response.CareTeam.Members.IsNullOrEmpty())
                        {
                            var contactIds   = response.CareTeam.Members.Select(a => a.ContactId).ToList();
                            var contactsData = EndpointUtil.GetContactsByContactIds(contactIds, request.Version, request.ContractNumber, request.UserId);
                            if (contactsData != null)
                            {
                                foreach (var member in response.CareTeam.Members)
                                {
                                    var data = contactsData.FirstOrDefault(c => c.Id == member.ContactId);
                                    if (data == null)
                                    {
                                        throw new ApplicationException(string.Format("Contact card for a care team member with contact id = {0} was not found", member.ContactId));
                                    }
                                    else
                                    {
                                        member.Contact = Mapper.Map <Contact>(data);
                                    }
                                }
                            }
                        }
                    }

                    #endregion

                    var cohortRuleCheckData = new CohortRuleCheckData()
                    {
                        ContactId      = request.ContactId,
                        ContractNumber = request.ContractNumber,
                        UserId         = request.UserId,
                        PatientId      = contact.PatientId
                    };
                    CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("AD:SaveCareTeam()::" + ex.Message, ex.InnerException);
            }

            return(response);
        }
示例#27
0
        public UpdateCareTeamMemberResponse UpdateCareTeamMember(UpdateCareTeamMemberRequest request)
        {
            var response = new UpdateCareTeamMemberResponse();

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (request.CareTeamMember == null)
            {
                throw new ArgumentNullException("CareTeamMemberData is Null", "request");
            }

            if (string.IsNullOrEmpty(request.ContactId))
            {
                throw new ArgumentNullException("Null or empty ContactId", "request");
            }

            if (string.IsNullOrEmpty(request.CareTeamId))
            {
                throw new ArgumentNullException("Null or empty CareTeamId", "request");
            }

            if (string.IsNullOrEmpty(request.Id))
            {
                throw new ArgumentNullException("Null or empty MemberId", "request");
            }

            if (request.Id != request.CareTeamMember.Id)
            {
                throw new ArgumentNullException("CareTeamMemberData.Id and Id are different", "request");
            }

            var contact = GetContactByContactId(new GetContactByContactIdRequest
            {
                ContractNumber = request.ContractNumber,
                ContactId      = request.ContactId,
                UserId         = request.UserId,
                Version        = request.Version
            });

            if (contact == null)
            {
                throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId));
            }


            var cohortRuleCheckData = new CohortRuleCheckData()
            {
                ContactId      = request.ContactId,
                ContractNumber = request.ContractNumber,
                UserId         = request.UserId,
                PatientId      = contact.PatientId
            };

            //Get the currentActiveCore TeamMember Id.
            string currentActiveCorePCMId = CohortRules.GetCareTeamActiveCorePCMId(cohortRuleCheckData);


            if (currentActiveCorePCMId != null && request.CareTeamMember.Core && currentActiveCorePCMId != request.Id & request.CareTeamMember.RoleId == Constants.PCMRoleId && request.CareTeamMember.StatusId == (int)CareTeamMemberStatus.Active)
            {
                throw new ArgumentNullException("Care Team already has an Active Core PCM", "request");
            }

            ValidateCareTeamMemberFields(request.CareTeamMember);

            try
            {
                var domainResponse = EndpointUtil.UpdateCareTeamMember(request);
                if (domainResponse != null)
                {
                    response.Status = domainResponse.Status;
                    CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("AD:UpdateCareTeamMember()::" + ex.Message, ex.InnerException);
            }

            return(response);
        }
示例#28
0
        public AddCareTeamMemberResponse AddCareTeamMember(AddCareTeamMemberRequest request)
        {
            var response = new AddCareTeamMemberResponse();

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            ValidateCareTeamMemberFields(request.CareTeamMember);

            var careTeamData = EndpointUtil.GetCareTeam(new GetCareTeamRequest {
                ContactId = request.ContactId, ContractNumber = request.ContractNumber, UserId = request.UserId, Version = request.Version
            });

            if (careTeamData == null)
            {
                throw new ApplicationException(string.Format("No care team exists for contact  {0}", request.ContactId));
            }

            var members = careTeamData.Members;

            if (!members.IsNullOrEmpty())
            {
                var mappedMembers = members.Select(Mapper.Map <Member>).ToList();
                mappedMembers.Add(request.CareTeamMember);

                var careTeam = new CareTeam {
                    Members = mappedMembers, ContactId = request.ContactId, Id = careTeamData.Id
                };

                if (CohortRuleUtil.HasMultipleActiveCorePCM(careTeam))
                {
                    throw new ApplicationException("The Care team cannot have multiple Active, Core PCMs");
                }

                if (CohortRuleUtil.HasMultipleActiveCorePCP(careTeam))
                {
                    throw new ApplicationException("The Care team cannot have multiple Active, Core PCPs");
                }
            }

            var contact = GetContactByContactId(new GetContactByContactIdRequest
            {
                ContractNumber = request.ContractNumber,
                ContactId      = request.ContactId,
                UserId         = request.UserId,
                Version        = request.Version
            });

            if (contact == null)
            {
                throw new ApplicationException(string.Format("Contact with id: {0} does not exist", request.ContactId));
            }

            var cohortRuleCheckData = new CohortRuleCheckData()
            {
                ContactId      = request.ContactId,
                ContractNumber = request.ContractNumber,
                UserId         = request.UserId,
                PatientId      = contact.PatientId
            };

            try
            {
                var domainResponse = EndpointUtil.AddCareTeamMember(request);
                if (domainResponse != null)
                {
                    response.Id = domainResponse.Id;
                    CohortRules.EnqueueCohorRuleCheck(cohortRuleCheckData);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("AD:UpdateCareTeamMember()::" + ex.Message, ex.InnerException);
            }

            return(response);
        }
示例#29
0
        public PatientMedSupp SavePatientMedSupp(PostPatientMedSuppRequest request)
        {
            PatientMedSupp patientMedSupp = null;

            try
            {
                if (request.PatientMedSupp != null)
                {
                    string name     = string.IsNullOrEmpty(request.PatientMedSupp.Name) ? string.Empty : request.PatientMedSupp.Name.ToUpper();
                    string form     = string.IsNullOrEmpty(request.PatientMedSupp.Form) ? string.Empty : request.PatientMedSupp.Form.ToUpper();
                    string route    = string.IsNullOrEmpty(request.PatientMedSupp.Route) ? string.Empty : request.PatientMedSupp.Route.ToUpper();
                    string strength = string.IsNullOrEmpty(request.PatientMedSupp.Strength) ? string.Empty : request.PatientMedSupp.Strength;

                    #region Search MedicationMap
                    // Search if any record exists with the given combination of name, strength, route and form.
                    GetMedicationMapsRequest mmRequest = new GetMedicationMapsRequest
                    {
                        Name           = name,
                        Route          = route,
                        Form           = form,
                        Strength       = strength,
                        ContractNumber = request.ContractNumber,
                        UserId         = request.UserId,
                        Version        = request.Version
                    };
                    List <MedicationMapData> list = EndpointUtil.SearchMedicationMap(mmRequest);
                    #endregion
                    if (list == null)
                    {
                        MedicationMapData medData = null;
                        if (string.IsNullOrEmpty(request.PatientMedSupp.FamilyId))
                        {
                            #region Insert MedicationMap
                            PostMedicationMapRequest insertReq = new PostMedicationMapRequest
                            {
                                MedicationMap = new DTO.MedicationMap
                                {
                                    FullName      = name,
                                    SubstanceName = string.Empty,
                                    Strength      = strength,
                                    Route         = route,
                                    Form          = form,
                                    Custom        = true,
                                    Verified      = false
                                },
                                ContractNumber = request.ContractNumber,
                                UserId         = request.UserId,
                                Version        = request.Version
                            };
                            medData = EndpointUtil.InsertMedicationMap(insertReq);
                            #endregion
                        }
                        else
                        {
                            #region Update MedicationMap
                            // This saves the initialized medicine map
                            PutMedicationMapRequest req = new PutMedicationMapRequest
                            {
                                MedicationMap = new DTO.MedicationMap
                                {
                                    Id            = request.PatientMedSupp.FamilyId,
                                    FullName      = name,
                                    SubstanceName = string.Empty,
                                    Strength      = strength,
                                    Route         = route,
                                    Form          = form,
                                    Custom        = true,
                                    Verified      = false
                                },
                                ContractNumber = request.ContractNumber,
                                UserId         = request.UserId,
                                Version        = request.Version
                            };
                            medData = EndpointUtil.UpdateMedicationMap(req);
                            #endregion
                        }
                        RegisterMedication(request, medData);
                    }
                    #region Calculate NDC codes.
                    bool calculateNDC = false;
                    if (request.Insert)
                    {
                        calculateNDC = true;
                        request.PatientMedSupp.SystemName = Constants.SystemName;
                    }
                    else
                    {
                        // On update, check for ReCalculateNDC flag.
                        if (request.RecalculateNDC)
                        {
                            calculateNDC = true;
                        }
                    }
                    if (calculateNDC)
                    {
                        request.PatientMedSupp.NDCs = EndpointUtil.GetMedicationNDCs(request);
                    }
                    #endregion

                    string sigCode = CalculateSigCode(request);
                    if (!string.IsNullOrEmpty(sigCode))
                    {
                        request.PatientMedSupp.SigCode = sigCode;
                    }
                    PatientMedSuppData data = EndpointUtil.SavePatientMedSupp(request);
                    if (data != null)
                    {
                        patientMedSupp = Mapper.Map <PatientMedSupp>(data);
                    }
                }
                return(patientMedSupp);
            }
            catch (Exception ex) { throw ex; }
        }