private static void setBodyAndContentType(HttpWebRequest request, Resource data, ResourceFormat format, bool CompressRequestBody, out byte[] body)
        {
            if (data == null)
            {
                throw Error.ArgumentNull(nameof(data));
            }

            if (data is Binary)
            {
                var bin = (Binary)data;
                body = bin.Content;
                // This is done by the caller after the OnBeforeRequest is called so that other properties
                // can be set before the content is committed
                // request.WriteBody(CompressRequestBody, bin.Content);
                request.ContentType = bin.ContentType;
            }
            else
            {
                body = format == ResourceFormat.Xml ?
                       FhirSerializer.SerializeToXmlBytes(data, summary: Fhir.Rest.SummaryType.False) :
                       FhirSerializer.SerializeToJsonBytes(data, summary: Fhir.Rest.SummaryType.False);

                // This is done by the caller after the OnBeforeRequest is called so that other properties
                // can be set before the content is committed
                // request.WriteBody(CompressRequestBody, body);
                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }
Example #2
0
        private static void SetBodyAndContentType(HttpWebRequest request, Resource payload, ResourceFormat format, bool CompressRequestBody, out byte[] body)
        {
            if (payload == null)
            {
                throw Error.ArgumentNull(nameof(payload));
            }

            if (payload is Binary)
            {
                var bin = (Binary)payload;
                body = bin.Content;
                request.ContentType = bin.ContentType;
            }
            else
            {
                body = format == ResourceFormat.Xml ?
                       FhirSerializer.SerializeToXmlBytes(payload, summary: Hl7.Fhir.Rest.SummaryType.False) :
                       FhirSerializer.SerializeToJsonBytes(payload, summary: Hl7.Fhir.Rest.SummaryType.False);

                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }
        private static void setBodyAndContentType(HttpWebRequest request, Resource data, ResourceFormat format)
        {
            if (data == null)
            {
                throw Error.ArgumentNull("data");
            }

            if (data is Binary)
            {
                var bin = (Binary)data;
                request.WriteBody(bin.Content);
                request.ContentType = bin.ContentType;
            }
            else
            {
                var body = format == ResourceFormat.Xml ?
                           FhirSerializer.SerializeToXmlBytes(data, summary: false) :
                           FhirSerializer.SerializeToJsonBytes(data, summary: false);

                request.WriteBody(body);
                request.ContentType = Hl7.Fhir.Rest.ContentType.BuildContentType(format, forBundle: false);
            }
        }
Example #4
0
        public static Patient CreateTestFHIRPatientProfile()
        {
            Patient    pt = new Patient();
            Identifier idSession;
            Identifier idPatientCertificate;

            idSession        = new Identifier();
            idSession.System = "http://www.mynoid.com/fhir/SessionID";
            idSession.Value  = "S12348";
            pt.Identifier.Add(idSession);

            idPatientCertificate        = new Identifier();
            idPatientCertificate.System = "http://www.mynoid.com/fhir/PatientCertificateID";
            idPatientCertificate.Value  = "PT67891";
            pt.Identifier.Add(idPatientCertificate);

            ResourceReference managingOrganization = new ResourceReference(NoID_OID, "Test NoID");

            pt.ManagingOrganization = managingOrganization;

            pt.Language      = "English";
            pt.BirthDate     = "2006-07-03";
            pt.Gender        = AdministrativeGender.Female;
            pt.MultipleBirth = new FhirString("No");
            // Add patient name
            HumanName ptName = new HumanName();

            ptName.Given  = new string[] { "Mary", "J" };
            ptName.Family = "Bling";
            pt.Name       = new List <HumanName> {
                ptName
            };
            // Add patient address
            Address address = new Address();

            address.Line       = new string[] { "300 Exit St", "Unit 5" };
            address.City       = "New Orleans";
            address.State      = "LA";
            address.Country    = "USA";
            address.PostalCode = "70112-1202";
            pt.Address.Add(address);
            Attachment attach = new Attachment();
            Media      media  = new Media();

            media.AddExtension("Healthcare Node", FHIRUtilities.OrganizationExtension("Test NoID FHIR Message", "noidtest.net", "devtest.noidtest.net"));
            media.AddExtension("Biometic Capture", FHIRUtilities.CaptureSiteExtension(
                                   CaptureSiteSnoMedCode.IndexFinger, LateralitySnoMedCode.Left, "Test Scanner Device", 500, 350, 290));
            Extension extFingerPrintMedia = FHIRUtilities.FingerPrintMediaExtension(
                "123",
                "211",
                "43",
                "0"
                );

            media.Extension.Add(extFingerPrintMedia);

            extFingerPrintMedia = FHIRUtilities.FingerPrintMediaExtension(
                "180",
                "91",
                "211",
                "1"
                );

            media.Extension.Add(extFingerPrintMedia);

            extFingerPrintMedia = FHIRUtilities.FingerPrintMediaExtension(
                "201",
                "154",
                "44",
                "1"
                );

            media.Extension.Add(extFingerPrintMedia);

            extFingerPrintMedia = FHIRUtilities.FingerPrintMediaExtension(
                "21",
                "279",
                "310",
                "0"
                );

            media.Extension.Add(extFingerPrintMedia);


            attach.Data = FhirSerializer.SerializeToJsonBytes(media, summary: Hl7.Fhir.Rest.SummaryType.False);

            pt.Photo.Add(attach);

            return(pt);
        }
Example #5
0
        public Patient CreateFHIRPatientProfile()
        {
            Patient pt;

            try
            {
                /*
                 *
                 * _patientFHIRProfile.NoIDHubPassword = password;
                 * _patientFHIRProfile.NoIDHubName = patientHub;
                 * _patientFHIRProfile.GenderChangeFlag = genderChangeFlag;
                 *
                 */
                pt = new Patient();

                BiometricsCaptured = GetBiometricsCaptured();
                // Add message status New, Return or Update
                Meta meta = new Meta();

                meta.Extension.Add(FHIRUtilities.MessageTypeExtension(NoIDStatus, NoIDType, CheckinDateTime));
                meta.Extension.Add(FHIRUtilities.ClinicLocationExtension(ClinicArea, DevicePhysicalLocation));
                if (FingerPrintMinutiasList.Count > 0)
                {
                    meta.Extension.Add(FHIRUtilities.CaptureSummaryExtension(BiometricsCaptured,
                                                                             FingerPrintMinutiasList[0].DeviceName,
                                                                             FingerPrintMinutiasList[0].OriginalDpi,
                                                                             FingerPrintMinutiasList[0].OriginalHeight,
                                                                             FingerPrintMinutiasList[0].OriginalWidth)
                                       );
                }
                meta.Extension.Add(FHIRUtilities.NoIDHubInfo(NoIDHubName, NoIDHubPassword));
                if (GenderChangeFlag.ToLower().Contains("yes") == true || MultipleBirth.ToLower().Contains("no") == false)
                {
                    meta.Extension.Add(FHIRUtilities.GenderAndTwinInfo(GenderChangeFlag, MultipleBirth));
                }

                pt.Meta = meta;

                //TODO: Move fingerprint minutias to Identifier.Extension
                Identifier idSession = new Identifier();
                idSession.System = ServerName + "/fhir/SessionID";
                if (SessionID == null || SessionID.Length == 0)
                {
                    NewSession();
                }
                idSession.Value = SessionID;
                pt.Identifier.Add(idSession);


                if (BiometricExceptionMissingReason.Length > 0)
                {
                    if (SecretQuestion1.Length > 0 && SecretAnswer1.Length > 0 && SecretQuestion2.Length > 0 && SecretAnswer2.Length > 0)
                    {
                        Identifier idBiometricException = new Identifier();
                        idBiometricException.System = ServerName + "/fhir/BiometricException";
                        idBiometricException.Value  = "Biometric Exception Pathway";
                        Extension extBiometricException;
                        extBiometricException = FHIRUtilities.BiometricException(
                            BiometricExceptionMissingReason,
                            SecretQuestion1, SecretAnswer1,
                            SecretQuestion2, SecretAnswer2
                            );
                        idBiometricException.Extension.Add(extBiometricException);
                        pt.Identifier.Add(idBiometricException);
                    }
                    {
                        //throw an error back to the page.
                    }
                }

                ResourceReference managingOrganization = new ResourceReference(OrganizationName, DomainName);
                pt.ManagingOrganization = managingOrganization;

                // Add patient demographics
                pt.Language  = Language;
                pt.BirthDate = BirthDate;
                if (Gender.ToLower() == "f")
                {
                    pt.Gender = AdministrativeGender.Female;
                }
                else if (Gender.ToLower() == "m")
                {
                    pt.Gender = AdministrativeGender.Male;
                }
                else
                {
                    pt.Gender = AdministrativeGender.Unknown;
                }

                if (!(MultipleBirth == null) && MultipleBirth.Length > 0)
                {
                    if (MultipleBirth.ToLower().Substring(0, 2) == "no")
                    {
                        pt.MultipleBirth = new FhirString("No");
                    }
                    else if (MultipleBirth.ToLower() == "yes")
                    {
                        pt.MultipleBirth = new FhirString("Yes");
                    }
                }
                // Add patient name
                HumanName ptName = new HumanName();
                ptName.Given  = new string[] { FirstName, MiddleName };
                ptName.Family = LastName;
                pt.Name       = new List <HumanName> {
                    ptName
                };

                if (StreetAddress.Length > 0 || City.Length > 0 || State.Length > 0 || PostalCode.Length > 0)
                {
                    Address address = new Address(); // Add patient address
                    address.Line       = new string[] { StreetAddress, StreetAddress2 };
                    address.City       = City;
                    address.State      = State;
                    address.Country    = Country;
                    address.PostalCode = PostalCode;
                    pt.Address.Add(address);
                }

                // Add patient contact information (phone numbers and email)
                // TODO: make sure email and phone are valid.
                // Validate phone with UI.
                Patient.ContactComponent contact = new Patient.ContactComponent();
                bool addContact = false;
                if ((EmailAddress != null) && EmailAddress.Length > 0)
                {
                    ContactPoint emailAddress = new ContactPoint(ContactPoint.ContactPointSystem.Email, ContactPoint.ContactPointUse.Home, EmailAddress);
                    contact.Telecom.Add(emailAddress);
                    addContact = true;
                }
                if ((PhoneHome != null) && PhoneHome.Length > 0)
                {
                    ContactPoint phoneHome = new ContactPoint(ContactPoint.ContactPointSystem.Phone, ContactPoint.ContactPointUse.Home, PhoneHome);
                    contact.Telecom.Add(phoneHome);
                    addContact = true;
                }
                if ((PhoneCell != null) && PhoneCell.Length > 0)
                {
                    ContactPoint phoneCell = new ContactPoint(ContactPoint.ContactPointSystem.Phone, ContactPoint.ContactPointUse.Mobile, PhoneCell);
                    contact.Telecom.Add(phoneCell);
                    addContact = true;
                }
                if ((PhoneWork != null) && PhoneWork.Length > 0)
                {
                    ContactPoint phoneWork = new ContactPoint(ContactPoint.ContactPointSystem.Phone, ContactPoint.ContactPointUse.Work, PhoneWork);
                    contact.Telecom.Add(phoneWork);
                    addContact = true;
                }
                if (addContact)
                {
                    pt.Contact.Add(contact);
                }
                //TODO: Change location of minutias in Patient FHIR profile from attached Photo.Extension to Identity.Extension
                foreach (FingerPrintMinutias minutias in FingerPrintMinutiasList)
                {
                    Attachment attach           = new Attachment();
                    Media      fingerprintMedia = FingerPrintFHIRMedia(minutias, minutias.DeviceName, minutias.OriginalDpi, minutias.OriginalHeight, minutias.OriginalWidth);
                    byte[]     mediaBytes       = FhirSerializer.SerializeToJsonBytes(fingerprintMedia, summary: SummaryType.Data);
                    attach.Data = mediaBytes;
                    pt.Photo.Add(attach);
                }
            }
            catch (Exception ex)
            {
                BaseException = new Exception("Error in PatientProfile::CreateFHIRProfile(). Failed to create a new FHIR profile: " + ex.Message);
                return(null);
            }
            return(pt);
        }