public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { Stream httpStream = context.Request.InputStream; StreamReader httpStreamReader = new StreamReader(httpStream); Resource newResource = FHIRUtilities.StreamToFHIR(httpStreamReader); _patient = (Patient)newResource; //find all patient without fingerprints. should be a small sample. //if found, return localid //if not found, return "no match found" MongoDBWrapper dbwrapper = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress); AlternateSearch altSearch = GetAlternateFromPatient(_patient); string localNoID = dbwrapper.AlternateSearch(altSearch); if (localNoID.ToLower().Contains("noid://") == false) { dbwrapper.AddAlternateSearch(altSearch); _responseText = "no match found"; } else { _responseText = localNoID; } } catch (Exception ex) { _responseText = "Error in AltMatchByDemographics::ProcessRequest: " + ex.Message; LogUtilities.LogEvent(_responseText); } context.Response.Write(_responseText); context.Response.End(); }
public void ProcessRequest(HttpContext context) { try { if (uint.TryParse(MinimumAcceptedMatchScore, out _minimumAcceptedMatchScore) == false) { _minimumAcceptedMatchScore = 30; } Resource newResource = FHIRUtilities.StreamToFHIR(new StreamReader(context.Request.InputStream)); _biometics = (Media)newResource; // TODO send to biometric match engine. If found, add patient reference to FHIR message. // convert FHIR fingerprint message (_biometics) to AFIS template class Template probe = ConvertFHIR.FHIRToTemplate(_biometics); dbMinutia = new FingerPrintMatchDatabase(_databaseDirectory, _backupDatabaseDirectory, _minimumAcceptedMatchScore); try { dbMinutia.LateralityCode = (FHIRUtilities.LateralitySnoMedCode)probe.NoID.LateralitySnoMedCode; dbMinutia.CaptureSite = (FHIRUtilities.CaptureSiteSnoMedCode)probe.NoID.CaptureSiteSnoMedCode; } catch { } MinutiaResult minutiaResult = dbMinutia.SearchPatients(probe); if (minutiaResult != null) { if (minutiaResult.NoID != null && minutiaResult.NoID.Length > 0) { // Fingerprint found in database // check if patient is already pending. MongoDBWrapper dbwrapper = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress); string currentStatus = dbwrapper.GetCurrentStatus(minutiaResult.NoID); if (currentStatus.ToLower() != "pending") { _responseText = minutiaResult.NoID; //TODO: for now, it returns the localNoID. should return a FHIR response. } else { _responseText = "pending"; } LogUtilities.LogEvent(_responseText); } else { _responseText = "No local database match."; LogUtilities.LogEvent(_responseText); } } else { _responseText = "No local database match."; LogUtilities.LogEvent(_responseText); } dbMinutia.Dispose(); LogUtilities.LogEvent("After dbMinutia.Dispose();"); } catch (Exception ex) { _exception = ex; _responseText = ex.Message; } context.Response.Write(_responseText); context.Response.End(); }
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(); }