Example #1
0
        static void Main(string[] args)
        {
            string commandLine = "";

            Console.WriteLine("Enter C for checkin patient, P for pending patient queue, M for Mongo tests, F for fingerprint identity and Q to quit");
            while (commandLine != "q")
            {
                if (commandLine == "c")
                {
                    // call PatentCheckinUri
                    Console.WriteLine("Sending test patient FHIR message.");
                    Patient testPt = TestPatient();
                    SendJSON(testPt);
                    Console.WriteLine("Sending FHIR message from file.");
                    Patient readPt = ReadPatient(@"C:\JSONTest\sample-new-patient.json");
                    SendJSON(readPt);
                }
                else if (commandLine == "p") //send profiles
                {
                    // call PendingPatientsUri
                    IList <PatientProfile> patientProfiles = GetCheckinList();
                    Console.WriteLine("Patient profiles received.");
                }
                else if (commandLine == "m") // MongoDB tests
                {
                    MongoDBWrapper dbwrapper = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress);
                    SessionQueue   seq       = new SessionQueue();
                    seq._id                 = Guid.NewGuid().ToString();
                    seq.ClinicArea          = "Test Clinic";
                    seq.LocalReference      = "123456";
                    seq.SparkReference      = "spark5";
                    seq.ApprovalStatus      = "pending";
                    seq.PatientStatus       = "new";
                    seq.RemoteHubReference  = "rem440403";
                    seq.SessionComputerName = "Prototype Computer 1";
                    seq.SubmitDate          = DateTime.UtcNow.AddMinutes(-15);
                    seq.PatientBeginDate    = DateTime.UtcNow.AddMinutes(-19);
                    Console.WriteLine(seq.Serialize());
                    dbwrapper.AddPendingPatient(seq);
                    List <SessionQueue> PendingPatients = dbwrapper.GetPendingPatients();
                    dbwrapper.UpdateSessionQueueRecord(seq._id, "approved", "TestUser", "TestComputer");
                }
                else if (commandLine == "f") // test fingerprint identity web service
                {
                    Media readMedia = ReadMedia(@"C:\JSONTest\sample-media-fhir-message.json");
                    SendJSON(readMedia);
                }
                string previousCommand = commandLine;
                commandLine = Console.ReadLine();
                if (commandLine.Length > 0)
                {
                    commandLine = commandLine.ToLower().Substring(0, 1);
                }
                else
                {
                    commandLine = previousCommand;
                }
            }
        }
Example #2
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();
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            try
            {
                foreach (String key in context.Request.QueryString.AllKeys)
                {
                    switch (key.ToLower())
                    {
                    case "localnoid":
                        _localNoID = context.Request.QueryString[key];
                        break;

                    case "fieldname":
                        _confirmFieldName = context.Request.QueryString[key];
                        break;

                    case "confirmreponse":
                        _confirmReponse = context.Request.QueryString[key];
                        break;

                    case "computername":
                        _computerName = context.Request.QueryString[key];
                        break;

                    case "clinicarea":
                        _clinicArea = context.Request.QueryString[key];
                        break;
                    }
                }
                MongoDBWrapper dbwrapper      = new MongoDBWrapper(NoIDMongoDBAddress, SparkMongoDBAddress);
                FhirClient     client         = new FhirClient(sparkEndpointAddress);
                string         sparkReference = dbwrapper.GetSparkID(_localNoID);
                string         sparkAddress   = sparkEndpointAddress.ToString() + "/Patient/" + sparkReference;
                Patient        pendingPatient = (Patient)client.Get(sparkAddress);
                if (pendingPatient != null)
                {
                    if (_confirmFieldName == "birthdate")
                    {
                        if (pendingPatient.BirthDate != null && _confirmReponse == pendingPatient.BirthDate)
                        {
                            SessionQueue seq = Utilities.PatientToSessionQueue(pendingPatient, sparkReference, _localNoID, "return", "pending");
                            seq.SubmitDate          = DateTime.UtcNow;
                            seq._id                 = StringUtilities.SHA256(DomainName + Guid.NewGuid().ToString() + NodeSalt);
                            seq.SessionComputerName = _computerName;
                            seq.ClinicArea          = _clinicArea;
                            dbwrapper.AddPendingPatient(seq);
                            context.Response.Write("yes");
                        }
                        else
                        {
                            context.Response.Write("no");
                        }
                    }
                    else if (_confirmFieldName == "lastname")
                    {
                        //TODO: implement lastname, use metaphone or just accept exact matches?
                        context.Response.Write("Error occurred.  " + _confirmFieldName + " is not implemented yet!");
                    }
                    else if (_confirmFieldName == "firstname")
                    {
                        //TODO: implement firstname, use root or just accept exact matches?
                        context.Response.Write("Error occurred.  " + _confirmFieldName + " is not implemented yet!");
                    }
                    else if (_confirmFieldName == "failedchallenge")
                    {
                        SessionQueue seq = Utilities.PatientToSessionQueue(pendingPatient, sparkReference, _localNoID, "return**", "pending");
                        seq.SubmitDate          = DateTime.UtcNow;
                        seq._id                 = StringUtilities.SHA256(DomainName + Guid.NewGuid().ToString() + NodeSalt);
                        seq.SessionComputerName = _computerName;
                        seq.ClinicArea          = _clinicArea;
                        dbwrapper.AddPendingPatient(seq);
                        context.Response.Write("yes");
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write("no. Error occured for LocalNoID = " + _localNoID + ".  UpdatePendingStatus::ProcessRequest: " + ex.Message);
            }
            context.Response.End();
        }