Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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 src/In.ProjectEKA.DefaultHip/Link/PatientRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Option<Patient> PatientWith(string referenceNumber)
return Option.None<Patient>();
}
}

private IEnumerable<Patient> All()
{
var patientsInfo = FileReader.ReadJson(filePath);
Expand Down
69 changes: 69 additions & 0 deletions src/In.ProjectEKA.DefaultHip/Patient/MaskingUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace In.ProjectEKA.DefaultHip.Patient
{
using System.Collections.Generic;
using System.Linq;
using HipLibrary.Patient;

public class MaskingUtility : IMaskUtility
{
private static Dictionary<string, string> maskedDataMap = new Dictionary<string, string>();

public string MaskReference(string referenceNumber)
{
var maskedPatientReferenceNumber = "";
if (referenceNumber.Length > 2)
{
maskedPatientReferenceNumber = string.Concat(
"".PadLeft(referenceNumber.Length - 2, 'X'),
referenceNumber.Substring(referenceNumber.Length - 2));
}
else
{
maskedPatientReferenceNumber = "XXX" + referenceNumber;
}

if (!maskedDataMap.ContainsKey(referenceNumber))
{
maskedDataMap.Add(referenceNumber, maskedPatientReferenceNumber);
}

return maskedPatientReferenceNumber;
}

public string MaskMobileNumber(string mobileNumber)
{
var number = mobileNumber;
var paddingBit = "".PadLeft(mobileNumber.Length - 8, 'X');
return string.Concat(
number.Substring(0, 6) +
paddingBit,
number.Substring(mobileNumber.Length - 2));
}

public string MaskCareContextDisplay(string referenceNumber)
{
return string.Concat(
"".PadLeft(referenceNumber.Length - 4, 'X'),
referenceNumber.Substring(referenceNumber.Length - 2));
}

public string UnmaskData(string maskedData)
{
var keysWithMatchingValues = maskedDataMap.Where(p => p.Value == maskedData).Select(p => p.Key);
return keysWithMatchingValues.First();
}

public string MaskPatientName(string patientName)
{
if (patientName.Length >= 5)
{
return string.Concat(
patientName.Substring(0, 2) +
"".PadLeft(patientName.Length - 4, 'X'),
patientName.Substring(patientName.Length - 2));
}

return "XXX" + patientName;
}
}
}
11 changes: 11 additions & 0 deletions src/In.ProjectEKA.HipLibrary/Patient/IMaskUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace In.ProjectEKA.HipLibrary.Patient
{
public interface IMaskUtility
{
string MaskReference(string referenceNumber);
string MaskCareContextDisplay(string referenceNumber);
string UnmaskData(string maskedData);
string MaskMobileNumber(string mobileNumber);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace In.ProjectEKA.HipLibrary.Patient.Model
{
public class CareContextEnquiry
{
public string ReferenceNumber { get; }
public string ReferenceNumber { get; set; }

public CareContextEnquiry(string referenceNumber)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace In.ProjectEKA.HipLibrary.Patient.Model
{
public class CareContextRepresentation
{
public string ReferenceNumber { get; }
public string ReferenceNumber { get; set; }

public string Display { get; }
public string Display { get; set; }

public CareContextRepresentation(string referenceNumber, string display)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace In.ProjectEKA.HipLibrary.Patient.Model
{
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Xml.Serialization;

public class LinkConfirmationRepresentation
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class LinkEnquiryRepresentation

public string AuthenticationType { get; }

public LinkReferenceMeta Meta { get; }
public LinkReferenceMeta Meta { get; set; }

public LinkEnquiryRepresentation()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ namespace In.ProjectEKA.HipLibrary.Patient.Model
{
public class LinkReferenceMeta
{
public string CommunicationMedium { get; }
public string CommunicationMedium { get; set; }

public string CommunicationHint { get; }
public string CommunicationHint { get; set; }

public string CommunicationExpiry { get; }


public LinkReferenceMeta(string communicationMedium, string communicationHint, string communicationExpiry)
{
CommunicationMedium = communicationMedium;
Expand Down
2 changes: 1 addition & 1 deletion src/In.ProjectEKA.HipLibrary/Patient/Model/Patient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace In.ProjectEKA.HipLibrary.Patient.Model
public class Patient
{
public string Identifier { get; set; }

public Gender Gender { get; set; }

public string PhoneNumber { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace In.ProjectEKA.HipLibrary.Patient.Model

public class PatientEnquiryRepresentation
{
public string ReferenceNumber { get; }
public string ReferenceNumber { get; set; }

public string Display { get; }
public string Display { get; set; }

public IEnumerable<CareContextRepresentation> CareContexts { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.4")
.HasAnnotation("ProductVersion", "3.1.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("In.ProjectEKA.HipService.Discovery.Model.DiscoveryRequest", b =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Linq;

namespace In.ProjectEKA.HipService.Discovery
{
using System.Threading.Tasks;
Expand Down Expand Up @@ -46,5 +48,11 @@ public Task<bool> RequestExistsFor(string requestId)
return discoveryContext.DiscoveryRequest
.AnyAsync(request => request.TransactionId == requestId);
}

public async Task<DiscoveryRequest> GetRequestFor(string transactionId)
{
return await discoveryContext.DiscoveryRequest
.FirstOrDefaultAsync(request => request.TransactionId == transactionId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IDiscoveryRequestRepository
Task<bool> RequestExistsFor(string requestId, string consentManagerUserId, string patientReferenceNumber);

Task<bool> RequestExistsFor(string requestId);

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
Task<bool> RequestExistsFor(string requestId);
Task<bool> RequestExistsFor(string requestId);

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


Task<DiscoveryRequest> GetRequestFor(string requestTransactionId);
}
}
36 changes: 31 additions & 5 deletions src/In.ProjectEKA.HipService/Discovery/PatientDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ namespace In.ProjectEKA.HipService.Discovery
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DefaultHip.Patient;
using HipLibrary.Matcher;
using HipLibrary.Patient;
using HipLibrary.Patient.Model;
using Link;
using In.ProjectEKA.HipService.Link.Model;
using Link.Model;
using Logger;

public class PatientDiscovery
Expand Down Expand Up @@ -36,7 +37,8 @@ public virtual async Task<ValueTuple<DiscoveryRepresentation, ErrorRepresentatio
if (await AlreadyExists(request.TransactionId))
{
return (null,
new ErrorRepresentation(new Error(ErrorCode.DuplicateDiscoveryRequest, "Discovery Request already exists")));
new ErrorRepresentation(new Error(ErrorCode.DuplicateDiscoveryRequest,
"Discovery Request already exists")));
Comment on lines -39 to +41

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.

Is it needed?

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.

I remember you mentioning in another PR that line should not exceed some 80 columns

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.

120's the default column limit. I might have said 80/something whatever is default.

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.

it is at 120.

}

var (linkedAccounts, exception) = await linkPatientRepository.GetLinkedCareContexts(request.Patient.Id);
Expand All @@ -57,8 +59,13 @@ public virtual async Task<ValueTuple<DiscoveryRepresentation, ErrorRepresentatio
{
await discoveryRequestRepository.Add(new Model.DiscoveryRequest(request.TransactionId,
request.Patient.Id, patient.Identifier));
return (new DiscoveryRepresentation(patient.ToPatientEnquiryRepresentation(
GetUnlinkedCareContexts(linkedCareContexts, patient))),

var careContextRepresentations = GetUnlinkedCareContexts(linkedCareContexts, patient).ToList();
var maskedPatientEnquiryRepresentation = GetMaskedPatientEnquiryRepresentation(
patient.ToPatientEnquiryRepresentation(
careContextRepresentations));

return (new DiscoveryRepresentation(maskedPatientEnquiryRepresentation),
(ErrorRepresentation) null);
})
.ValueOr(Task.FromResult(((DiscoveryRepresentation) null,
Expand All @@ -76,7 +83,9 @@ await discoveryRequestRepository.Add(new Model.DiscoveryRequest(request.Transact

await discoveryRequestRepository.Add(new Model.DiscoveryRequest(request.TransactionId,
request.Patient.Id, patientEnquiryRepresentation.ReferenceNumber));
return (new DiscoveryRepresentation(patientEnquiryRepresentation), null);
var representation = GetMaskedPatientEnquiryRepresentation(patientEnquiryRepresentation);

return (new DiscoveryRepresentation(representation), null);
}

private async Task<bool> AlreadyExists(string transactionId)
Expand All @@ -102,5 +111,22 @@ private static IEnumerable<CareContextRepresentation> GetUnlinkedCareContexts(
allLinkedCareContexts.Find(linkedCareContext =>
linkedCareContext == careContext.ReferenceNumber) == null);
}

private PatientEnquiryRepresentation GetMaskedPatientEnquiryRepresentation(
PatientEnquiryRepresentation patient)
{
var maskingUtility = new MaskingUtility();
patient.ReferenceNumber = maskingUtility.MaskReference(patient.ReferenceNumber);
patient.Display = maskingUtility.MaskPatientName(patient.Display);
foreach (var careContextRepresentation in patient.CareContexts.AsEnumerable())
{
careContextRepresentation.ReferenceNumber =
new MaskingUtility().MaskReference(careContextRepresentation.ReferenceNumber);
careContextRepresentation.Display =
new MaskingUtility().MaskCareContextDisplay(careContextRepresentation.Display);
}

return patient;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public LinkPatientContext(DbContextOptions<LinkPatientContext> options) : base(o
}

public DbSet<LinkEnquires> LinkEnquires { get; set; }

public DbSet<LinkedAccounts> LinkedAccounts { get; set; }

public DbSet<LinkedAccounts> LinkedAccounts { get; set; }

public DbSet<InitiatedLinkRequest> InitiatedLinkRequest { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand All @@ -29,7 +29,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.WithOne(c => c.LinkEnquires)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);

modelBuilder.Entity<LinkedAccounts>(builder =>
{
builder.Property(p => p.DateTimeStamp)
Expand All @@ -43,7 +43,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
builder.Property(p => p.Status)
.HasDefaultValueSql("false");
});

modelBuilder.Entity<LinkedAccounts>()
.Property(e => e.CareContexts)
.HasConversion(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// <auto-generated />

using System;
using In.ProjectEKA.HipService.Link.Database;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -15,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.3")
.HasAnnotation("ProductVersion", "3.1.5")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

modelBuilder.Entity("In.ProjectEKA.HipService.Link.Model.CareContext", b =>
Expand Down Expand Up @@ -105,7 +107,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.ToTable("LinkedAccounts");
});

modelBuilder.Entity("In.ProjectEKA.HipService.Link.Model.CareContext", b =>
{
b.HasOne("In.ProjectEKA.HipService.Link.Model.LinkEnquires", "LinkEnquires")
Expand Down
2 changes: 2 additions & 0 deletions src/In.ProjectEKA.HipService/Link/ILinkPatientRepository.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using In.ProjectEKA.HipLibrary.Patient.Model;

namespace In.ProjectEKA.HipService.Link
{
using System;
Expand Down
Loading