From 2baeeb3d0431bd8cf7c9f6b24c9a3338bc91163d Mon Sep 17 00:00:00 2001 From: MacAdam Date: Mon, 11 Nov 2024 11:53:48 -0500 Subject: [PATCH 1/4] read fixed size for cap statement --- messaging/Controllers/CapStmtController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/messaging/Controllers/CapStmtController.cs b/messaging/Controllers/CapStmtController.cs index 34fdd4a..92f8bcb 100644 --- a/messaging/Controllers/CapStmtController.cs +++ b/messaging/Controllers/CapStmtController.cs @@ -44,7 +44,11 @@ public async Task GetCapabilityStatement(string jurisdictionId) { using (StreamReader r = new StreamReader(stream)) { - string str = r.ReadToEnd(); + // the capability statement is approximately 1 kb + char[] buffer = new char[2000]; + int size = r.ReadBlock(buffer, 0, 2000); + string str = new string(buffer); + // string str = r.ReadToEnd(); string customStmt = str.Replace("XX", jurisdictionId); JObject json = JObject.Parse(customStmt); return Ok(json); From 78828f4d33199b26fae06d4d1f9b4d1dc6b56e98 Mon Sep 17 00:00:00 2001 From: MacAdam Date: Mon, 11 Nov 2024 14:32:30 -0500 Subject: [PATCH 2/4] require vital type for bfdr processing --- messaging/Controllers/BundlesController.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/messaging/Controllers/BundlesController.cs b/messaging/Controllers/BundlesController.cs index 9d313c1..adaa65c 100644 --- a/messaging/Controllers/BundlesController.cs +++ b/messaging/Controllers/BundlesController.cs @@ -505,21 +505,26 @@ protected virtual string GetNextUri() protected IncomingMessageItem ParseIncomingMessageItem(string jurisdictionId, string vitalType, Bundle bundle) { - - if (_settings.BFDREnabled && (String.IsNullOrEmpty(vitalType) || vitalType.Equals("BFDR"))) + // the vital type must be specified as BFDR to post BFDR records + if (_settings.BFDREnabled && vitalType.Equals("BFDR")) { try { CommonMessage message = BFDRBaseMessage.Parse(bundle); return ValidateAndCreateIncomingMessageItem(message, jurisdictionId); } - catch (BFDR.MessageParseException) { } + catch (BFDR.MessageParseException mpex) + { + _logger.LogDebug($"The message could not be parsed as a BFDR message. {mpex}"); + throw new ArgumentException($"Failed to parse input as a BFDR message, message type unrecognized."); + } catch (ArgumentException aex) { throw aex; } } + // null vital type is considered VRDR by default if (String.IsNullOrEmpty(vitalType) || vitalType.Equals("VRDR")) { try @@ -532,15 +537,18 @@ protected IncomingMessageItem ParseIncomingMessageItem(string jurisdictionId, st { throw mrx; } - catch (VRDR.MessageParseException) { } + catch (VRDR.MessageParseException mpex) + { + _logger.LogDebug($"The message could not be parsed as a VRDR message. {mpex}"); + throw new ArgumentException($"Failed to parse input as a VRDR message, message type unrecognized."); + } catch (ArgumentException aex) { throw aex; } } - _logger.LogDebug("The message could not be parsed as a BFDR or VRDR message. Throw exception."); - throw new ArgumentException("Failed to parse message, message type unrecognized"); + throw new ArgumentException($"Failed to parse input as a VRDR or BFDR message, message type unrecognized."); } protected IncomingMessageItem ValidateAndCreateIncomingMessageItem(CommonMessage message, string jurisdictionId) From 423c463f77f5a62e1a96e8aced8cd21f4fcf981b Mon Sep 17 00:00:00 2001 From: MacAdam Date: Tue, 12 Nov 2024 09:35:50 -0500 Subject: [PATCH 3/4] update tests to use bfdr in url param --- .../Integration/BundlesControllerTests.cs | 12 ++++++------ messaging/Controllers/BundlesController.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/messaging.tests/Integration/BundlesControllerTests.cs b/messaging.tests/Integration/BundlesControllerTests.cs index 0010c27..8c44e89 100644 --- a/messaging.tests/Integration/BundlesControllerTests.cs +++ b/messaging.tests/Integration/BundlesControllerTests.cs @@ -114,7 +114,7 @@ public async System.Threading.Tasks.Task NewBirthSubmissionMessagePostCreatesNew recordSubmission.CertNo = 1; // Submit that Death Record - HttpResponseMessage createSubmissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle", recordSubmission.ToJson()); + HttpResponseMessage createSubmissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle/BFDR/v2.0", recordSubmission.ToJson()); Assert.Equal(HttpStatusCode.NoContent, createSubmissionMessage.StatusCode); Hl7.Fhir.Model.Bundle updatedBundle = null; @@ -330,7 +330,7 @@ public async System.Threading.Tasks.Task QueryByBusinessIdsDeathYear() // Submit that Death Record HttpResponseMessage createSubmissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/" + recordSubmission.JurisdictionId + "/Bundle", recordSubmission.ToJson()); Assert.Equal(HttpStatusCode.NoContent, createSubmissionMessage.StatusCode); - await System.Threading.Tasks.Task.Delay(1000); + await System.Threading.Tasks.Task.Delay(2000); HttpResponseMessage getBundle = await _client.GetAsync("/" + recordSubmission.JurisdictionId + "/Bundle?deathYear=" + recordSubmission.DeathYear); Bundle updatedBundle = await JsonResponseHelpers.ParseBundleAsync(getBundle); @@ -456,7 +456,7 @@ public async System.Threading.Tasks.Task UpdateBirthMessagesAreSuccessfullyAckno recordSubmission.CertNo = 1; // Submit that Death Record - HttpResponseMessage submissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle", recordSubmission.ToJson()); + HttpResponseMessage submissionMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle/BFDR/v2.0", recordSubmission.ToJson()); Assert.Equal(HttpStatusCode.NoContent, submissionMessage.StatusCode); BirthRecordUpdateMessage recordUpdate = new BirthRecordUpdateMessage(recordSubmission.BirthRecord); @@ -466,7 +466,7 @@ public async System.Threading.Tasks.Task UpdateBirthMessagesAreSuccessfullyAckno recordUpdate.CertNo = 1; // Submit update message - HttpResponseMessage updateMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle", recordUpdate.ToJson()); + HttpResponseMessage updateMessage = await JsonResponseHelpers.PostJsonAsync(_client, "/UT/Bundle/BFDR/v2.0", recordUpdate.ToJson()); Assert.Equal(HttpStatusCode.NoContent, updateMessage.StatusCode); // Make sure the ACKs made it into the queue before querying the endpoint @@ -957,7 +957,7 @@ public async void PostNCHSIsInDestinationEndpointList() recordSubmission2.CertNo = 1; recordSubmission2.MessageDestination = "http://notnchs.cdc.gov/bfdr_submission,http://nchs.cdc.gov/bfdr_submission"; // Submit that Death Record - HttpResponseMessage createSubmissionMessage2 = await JsonResponseHelpers.PostJsonAsync(_client, $"/UT/Bundle", recordSubmission2.ToJson()); + HttpResponseMessage createSubmissionMessage2 = await JsonResponseHelpers.PostJsonAsync(_client, $"/UT/Bundle/BFDR/v2.0", recordSubmission2.ToJson()); Assert.Equal(HttpStatusCode.NoContent, createSubmissionMessage2.StatusCode); } @@ -986,7 +986,7 @@ public async void PostNCHSIsInDestinationEndpointListUppercase() recordSubmission.DeathYear = 2024; recordSubmission2.MessageDestination = "temp,http://nchs.CDC.gov/BFDR_Submission,temp"; // Submit that Death Record - HttpResponseMessage createSubmissionMessage2 = await JsonResponseHelpers.PostJsonAsync(_client, $"/MA/Bundle", recordSubmission2.ToJson()); + HttpResponseMessage createSubmissionMessage2 = await JsonResponseHelpers.PostJsonAsync(_client, $"/MA/Bundle/BFDR/v2.0", recordSubmission2.ToJson()); Assert.Equal(HttpStatusCode.NoContent, createSubmissionMessage2.StatusCode); } diff --git a/messaging/Controllers/BundlesController.cs b/messaging/Controllers/BundlesController.cs index adaa65c..c9bd322 100644 --- a/messaging/Controllers/BundlesController.cs +++ b/messaging/Controllers/BundlesController.cs @@ -506,7 +506,7 @@ protected virtual string GetNextUri() protected IncomingMessageItem ParseIncomingMessageItem(string jurisdictionId, string vitalType, Bundle bundle) { // the vital type must be specified as BFDR to post BFDR records - if (_settings.BFDREnabled && vitalType.Equals("BFDR")) + if (_settings.BFDREnabled && !String.IsNullOrEmpty(vitalType) && vitalType.Equals("BFDR")) { try { From c232d1010ccaed416db2b0538cbf8aea732fd404 Mon Sep 17 00:00:00 2001 From: MacAdam Date: Tue, 12 Nov 2024 13:06:25 -0500 Subject: [PATCH 4/4] remove commented out code --- messaging/Controllers/CapStmtController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/messaging/Controllers/CapStmtController.cs b/messaging/Controllers/CapStmtController.cs index 92f8bcb..2603a2e 100644 --- a/messaging/Controllers/CapStmtController.cs +++ b/messaging/Controllers/CapStmtController.cs @@ -48,7 +48,6 @@ public async Task GetCapabilityStatement(string jurisdictionId) char[] buffer = new char[2000]; int size = r.ReadBlock(buffer, 0, 2000); string str = new string(buffer); - // string str = r.ReadToEnd(); string customStmt = str.Replace("XX", jurisdictionId); JObject json = JObject.Parse(customStmt); return Ok(json);