/// <inheritdoc/> public async Task <RequestResult <List <MedicationStatementHistory> > > GetMedicationStatementsHistory(string hdid, string?protectiveWord) { using ITracer tracer = this.traceService.TraceMethod(this.GetType().Name); this.logger.LogDebug("Getting history of medication statements"); this.logger.LogTrace($"User hdid: {hdid}"); RequestResult <List <MedicationStatementHistory> > result = new RequestResult <List <MedicationStatementHistory> >(); var validationResult = ValidateProtectiveWord(protectiveWord); bool okProtectiveWord = validationResult.Item1; if (okProtectiveWord) { // Retrieve the phn string jwtString = this.httpContextAccessor.HttpContext.Request.Headers["Authorization"][0]; RequestResult <Patient> patientResult = this.patientDelegate.GetPatient(hdid, jwtString); if (patientResult.ResultStatus == ResultType.Success && patientResult.ResourcePayload != null) { Patient patient = patientResult.ResourcePayload; MedicationHistoryQuery historyQuery = new MedicationHistoryQuery() { StartDate = patient.Birthdate, EndDate = System.DateTime.Now, PHN = patient.PersonalHealthNumber, PageSize = 20000, }; IPAddress address = this.httpContextAccessor.HttpContext.Connection.RemoteIpAddress; string ipv4Address = address.MapToIPv4().ToString(); RequestResult <MedicationHistoryResponse> response = await this.medicationStatementDelegate.GetMedicationStatementsAsync(historyQuery, protectiveWord, hdid, ipv4Address).ConfigureAwait(true); result.ResultStatus = response.ResultStatus; result.ResultError = response.ResultError; if (response.ResultStatus == ResultType.Success) { result.PageSize = historyQuery.PageSize; result.PageIndex = historyQuery.PageNumber; if (response.ResourcePayload != null && response.ResourcePayload.Results != null) { result.TotalResultCount = response.ResourcePayload.Records; result.ResourcePayload = MedicationStatementHistory.FromODRModelList(response.ResourcePayload.Results.ToList()); this.PopulateBrandName(result.ResourcePayload.Select(r => r.MedicationSumary).ToList()); } else { result.ResourcePayload = new List <MedicationStatementHistory>(); } } } else { result.ResultError = patientResult.ResultError; } } else { this.logger.LogInformation($"Invalid protective word. {hdid}"); result.ResultStatus = ResultType.Protected; result.ResultError = new RequestResultError() { ResultMessage = validationResult.Item2, ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationInternal, ServiceType.Patient) }; } this.logger.LogDebug($"Finished getting history of medication statements"); return(result); }
/// <inheritdoc/> public async Task <RequestResult <IList <MedicationStatementHistory> > > GetMedicationStatementsHistory(string hdid, string?protectiveWord) { using (Source.StartActivity("GetMedicationStatementsHistory")) { this.logger.LogDebug("Getting history of medication statements"); this.logger.LogTrace($"User hdid: {hdid}"); RequestResult <IList <MedicationStatementHistory> > result = new RequestResult <IList <MedicationStatementHistory> >(); var validationResult = ValidateProtectiveWord(protectiveWord); bool okProtectiveWord = validationResult.Item1; if (okProtectiveWord) { // Retrieve the phn RequestResult <PatientModel> patientResult = await this.patientService.GetPatient(hdid).ConfigureAwait(true); if (patientResult.ResultStatus == ResultType.Success && patientResult.ResourcePayload != null) { PatientModel patient = patientResult.ResourcePayload; ODRHistoryQuery historyQuery = new ODRHistoryQuery() { StartDate = patient.Birthdate, EndDate = System.DateTime.Now, PHN = patient.PersonalHealthNumber, PageSize = 20000, }; IPAddress?address = this.httpContextAccessor.HttpContext?.Connection.RemoteIpAddress; string ipv4Address = address?.MapToIPv4().ToString() ?? "Unknown"; RequestResult <MedicationHistoryResponse> response = await this.medicationStatementDelegate.GetMedicationStatementsAsync(historyQuery, protectiveWord, hdid, ipv4Address).ConfigureAwait(true); result.ResultStatus = response.ResultStatus; result.ResultError = response.ResultError; if (response.ResultStatus == ResultType.Success) { result.PageSize = historyQuery.PageSize; result.PageIndex = historyQuery.PageNumber; if (response.ResourcePayload != null && response.ResourcePayload.Results != null) { result.TotalResultCount = response.ResourcePayload.TotalRecords; result.ResourcePayload = MedicationStatementHistory.FromODRModelList(response.ResourcePayload.Results.ToList()); this.PopulateMedicationSummary(result.ResourcePayload.Select(r => r.MedicationSummary).ToList()); } else { result.ResourcePayload = new List <MedicationStatementHistory>(); } } } else { result.ResultError = patientResult.ResultError; } } else { this.logger.LogInformation($"Invalid protective word. {hdid}"); result.ResultStatus = Common.Constants.ResultType.ActionRequired; result.ResultError = ErrorTranslator.ActionRequired(validationResult.Item2, ActionType.Protected); } this.logger.LogDebug($"Finished getting history of medication statements"); return(result); } }