public void ExtractCDAPackageWithCheck()
        {
            CDAPackage newPackage;
            string     message = "";

            // Extract the contents of a CDA package file and validate ths signature
            try
            {
                // Signature is verified on this call, with an exception thrown if the validation fails
                newPackage = CDAPackageUtility.Extract("CdaPackageFilePath.zip", VerifyCertificate);
            }
            catch (Exception ex)
            {
                // If exception thrown due to failed signature validation, capture the reason.
                // We recommend displaying the error to the user and continue to render the document.
                // This way the user can make a judgement call on whether or not to trust the
                // information contained within the document.
                message = ex.Message;
                // No Signature validation checked to allow user to view package still
                newPackage = CDAPackageUtility.Extract("CdaPackageFilePath.zip", null);
            }

            // Get CDA document content
            byte[] cdaRoodDocumentContent = newPackage.CDADocumentRoot.FileContent;

            // Get attachments if they exist
            if (newPackage.CDADocumentAttachments.Count == 2)
            {
                byte[] attachment1 = newPackage.CDADocumentAttachments[0].FileContent;
                string fileName1   = newPackage.CDADocumentAttachments[0].FileName;

                byte[] attachment2 = newPackage.CDADocumentAttachments[1].FileContent;
                string fileName2   = newPackage.CDADocumentAttachments[1].FileName;
            }
        }
Пример #2
0
        public void CreateCDAPackage()
        {
            // ------------------------------------------------------------------------------
            // Set up signing certificate and identifiers
            // ------------------------------------------------------------------------------

            // Load certificate used to sign the CDA document
            X509Certificate2 signingCert = X509CertificateUtil.GetCertificate(
                "Signing Certificate Find Value",
                X509FindType.FindBySubjectName,
                StoreName.My,
                StoreLocation.CurrentUser,
                true);

            // ------------------------------------------------------------------------------
            // Create CDAPackage
            // ------------------------------------------------------------------------------

            // Create an approver
            var approver = new Approver()
            {
                PersonId         = new Uri("http://ns.electronichealth.net.au/id/hi/hpii/1.0/8003610000000000"),
                PersonFamilyName = "Jacobs",
                PersonGivenNames = new List <string> {
                    "Adam", "Barry"
                },
                PersonNameSuffixes = new List <string> {
                    "MD", "JR"
                },
                PersonTitles = new List <string> {
                    "MR", "DR"
                }
            };

            // Create a CDAPackage instance
            var package = new CDAPackage(approver);

            // Create the CDA root document for the CDA package
            package.CreateRootDocument(File.ReadAllBytes("CdaDocumentXmlFile.xml"));

            // Add an image attachment
            package.AddDocumentAttachment(
                "ImageAttachment1.jpg",
                File.ReadAllBytes("ImageAttachment1.jpg")
                );

            // Add another image attachment
            package.AddDocumentAttachment(
                "ImageAttachment2.png",
                File.ReadAllBytes("ImageAttachment2.png")
                );

            // Create the CDA package zip
            CDAPackageUtility.CreateZip(package, "CdaPackageOutputFilePath.zip", signingCert);
        }
Пример #3
0
        /// <summary>
        /// Extract the package data.
        /// </summary>
        /// <param name="cdaPackageData"></param>
        /// <returns></returns>
        public CdaPackageData ExtractPackageData(byte[] cdaPackageData)
        {
            // NOTE will throw a validation exception if the signature is not valid
            CDAPackage cdaPackage = CDAPackageUtility.Extract(cdaPackageData, certificate =>
            {
                // NO-OP assume the certificate is valid
            });

            // Load the document
            XmlDocument cdaDocument = GetCdaDocumentFromPackage(cdaPackage);

            // Extract the package data
            return(ExtractPackageData(cdaDocument));
        }
        public void ExtractCDAPackage()
        {
            // Extract the contents of a CDA package file
            // Signature is verified on this call, with an exception thrown if the validation fails
            var newPackage = CDAPackageUtility.Extract(
                "CdaPackageFilePath.zip",
                VerifyCertificate
                );

            // Get CDA document content
            byte[] cdaRoodDocumentContent = newPackage.CDADocumentRoot.FileContent;

            // Get attachments if they exist
            if (newPackage.CDADocumentAttachments.Count == 2)
            {
                byte[] attachment1 = newPackage.CDADocumentAttachments[0].FileContent;
                string fileName1   = newPackage.CDADocumentAttachments[0].FileName;

                byte[] attachment2 = newPackage.CDADocumentAttachments[1].FileContent;
                string fileName2   = newPackage.CDADocumentAttachments[1].FileName;
            }
        }
Пример #5
0
        public void Process(PackagerInput Input)
        {
            // ------------------------------------------------------------------------------
            // Set up signing certificate and identifiers
            // ------------------------------------------------------------------------------

            // Load certificate used to sign the CDA document
            X509Certificate2 signingCert = X509CertificateUtil.GetCertificate(
                Input.NashCertificateSerial,
                X509FindType.FindBySerialNumber,
                StoreName.My,
                StoreLocation.CurrentUser,
                true);

            // ------------------------------------------------------------------------------
            // Create CDAPackage
            // ------------------------------------------------------------------------------

            // Create an approver
            var approver = new Approver()
            {
                PersonId         = new Uri($"http://ns.electronichealth.net.au/id/hi/hpii/1.0/{Input.Approver.Hpii}"),
                PersonFamilyName = Input.Approver.FamilyName,
                PersonGivenNames = new List <string> {
                    Input.Approver.GivenName
                },
                //PersonNameSuffixes = new List<string> { Input.Approver },
                PersonTitles = new List <string> {
                    Input.Approver.Title
                }
            };

            // Create a CDAPackage instance
            var package = new Nehta.VendorLibrary.CDAPackage.CDAPackage(approver);

            if (!File.Exists(Input.CdaDocumentInputFilePath))
            {
                throw new ApplicationException($"Unable to locate the CDA file at file path: {Input.CdaDocumentInputFilePath}");
            }
            // Create the CDA root document for the CDA package
            package.CreateRootDocument(File.ReadAllBytes(Input.CdaDocumentInputFilePath));

            //Add the PDF report attachment
            var PdfAtachmentFileInfo = new FileInfo(Input.PdfReportAttachment);

            if (!PdfAtachmentFileInfo.Exists)
            {
                throw new ApplicationException($"Unable to locate attachment file at file path: {Input.PdfReportAttachment}");
            }
            package.AddDocumentAttachment("attachment.pdf", File.ReadAllBytes(Input.PdfReportAttachment));

            //Add the logo image attachment
            package.AddDocumentAttachment("logo.png", Input.CdaDocumentLogoBytes);

            FileInfo CdaDocumentFileinfo = new FileInfo(Input.CdaDocumentInputFilePath);

            //string CdaPackageFileName = CdaDocumentFileinfo.Name.Replace(CdaDocumentFileinfo.Extension, ".zip");
            //CdaPackageFileName = Path.Combine(CdaDocumentFileinfo.DirectoryName, CdaPackageFileName);
            // Create the CDA package zip
            CDAPackageUtility.CreateZip(package, Input.CdaPackageOutputFilePath, signingCert);

            //Delete the raw CDA xml file
            //CdaDocumentFileinfo.Delete();
        }