-
Notifications
You must be signed in to change notification settings - Fork 20
Unmask story #306
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
base: master
Are you sure you want to change the base?
Unmask story #306
Changes from all commits
fe64db3
cd724f4
1aa2bfb
715b150
d6130ba
5e06bb4
9168c81
eeb7fbe
2c7e3b8
fd059d3
b80116c
cf69d07
65388b4
5329544
77d0ada
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } | ||
| } | ||
| } |
| 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 |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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
Contributor
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. Is it needed?
Contributor
Author
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. I remember you mentioning in another PR that line should not exceed some 80 columns
Contributor
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. 120's the default column limit. I might have said 80/something whatever is default.
Contributor
Author
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. it is at 120. |
||
| } | ||
|
|
||
| var (linkedAccounts, exception) = await linkPatientRepository.GetLinkedCareContexts(request.Patient.Id); | ||
|
|
@@ -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, | ||
|
|
@@ -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) | ||
|
|
@@ -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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| using In.ProjectEKA.HipLibrary.Patient.Model; | ||
|
|
||
| namespace In.ProjectEKA.HipService.Link | ||
| { | ||
| using System; | ||
|
|
||
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.
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