Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read capability stream #99

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions messaging.tests/Integration/BundlesControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 14 additions & 6 deletions messaging/Controllers/BundlesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 && !String.IsNullOrEmpty(vitalType) && 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
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion messaging/Controllers/CapStmtController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

// GET: CapabilityStatement
[HttpGet]
public async Task<IActionResult> GetCapabilityStatement(string jurisdictionId)

Check warning on line 31 in messaging/Controllers/CapStmtController.cs

View workflow job for this annotation

GitHub Actions / test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (!VR.IJEData.Instance.JurisdictionCodes.ContainsKey(jurisdictionId))
{
Expand All @@ -44,7 +44,10 @@
{
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 customStmt = str.Replace("XX", jurisdictionId);
JObject json = JObject.Parse(customStmt);
return Ok(json);
Expand Down
Loading