/// <summary> /// Process a response message doing query continuation if needed /// </summary> private void PullPatientsAsync(Object state) { // Cast request QBP_Q21 request = state as QBP_Q21; // Send the PDQ message try { var response = this.m_sender.SendAndReceive(request) as RSP_K21; AuditUtil.SendPDQAudit(request, response); if (response == null || response.MSA.AcknowledgmentCode.Value != "AA") { foreach (var err in response.ERR.GetErrorCodeAndLocation()) { Trace.TraceError("{0}: CR ERR: {1} ({2})", this.m_context.JobId, err.CodeIdentifyingError.Text, err.CodeIdentifyingError.AlternateText); } // Kill! Trace.TraceError("Stopping sync"); this.m_errorState = true; } // Is there a continuation pointer? if (!String.IsNullOrEmpty(response.DSC.ContinuationPointer.Value)) { Trace.TraceInformation("{0}: Need to continue query", this.m_context.JobId); request.DSC.ContinuationPointer.Value = response.DSC.ContinuationPointer.Value; this.UpdateMSH(request.MSH, "QBP_Q21", "QBP", "Q22"); this.m_waitThread.QueueUserWorkItem(this.PullPatientsAsync, request); } // Process the patients in this response lock (this.m_syncState) for (int i = 0; i < response.QUERY_RESPONSERepetitionsUsed; i++) { var responseData = response.GetQUERY_RESPONSE(i); this.m_workerItems.Push(responseData); } // Relieve memorypressure lock (this.m_syncState) while (this.m_workerItems.Count > 0) { this.m_waitThread.QueueUserWorkItem(this.ProcessPIDAsync, this.m_workerItems.Pop()); } } catch (Exception e) { Trace.TraceError(e.ToString()); this.m_errorState = true; } }