Example #1
0
        public object Save <T>(T patients, string contract)
        {
            LoggerDomainEvent.Raise(new LogStatus {
                Message = "1) Sending insert Patient DD request.", Type = LogType.Debug
            });

            var userid = ProcConstants.UserId; // need to find a valid session id.

            try
            {
                IRestClient client = new JsonServiceClient {
                    Timeout = TimeSpan.FromMinutes(50)
                };                                                                                //new TimeSpan( 28000000000) };
                //"/{Context}/{Version}/{ContractNumber}/Batch/Patients"
                var url =
                    Helper.BuildURL(
                        string.Format("{0}/{1}/{2}/{3}/Batch/Patients/", DDPatientServiceUrl, "NG", 1, contract), userid);

                InsertBatchPatientsDataResponse response = client.Post <InsertBatchPatientsDataResponse>(url,
                                                                                                         new InsertBatchPatientsDataRequest
                {
                    Context        = "NG",
                    ContractNumber = contract,
                    PatientsData   = patients as List <PatientData>,
                    UserId         = userid,
                    Version        = 1
                });

                LogUtil.FormatOutputDebug <T>(response);
                LoggerDomainEvent.Raise(new LogStatus {
                    Message = "1) Success", Type = LogType.Debug
                });
                return(response.Responses);
            }
            catch (Exception ex)
            {
                LoggerDomainEvent.Raise(new LogStatus {
                    Message = "PatientDataDomain:Save(): " + ex.Message, Type = LogType.Error
                });
                throw new ArgumentException("PatientDataDomain:Save(): " + ex.Message);
            }
        }
Example #2
0
        public InsertBatchPatientsDataResponse Post(InsertBatchPatientsDataRequest request)
        {
            InsertBatchPatientsDataResponse response = new InsertBatchPatientsDataResponse();

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

                response         = PatientManager.InsertBatchPatients(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);
        }
Example #3
0
        public InsertBatchPatientsDataResponse InsertBatchPatients(InsertBatchPatientsDataRequest request)
        {
            InsertBatchPatientsDataResponse response = new InsertBatchPatientsDataResponse();

            if (request.PatientsData != null && request.PatientsData.Count > 0)
            {
                List <HttpObjectResponse <PatientData> > list = new List <HttpObjectResponse <PatientData> >();
                IPatientRepository repo   = Factory.GetRepository(request, RepositoryType.Patient);
                BulkInsertResult   result = (BulkInsertResult)repo.InsertAll(request.PatientsData.Cast <object>().ToList());
                if (result != null)
                {
                    if (result.ProcessedIds != null && result.ProcessedIds.Count > 0)
                    {
                        // Get the patients that were newly inserted.
                        List <PatientData> insertedPatients = repo.Select(result.ProcessedIds);
                        if (insertedPatients != null && insertedPatients.Count > 0)
                        {
                            List <string> insertedPatientIds = insertedPatients.Select(p => p.Id).ToList();

                            #region DataAudit for Patients
                            AuditHelper.LogDataAudit(request.UserId, MongoCollectionName.Patient.ToString(), insertedPatientIds, Common.DataAuditType.Insert, request.ContractNumber);
                            #endregion

                            #region BulkInsert CohortPatientView
                            List <CohortPatientViewData> cpvList = getMECohortPatientView(insertedPatients);
                            IPatientRepository           cpvRepo = Factory.GetRepository(request, RepositoryType.CohortPatientView);
                            cpvRepo.InsertAll(cpvList.Cast <object>().ToList());
                            #endregion

                            #region BulkInsert EngagePatientSystems.
                            List <string>            processedPatientSystemIds = insertBatchEngagePatientSystem(insertedPatientIds, request);
                            List <PatientSystemData> insertedPatientSystems    = getPatientSystems(processedPatientSystemIds, request);

                            #region DataAudit for EngagePatientSystems
                            List <string> insertedPatientSystemIds = insertedPatientSystems.Select(p => p.Id).ToList();
                            AuditHelper.LogDataAudit(request.UserId, MongoCollectionName.PatientSystem.ToString(), insertedPatientSystemIds, Common.DataAuditType.Insert, request.ContractNumber);
                            #endregion

                            insertedPatients.ForEach(r =>
                            {
                                string engageValue = string.Empty;
                                var x = insertedPatientSystems.Where(s => s.PatientId == r.Id).FirstOrDefault();
                                if (x != null)
                                {
                                    engageValue = x.Value;
                                }
                                list.Add(new HttpObjectResponse <PatientData> {
                                    Code = HttpStatusCode.Created, Body = (PatientData) new PatientData {
                                        Id = r.Id, ExternalRecordId = r.ExternalRecordId, EngagePatientSystemValue = engageValue
                                    }
                                });
                            });
                            #endregion
                        }
                    }
                    result.ErrorMessages.ForEach(e =>
                    {
                        list.Add(new HttpObjectResponse <PatientData> {
                            Code = HttpStatusCode.InternalServerError, Message = e
                        });
                    });
                }
                response.Responses = list;
            }

            return(response);
        }