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); }
public InsertBatchPatientsDataResponse InsertBatchPatients(InsertBatchPatientsDataRequest request) { throw new NotImplementedException(); }
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); }