public void NewSession() { _noID = new SourceAFIS.Templates.NoID(); _noID.SessionID = StringUtilities.SHA256(Guid.NewGuid().ToString()); //TODO: Add domain name to session string. _sessionID = "noid://" + DomainName + "/" + _noID.SessionID; }
public FingerPrintMinutias(string sessionID, Template template, FHIRUtilities.LateralitySnoMedCode laterality, FHIRUtilities.CaptureSiteSnoMedCode captureSiteSnoMedCode) { SourceAFIS.Templates.NoID noID = new SourceAFIS.Templates.NoID(); noID.SessionID = sessionID; LateralitySnoMedCode = laterality; CaptureSiteSnoMedCode = captureSiteSnoMedCode; Minutiae = FingerprintMinutiaConvertor.ConvertTemplate(template); }
static SourceAFIS.Templates.NoID FHIRToNoID(Resource fhirMessage) { SourceAFIS.Templates.NoID GetNoID = null; try { switch (fhirMessage.TypeName) { case "Media": Media mediaBiometrics = (Media)fhirMessage; GetNoID = new SourceAFIS.Templates.NoID(); foreach (Identifier id in mediaBiometrics.Identifier) { if (id.System.Contains("SessionID") == true) { GetNoID.SessionID = id.Value; } else if (id.System.Contains("LocalNoID") == true) { GetNoID.LocalNoID = id.Value; } else if (id.System.Contains("RemoteNoID") == true) { GetNoID.RemoteNoID = id.Value; } } break; case "Patient": case "NoID Profile": throw new Exception("Processing the " + fhirMessage.TypeName + " is not implemented yet."); default: throw new Exception("Could not convert FHIR resource type " + fhirMessage.TypeName + " to a minutia template class."); } } catch (Exception ex) { throw ex; } return(GetNoID); }
public void ProcessRequest(HttpContext context) { try { bool biometricsSaved = false; string missingReason = ""; string question1 = ""; string question2 = ""; string answer1 = ""; string answer2 = ""; if (uint.TryParse(MinimumAcceptedMatchScore, out _minimumAcceptedMatchScore) == false) { _minimumAcceptedMatchScore = 30; } Stream httpStream = context.Request.InputStream; StreamReader httpStreamReader = new StreamReader(httpStream); Resource newResource = FHIRUtilities.StreamToFHIR(httpStreamReader); _patient = (Patient)newResource; //TODO: make sure this FHIR message has a new pending status. //TODO: make this an atomic transaction. // delete the FHIR message from Spark if there is an error in the minutia. Patient ptSaved = (Patient)SendPatientToSparkServer(); //LogUtilities.LogEvent("AddNewPatient.ashx Saved FHIR in spark."); if (ptSaved == null) { _responseText = "Error sending Patient FHIR message to the Spark FHIR endpoint. " + ExceptionString; return; } SourceAFIS.Templates.NoID noID = new SourceAFIS.Templates.NoID(); noID.SessionID = ptSaved.Id.ToString(); //TODO: Add Argon2d hash here: noID.LocalNoID = "noid://" + DomainName + "/" + StringUtilities.SHA256(DomainName + noID.SessionID + NodeSalt); SessionQueue seq = Utilities.PatientToSessionQueue(_patient, ptSaved.Id.ToString(), noID.LocalNoID, "new", "pending"); seq.SubmitDate = DateTime.UtcNow; //TODO: send to selected match hub and get the remote hub ID. // Hub ID in the same format: noid://domain/LocalID if (_patient.Photo.Count > 0) { dbMinutia = new FingerPrintMatchDatabase(DatabaseDirectory, BackupDatabaseDirectory, _minimumAcceptedMatchScore); foreach (var minutia in _patient.Photo) { byte[] byteMinutias = minutia.Data; Stream stream = new MemoryStream(byteMinutias); Media media = (Media)FHIRUtilities.StreamToFHIR(new StreamReader(stream)); // Save minutias for matching. Template fingerprintTemplate = ConvertFHIR.FHIRToTemplate(media); fingerprintTemplate.NoID = noID; try { dbMinutia.LateralityCode = (FHIRUtilities.LateralitySnoMedCode)fingerprintTemplate.NoID.LateralitySnoMedCode; dbMinutia.CaptureSite = (FHIRUtilities.CaptureSiteSnoMedCode)fingerprintTemplate.NoID.CaptureSiteSnoMedCode; } catch { } if (dbMinutia.AddTemplate(fingerprintTemplate) == false) { _responseText = "Error adding a fingerprint to the match database."; } } dbMinutia.Dispose(); biometricsSaved = true; } else { // check alternate pathway Q&A foreach (var id in _patient.Identifier) { if (id.System.ToLower().Contains("biometric") == true) { Extension extExceptionQA = id.Extension[0]; foreach (var ext in extExceptionQA.Extension) { if (ext.Url.ToLower().Contains("reason") == true) { missingReason = ext.Value.ToString(); } else if (ext.Url.ToLower().Contains("question 1") == true) { question1 = ext.Value.ToString(); } else if (ext.Url.ToLower().Contains("answer 1") == true) { answer1 = ext.Value.ToString(); } else if (ext.Url.ToLower().Contains("question 2") == true) { question2 = ext.Value.ToString(); } else if (ext.Url.ToLower().Contains("answer 2") == true) { answer2 = ext.Value.ToString(); } } if ( missingReason.Length > 0 && question1.Length > 0 && answer1.Length > 0 && question2.Length > 0 && answer2.Length > 0 ) { if (missingReason != "I am permanently physically unable to provide fingerprints") { if (missingReason == "I am temporarily physically unable to provide fingerprints") { seq.PatientStatus = "hold**"; } else if (missingReason == "I attempted the fingerprint scan process, but I could not get a successful scan on either hand") { seq.PatientStatus = "hold"; } } else { seq.PatientStatus = "new***"; } biometricsSaved = true; } } } // log patient in alternatesearch container } if (biometricsSaved) { MongoDBWrapper dbwrapper = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress); dbwrapper.AddPendingPatient(seq); } else { _responseText = "Critical Error! No biometrics or alternates provided. Can not complete enrollment."; LogUtilities.LogEvent(_responseText); } //TODO: end atomic transaction. _responseText = "Successful."; //LogUtilities.LogEvent("Ending AddNewPatient.ashx"); } catch (Exception ex) { _responseText = "Error in AddNewPatient::ProcessRequest: " + ex.Message; LogUtilities.LogEvent(_responseText); } context.Response.Write(_responseText); context.Response.End(); }
public PatientProfile(string organizationName, Uri fhirAddress, Patient loadPatient, string noidStatus, DateTime checkinDateTime) { _organizationName = organizationName; _fhirAddress = fhirAddress; _noidStatus = noidStatus; _checkinDateTime = FHIRUtilities.DateTimeToFHIRString(checkinDateTime); NewSession(); if (loadPatient != null) { _noID = new SourceAFIS.Templates.NoID(); SetMetaData(loadPatient); //Sets all the data from the meta area of FHIR message SetIdentifierData(loadPatient); //Sets all the data from the identifier area of FHIR message // Gets the demographics from the patient FHIR resource class _lastName = loadPatient.Name[0].Family.ToString(); List <string> givenNames = loadPatient.Name[0].Given.ToList(); _firstName = givenNames[0].ToString(); if (givenNames.Count > 1) { _middleName = givenNames[1].ToString(); } _gender = loadPatient.Gender.ToString().Substring(0, 1).ToUpper(); _birthDate = loadPatient.BirthDate.ToString(); // Gets the address information from the patient FHIR resource class if (loadPatient.Address.Count > 0) { List <string> addressLines = loadPatient.Address[0].Line.ToList(); _streetAddress = addressLines[0].ToString(); if (addressLines.Count > 1) { _streetAddress2 = addressLines[1].ToString(); } _city = loadPatient.Address[0].City.ToString(); _state = loadPatient.Address[0].State.ToString(); _postalCode = loadPatient.Address[0].PostalCode.ToString(); _country = loadPatient.Address[0].Country.ToString(); } // Gets the contact information from the patient FHIR resource class if (loadPatient.Contact.Count > 0) { foreach (var contact in loadPatient.Contact) { foreach (var telecom in contact.Telecom) { if (telecom.Use.ToString().ToLower() == "home") { if (telecom.System.ToString().ToLower() == "email") { EmailAddress = telecom.Value.ToString(); } else if (telecom.System.ToString().ToLower() == "phone") { PhoneHome = telecom.Value.ToString(); } } else if (telecom.Use.ToString().ToLower() == "work") { PhoneWork = telecom.Value.ToString(); } else if (telecom.Use.ToString().ToLower() == "mobile") { PhoneCell = telecom.Value.ToString(); } } } } if (loadPatient.Photo.Count > 0) { foreach (var minutia in loadPatient.Photo) { Attachment mediaAttachment = loadPatient.Photo[0]; byte[] byteMinutias = mediaAttachment.Data; Stream stream = new MemoryStream(byteMinutias); Media media = (Media)FHIRUtilities.StreamToFHIR(new StreamReader(stream)); // Get captureSite and laterality from media string captureSiteDescription = media.Extension[1].Value.Extension[1].Value.ToString(); string lateralityCode = media.Extension[1].Value.Extension[2].Value.ToString(); string DeviceName = media.Extension[2].Value.Extension[1].Value.ToString(); string OriginalDpi = media.Extension[2].Value.Extension[2].Value.ToString(); string OriginalHeight = media.Extension[2].Value.Extension[3].Value.ToString(); string OriginalWidth = media.Extension[2].Value.Extension[4].Value.ToString(); Template addMinutia = ConvertFHIR.FHIRToTemplate(media); FingerPrintMinutias newFingerPrintMinutias = new FingerPrintMinutias( SessionID, addMinutia, FHIRUtilities.SnoMedCodeToLaterality(lateralityCode), FHIRUtilities.StringToCaptureSite(captureSiteDescription)); AddFingerPrint(newFingerPrintMinutias, DeviceName, Int32.Parse(OriginalDpi), Int32.Parse(OriginalHeight), Int32.Parse(OriginalWidth)); } _biometricsCaptured = GetBiometricsCaptured(); } } else { throw new Exception("Error in PatientProfile constructor. loadPatient is null."); } }