コード例 #1
0
ファイル: MatchProbesTest.cs プロジェクト: AmirAbrams/noid-1
        public MatchProbesTest(string databaseDirectory, string backupDatabaseDirectory, string lateralityCode, string captureSiteCode)
        {
            dbMinutia = new FingerPrintMatchDatabase(databaseDirectory, backupDatabaseDirectory, _matchThreshold);
            try
            {
                dbMinutia.LateralityCode = (FHIRUtilities.LateralitySnoMedCode)Int32.Parse(lateralityCode);
                dbMinutia.CaptureSite    = (FHIRUtilities.CaptureSiteSnoMedCode)Int32.Parse(captureSiteCode);
            }
            catch { }

            if (!(SetupScanner()))
            {
                if ((_exception == null))
                {
                    ScannerStatus = "Failed: Unknown error.";
                    throw new Exception("Unknown scanner setup error.");
                }
                else
                {
                    ScannerStatus = "Failed: " + _exception.Message;
                    throw _exception;
                }
            }
            ScannerStatus = "OK";
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string purgeResult = "";
            string destroyKey  = "";

            try
            {
                if (uint.TryParse(MinimumAcceptedMatchScore, out _minimumAcceptedMatchScore) == false)
                {
                    _minimumAcceptedMatchScore = 30;
                }

                foreach (String key in context.Request.QueryString.AllKeys)
                {
                    if (key == "destroykey")
                    {
                        destroyKey = context.Request.QueryString[key];
                        break;
                    }
                }
                if (destroyKey == DestroyKey)
                {
                    MongoDBWrapper dbwrapper = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress);
                    if (dbwrapper.DeleteMongoDBs() == true)
                    {
                        FingerPrintMatchDatabase dbMinutia = new FingerPrintMatchDatabase(DatabaseLocation, BackupLocation, _minimumAcceptedMatchScore);
                        if (dbMinutia.DeleteMatchDatabase())
                        {
                            purgeResult = "Successful.";
                        }
                        else
                        {
                            purgeResult = "Error in PurgeAllDatabases::ProcessRequest: Unable to delete all databases.";
                        }
                    }
                }
                else
                {
                    //TODO: log this event as an invalid attempt due to mismatched keys.
                }
            }
            catch (Exception ex)
            {
                purgeResult = "Error in PurgeAllDatabases::ProcessRequest: " + ex.Message;
            }
            context.Response.Write(purgeResult);
        }
コード例 #3
0
 public MatchProbesTest()
 {
     dbMinutia = new FingerPrintMatchDatabase(_dabaseFilePath, _dabaseBackupLocation, _matchThreshold);
     try
     {
         dbMinutia.LateralityCode = (FHIRUtilities.LateralitySnoMedCode)Int32.Parse(_lateralityCode);
         dbMinutia.CaptureSite    = (FHIRUtilities.CaptureSiteSnoMedCode)Int32.Parse(_captureSiteCode);
     }
     catch { }
     if (!(SetupScanner()))
     {
         if ((_exception == null))
         {
             throw new Exception("Unknown scanner setup error.");
         }
         else
         {
             throw _exception;
         }
     }
 }
コード例 #4
0
 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();
 }
コード例 #5
0
        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();
        }
コード例 #6
0
        public FHIRMessageRouter(HttpContext context)
        {
            try
            {
                if (uint.TryParse(MinimumAcceptedMatchScore, out _minimumAcceptedMatchScore) == false)
                {
                    _minimumAcceptedMatchScore = 30;
                }

                Resource newResource = FHIRUtilities.StreamToFHIR(new StreamReader(context.Request.InputStream));
                switch (newResource.TypeName.ToLower())
                {
                case "patient":
                    //if new patient. TODO: check meta for NoID status
                    SessionQueue seq = new SessionQueue();


                    _patient = (Patient)newResource;
                    string sessionID = "";
                    if (_patient.Identifier.Count > 0)
                    {
                        foreach (Identifier id in _patient.Identifier)
                        {
                            if (id.System.ToString().ToLower().Contains("session") == true)
                            {
                                sessionID = id.Value.ToString();
                            }
                        }
                    }

                    Patient ptSaved = (Patient)SendPatientToSparkServer();
                    if (ptSaved == null)
                    {
                        _responseText = "Error sending Patient FHIR message to the Spark FHIR endpoint. " + ExceptionString;
                        return;
                    }

                    string LocalNoID = ptSaved.Id.ToString();
                    //TODO: make this an atomic transaction.
                    //          delete the FHIR message from Spark if there is an error in the minutia.

                    //TODO check for existing patient and expire old messages for the patient.
                    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.LocalNoID = LocalNoID;
                            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();
                        _responseText = "Successful.";
                    }
                    break;

                case "media":
                    _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
                            _responseText = minutiaResult.NoID;      //TODO: for now, it returns the localNoID.  should return a FHIR response.
                        }
                        else
                        {
                            _responseText = "No local database match.";
                        }
                    }
                    else
                    {
                        _responseText = "No local database match.";
                    }
                    dbMinutia.Dispose();

                    if (!(SendBiometicsToSparkServer()))
                    {
                        _responseText = "Error sending Biometric Media FHIR message to the Spark FHIR endpoint. " + ExceptionString;
                    }
                    break;

                default:
                    _responseText = newResource.TypeName.ToLower() + " not supported.";
                    break;
                }
            }
            catch (Exception ex)
            {
                _responseText = "Error in FHIRMessageRouter::FHIRMessageRouter: " + ex.Message;
            }
        }