-
Notifications
You must be signed in to change notification settings - Fork 19
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
Network Hip initial implementation(AIIMS) #373
Open
Nexengineer
wants to merge
13
commits into
master
Choose a base branch
from
NetworkHip
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9ca4c9b
Network hip intial implementation
Nexengineer 534a294
Fixing test case
Nexengineer 638b03c
PR Fixes
Nexengineer 4154fee
Test case fixes
Nexengineer 98242ee
Codacy fix
Nexengineer b661805
PR Review Fixes
Nexengineer 26f01d2
PR fixes
Nexengineer f91981c
Adding network call for Discovery
Nexengineer 054386b
Adding model file in Discovery
Nexengineer 97517bf
Merge branch 'master' into NetworkHip
Nexengineer 355f691
Codacy Fix
Nexengineer 6305715
Merge branch 'NetworkHip' of https://github.com/ProjectEKA/hip-servic…
Nexengineer d56e534
Merging with master
Nexengineer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
namespace In.ProjectEKA.DefaultHip.DataFlow | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Mime; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using HipLibrary.Patient; | ||
using HipLibrary.Patient.Model; | ||
using Hl7.Fhir.Model; | ||
using Hl7.Fhir.Serialization; | ||
using Hl7.Fhir.Utility; | ||
using Model; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
using Optional; | ||
using Patient; | ||
using Serilog; | ||
|
||
public class Collect : ICollect | ||
{ | ||
private readonly string HipSystemDataUrl; | ||
private readonly HttpClient HttpClient; | ||
|
||
public Collect(string hipSystemDataUrl, HttpClient httpClient) | ||
{ | ||
HipSystemDataUrl = hipSystemDataUrl; | ||
HttpClient = httpClient; | ||
} | ||
|
||
public async Task<Option<Entries>> CollectData(DataRequest dataRequest) | ||
{ | ||
var bundles = new List<CareBundle>(); | ||
var patientData = await FindPatientsData(dataRequest); | ||
var careContextReferences = patientData.Keys.ToList(); | ||
foreach (var careContextReference in careContextReferences) | ||
foreach (var result in patientData.GetOrDefault(careContextReference)) | ||
{ | ||
Log.Information($"Returning file: {result}"); | ||
var fjp = new FhirJsonParser(); | ||
bundles.Add(new CareBundle(careContextReference, fjp.Parse<Bundle>(result))); | ||
} | ||
|
||
var entries = new Entries(bundles); | ||
return Option.Some(entries); | ||
} | ||
|
||
private async Task<Dictionary<string, List<string>>> FindPatientsData(DataRequest request) | ||
{ | ||
// LogDataRequest(request); | ||
|
||
var patientReferenceNumber = request.CareContexts.First().PatientReference; | ||
var careContexts = request.CareContexts.Select(careContext => careContext.CareContextReference).ToList(); | ||
var dataResponse = await GetPatientsData(new NetworkDataRequest(patientReferenceNumber, | ||
careContexts, | ||
request.DateRange, | ||
request.HiType)); | ||
var structuredData = new Dictionary<string, List<string>>(); | ||
return dataResponse.Map(content => | ||
{ | ||
foreach (var result in content.Results) | ||
{ | ||
if (structuredData.ContainsKey(result.CareContext)) | ||
{ | ||
structuredData[result.CareContext].Add(result.Data); | ||
} | ||
else | ||
{ | ||
structuredData.Add(result.CareContext, new List<string> {result.Data}); | ||
} | ||
} | ||
return structuredData; | ||
}).ValueOr(structuredData); | ||
} | ||
|
||
private async Task<Option<NetworkDataResponse>> GetPatientsData(NetworkDataRequest networkDataRequest) | ||
{ | ||
try | ||
{ | ||
var json = JsonConvert.SerializeObject(networkDataRequest, new JsonSerializerSettings | ||
{ | ||
NullValueHandling = NullValueHandling.Ignore, | ||
ContractResolver = new DefaultContractResolver | ||
{ | ||
NamingStrategy = new CamelCaseNamingStrategy() | ||
} | ||
}); | ||
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri($"{HipSystemDataUrl}")) | ||
{ | ||
Content = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json) | ||
}; | ||
var response = await HttpClient.SendAsync(httpRequestMessage).ConfigureAwait(false); | ||
if (!response.IsSuccessStatusCode) | ||
return Option.None<NetworkDataResponse>(); | ||
|
||
var responseContent = response.Content; | ||
using var reader = new StreamReader(await responseContent.ReadAsStreamAsync()); | ||
var result = await reader.ReadToEndAsync().ConfigureAwait(false); | ||
return Option.Some(JsonConvert.DeserializeObject<NetworkDataResponse>(result)); | ||
} | ||
catch (Exception exception) | ||
{ | ||
Log.Error(exception, exception.StackTrace); | ||
return Option.None<NetworkDataResponse>(); | ||
} | ||
} | ||
|
||
private static void LogDataRequest(DataRequest request) | ||
{ | ||
var ccList = JsonConvert.SerializeObject(request.CareContexts); | ||
var requestedHiTypes = string.Join(", ", request.HiType.Select(hiType => hiType.ToString())); | ||
Log.Information("Data request received." + | ||
$" transactionId:{request.TransactionId} , " + | ||
$"CareContexts:{ccList}, " + | ||
$"HiTypes:{requestedHiTypes}," + | ||
$" From date:{request.DateRange.From}," + | ||
$" To date:{request.DateRange.To}, " + | ||
$"CallbackUrl:{request.DataPushUrl}"); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace In.ProjectEKA.DefaultHip.DataFlow.Model | ||
{ | ||
using HipLibrary.Patient.Model; | ||
public class NetworkData | ||
{ | ||
public string CareContext { get; set; } | ||
public HiType HiType { get; set; } | ||
public string Data { get; set; } | ||
|
||
public NetworkData(string careContext, HiType hiType, string data) | ||
{ | ||
CareContext = careContext; | ||
HiType = hiType; | ||
Data = data; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkDataRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace In.ProjectEKA.DefaultHip.DataFlow.Model | ||
{ | ||
using System.Collections.Generic; | ||
using HipLibrary.Patient.Model; | ||
|
||
public class NetworkDataRequest | ||
{ | ||
public string PatientReference { get; set; } | ||
public IEnumerable<string> CareContexts { get; set; } | ||
public DateRange DataRange { get; set; } | ||
public IEnumerable<HiType> HiTypes { get; set; } | ||
|
||
public NetworkDataRequest(string patientReference, IEnumerable<string> careContexts, DateRange dataRange, IEnumerable<HiType> hiTypes) | ||
{ | ||
PatientReference = patientReference; | ||
CareContexts = careContexts; | ||
DataRange = dataRange; | ||
HiTypes = hiTypes; | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkDataResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace In.ProjectEKA.DefaultHip.DataFlow.Model | ||
{ | ||
using System.Collections.Generic; | ||
|
||
public class NetworkDataResponse | ||
{ | ||
public IEnumerable<NetworkData> Results { get; set; } | ||
|
||
public NetworkDataResponse(IEnumerable<NetworkData> results) | ||
{ | ||
Results = results; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||
|
||||||
<PropertyGroup> | ||||||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||||||
<RootNamespace>In.ProjectEKA.DefaultHip</RootNamespace> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
</PropertyGroup> | ||||||
|
||||||
<ItemGroup> | ||||||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can call it FHIRHip
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done