Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion hip-service.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C6699092-7
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "In.ProjectEKA.HipServiceTest", "test\In.ProjectEKA.HipServiceTest\In.ProjectEKA.HipServiceTest.csproj", "{B5A9C0B9-25EC-472E-B2CD-3EC5A69584F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "In.ProjectEKA.DefaultHip", "src\In.ProjectEKA.DefaultHip\In.ProjectEKA.DefaultHip.csproj", "{23976B61-FBF9-41B8-AEA2-B70AD47F00A8}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "In.ProjectEKA.NetworkHip", "src\In.ProjectEKA.NetworkHip\In.ProjectEKA.NetworkHip.csproj", "{23976B61-FBF9-41B8-AEA2-B70AD47F00A8}"

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "In.ProjectEKA.DefaultHipTest", "test\In.ProjectEKA.DefaultHipTest\In.ProjectEKA.DefaultHipTest.csproj", "{4412373D-2E69-412A-8264-FA2806902173}"
EndProject
Expand Down
127 changes: 0 additions & 127 deletions src/In.ProjectEKA.DefaultHip/DataFlow/Collect.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\In.ProjectEKA.DefaultHip\In.ProjectEKA.DefaultHip.csproj" />
<ProjectReference Include="..\In.ProjectEKA.HipLibrary\In.ProjectEKA.HipLibrary.csproj" />
<ProjectReference Include="..\In.ProjectEKA.NetworkHip\In.ProjectEKA.NetworkHip.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/In.ProjectEKA.HipService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void ConfigureServices(IServiceCollection services)
.AddHangfire(config => { config.UseMemoryStorage(); })
.AddSingleton<IEncryptor, Encryptor>()
.AddSingleton<IPatientRepository>(new PatientRepository("demoPatients.json"))
.AddSingleton<ICollect>(new Collect("demoPatientCareContextDataMap.json"))
.AddSingleton<ICollect>(new Collect("http://localhost:8003/getData", HttpClient))
Comment thread
Veena-tw marked this conversation as resolved.
Outdated
.AddSingleton<IPatientRepository>(new PatientRepository("demoPatients.json"))
.AddRabbit(Configuration)
.Configure<OtpServiceConfiguration>(Configuration.GetSection("OtpService"))
Expand Down
6 changes: 3 additions & 3 deletions src/In.ProjectEKA.HipService/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"Serilog": {
"Using": [],
"MinimumLevel": {
"Default": "Debug",
"Default": "Information",
"Override": {
"Microsoft": "Debug",
"System": "Debug"
"Microsoft": "Warning",
"System": "Information"
}
},
"Enrich": [
Expand Down
2 changes: 1 addition & 1 deletion src/In.ProjectEKA.HipService/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
"System": "Information"
}
},
"Enrich": [
Expand Down
124 changes: 124 additions & 0 deletions src/In.ProjectEKA.NetworkHip/DataFlow/Collect.cs
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 src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkData.cs
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 src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkDataRequest.cs
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 src/In.ProjectEKA.NetworkHip/DataFlow/Model/NetworkDataResponse.cs
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>In.ProjectEKA.DefaultHip</RootNamespace>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<RootNamespace>In.ProjectEKA.DefaultHip</RootNamespace>
<RootNamespace>In.ProjectEKA.NetworkHip</RootNamespace>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\In.ProjectEKA.DefaultHip\In.ProjectEKA.DefaultHip.csproj" />
<ProjectReference Include="..\..\src\In.ProjectEKA.HipLibrary\In.ProjectEKA.HipLibrary.csproj" />
<ProjectReference Include="..\..\src\In.ProjectEKA.NetworkHip\In.ProjectEKA.NetworkHip.csproj" />
</ItemGroup>
</Project>