private bool IsValidPatientId(PutProgramToPatientRequest request)
        {
            bool result = false;

            try
            {
                string      path           = ConfigurationManager.AppSettings["DDPatientServiceUrl"];
                string      contractNumber = request.ContractNumber;
                string      context        = request.Context;
                double      version        = request.Version;
                IRestClient client         = new JsonServiceClient();

                string url = Helper.BuildURL(string.Format("{0}/{1}/{2}/{3}/patient/{4}",
                                                           path,
                                                           context,
                                                           version,
                                                           contractNumber,
                                                           request.PatientId), request.UserId);

                GetPatientDataResponse response = client.Get <GetPatientDataResponse>(url);

                if (response.Patient != null)
                {
                    result = true;
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:DataProgramManager:IsValidPatientId()::" + ex.Message, ex.InnerException);
            }
        }
Exemple #2
0
            public void Success()
            {
                PutProgramToPatientRequest request = new PutProgramToPatientRequest
                {
                    UserId            = "123456789012345678901234",
                    Context           = "NG",
                    ContractNumber    = "InHealth001",
                    ContractProgramId = "123456789012345678901111",
                    PatientId         = "222256789012345678902222",
                    Token             = "222256789012349999999999",
                    Version           = 1.0
                };

                ProgramService ps = new ProgramService
                {
                    CommonFormatterUtil = new StubCommonFormatterUtil(),
                    Helpers             = new StubHelper(),
                    ProgramDataManager  = new StubProgramDataManager()
                };

                PutProgramToPatientResponse response = ps.Put(request);
                int control = 1;

                Assert.AreEqual(control, response.Outcome.Result);
            }
        private bool IsContractProgramAssignable(PutProgramToPatientRequest request)
        {
            bool result = false;

            try
            {
                IProgramRepository contractProgRepo = Factory.GetRepository(request, RepositoryType.ContractProgram);

                ContractProgram c = contractProgRepo.FindByID(request.ContractProgramId) as ContractProgram;

                if (c != null)
                {
                    if (c.Status == 1 && c.Delete != true)
                    {
                        result = true;
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:DataProgramManager:IsContractProgramAssignable" + ex.Message, ex.InnerException);
            }
        }
Exemple #4
0
        public void PutProgramToPatientTest()
        {
            string userId = "000000000000000000000000";
            PutProgramToPatientRequest request = new PutProgramToPatientRequest {
                PatientId = "5325da17d6a4850adcbba532", CareManagerId = "5325c81f072ef705080d347e", ContractProgramId = "5330920da38116ac180009d2", UserId = userId
            };

            ProgramDataManager pm = new ProgramDataManager {
                Factory = new ProgramRepositoryFactory(), DTOUtility = new DTOUtility {
                    Factory = new ProgramRepositoryFactory()
                }
            };

            PutProgramToPatientResponse response = pm.PutPatientToProgram(request);

            Assert.IsNotNull(response);
        }
        private bool IsValidContractProgramId(PutProgramToPatientRequest request)
        {
            bool result = false;

            try
            {
                IProgramRepository contractProgRepo = Factory.GetRepository(request, RepositoryType.ContractProgram);

                object contractProgram = contractProgRepo.FindByID(request.ContractProgramId);
                if (contractProgram != null)
                {
                    result = true;
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:DataProgramManager:IsValidContractProgramId()::" + ex.Message, ex.InnerException);
            }
        }
Exemple #6
0
        public PutProgramToPatientResponse Put(PutProgramToPatientRequest request)
        {
            PutProgramToPatientResponse response = new PutProgramToPatientResponse();

            try
            {
                if (string.IsNullOrEmpty(request.UserId))
                {
                    throw new UnauthorizedAccessException("ProgramDD:Put()::Unauthorized Access");
                }

                response         = ProgramDataManager.PutPatientToProgram(request);
                response.Version = request.Version;
            }
            catch (Exception ex)
            {
                CommonFormatterUtil.FormatExceptionResponse(response, base.Response, ex);

                string aseProcessID = ConfigurationManager.AppSettings.Get("ASEProcessID") ?? "0";
                Helpers.LogException(int.Parse(aseProcessID), ex);
            }
            return(response);
        }
        public PutProgramToPatientResponse PutPatientToProgram(PutProgramToPatientRequest request)
        {
            try
            {
                PutProgramToPatientResponse response = new PutProgramToPatientResponse();
                response.Outcome = new Phytel.API.DataDomain.Program.DTO.Outcome();

                #region validation calls
                if (!IsValidPatientId(request))
                {
                    return(FormatExceptionResponse(response, "Patient does not exist or has an invalid id.", "500"));
                }

                if (!IsValidContractProgramId(request))
                {
                    return(FormatExceptionResponse(response, "ContractProgram does not exist or has an invalid identifier.", "500"));
                }

                if (!IsContractProgramAssignable(request))
                {
                    return(FormatExceptionResponse(response, "ContractProgram is not currently active.", "500"));
                }
                #endregion

                /**********************************/
                List <MEPatientProgram> pp = DTOUtility.FindExistingpatientProgram(request);

                if (!DTOUtility.CanInsertPatientProgram(pp))
                {
                    response.Outcome.Result = 0;
                    response.Outcome.Reason = pp[0].Name + " is already assigned or reassignment is not allowed";
                }
                else
                {
                    MEProgram cp = DTOUtility.GetProgramForDeepCopy(request);

                    var stepIdList = new List <ObjectId>();
                    List <MEResponse> responseList = DTOUtility.GetProgramResponseslist(stepIdList, cp, request);
                    DTOUtils.HydrateResponsesInProgram(cp, responseList, request.UserId);
                    MEPatientProgram nmePp = DTOUtility.CreateInitialMEPatientProgram(request, cp, stepIdList);
                    DTOUtility.InitializePatientProgramAssignment(request, nmePp);
                    List <MEPatientProgramResponse> pprs = DTOUtils.ExtractMEPatientProgramResponses(nmePp, request.ContractNumber, request.UserId);
                    ProgramInfo pi = DTOUtility.SaveNewPatientProgram(request, nmePp);

                    if (pi != null)
                    {
                        response.program = pi;
                        DTOUtility.SavePatientProgramResponses(pprs, request);
                        DTOUtility.InitializeProgramAttributes(request, response);
                    }

                    response.Outcome.Result = 1;
                    response.Outcome.Reason = "Successfully assigned this program for the individual";
                }

                return(response);
            }
            catch (Exception ex)
            {
                throw new Exception("DD:DataProgramManager:PutPatientToProgram()::" + ex.Message, ex.InnerException);
            }
        }