Exemplo n.º 1
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();
 }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        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.");
            }
        }