public void Sample()
        {
            // Obtain the certificate for use with TLS and signing
            X509Certificate2 cert = X509CertificateUtil.GetCertificate(
                "Serial Number",
                X509FindType.FindBySerialNumber,
                StoreName.My,
                StoreLocation.CurrentUser,
                true
                );

            // Create PCEHR header
            CommonPcehrHeader header = PcehrHeaderHelper.CreateHeader();

            // Override this value to the current patient's IHI.
            header.IhiNumber = "IHI";

            // Create the client
            // SVT endpoint is https://b2b.ehealthvendortest.health.gov.au/uploadDocument
            // production endpoint is https://services.ehealth.gov.au/uploadDocument
            UploadDocumentClient uploadDocumentClient = new UploadDocumentClient(
                new Uri("https://UploadDocumentEndpoint"), cert, cert);

            // Add server certificate validation callback
            ServicePointManager.ServerCertificateValidationCallback += ValidateServiceCertificate;

            byte[] packageBytes = File.ReadAllBytes("CdaPackage.zip"); // Create a package

            // Create a request to register a new document on the PCEHR.
            // Create a request to register a new document on the PCEHR.
            // Format codes and format code names are not fixed, and it is recommended for them to be configurable.
            // formatCode is the Template Package ID for each clinical document, formatCodeName is the Document type
            // please find specific details for each clinical document type on https://digitalhealth.gov.au/implementation-resources/clinical-documents
            // formatCodeName can be read in Table 3 of the Document Exchange Service Technical Service Specification
            // For example (formateCodeName - formatCode):
            // "eHealth Dispense Record" - 1.2.36.1.2001.1006.1.171.5
            // "Pathology Report" - 1.2.36.1.2001.1006.1.220.4
            // "Diagnostic Imaging Report" - 1.2.36.1.2001.1006.1.222.4
            ProvideAndRegisterDocumentSetRequestType request = uploadDocumentClient.CreateRequestForNewDocument(
                packageBytes,
                "formatCode",
                "formatCodeName",
                HealthcareFacilityTypeCodes.GeneralPractice,                // Update to relevant code
                PracticeSettingTypes.GeneralPracticeMedicalClinicService    // Update to relevant code
                );

            // To supercede / amend an existing document, the same UploadDocument call is used. However, the request is
            // prepared using the CreateRequestForReplacement function.

            // Note that the new document must have a different UUID/GUID to the one it is replacing.
            // the uuidOfDocumentToReplace must be converted to OID format and include the repository OID.
            // (i.e. a document being replaced in the My Health Record repository is)

            // ProvideAndRegisterDocumentSetRequestType request = uploadDocumentClient.CreateRequestForReplacement(
            //    packageBytes,
            //    "formatCode",
            //    "formatCodeName",
            //    HealthcareFacilityTypeCodes.GeneralPractice,
            //    PracticeSettingTypes.GeneralPracticeMedicalClinicService,
            //    "uuidOfDocumentToReplace"
            //    );

            // When uploading to the NPDR where the repository unique ID, document size and hash may need to be included
            // in the metadata, use the utility function below.

            // uploadDocumentClient.AddRepositoryIdAndCalculateHashAndSize(request, "REPOSITORY_UNIQUE_ID");

            try
            {
                // Invoke the service
                RegistryResponseType registryResponse = uploadDocumentClient.UploadDocument(header, request);

                // Get the soap request and response
                string soapRequest  = uploadDocumentClient.SoapMessages.SoapRequest;
                string soapResponse = uploadDocumentClient.SoapMessages.SoapResponse;
            }
            catch (FaultException fex)
            {
                // Handle any errors
            }
        }
Пример #2
0
        public void Upload()
        {
            //Get Certificate and Header objects
            CertAndHeaderInfo CertAndHeaderInfo = Support.CertAndHeaderFactory.Get(
                certSerial: "06fba6",
                serialHPIO: "8003629900019338",
                patientType: Support.PatientType.CalebDerrington);

            // Obtain the certificate for use with TLS and signing
            X509Certificate2 cert = CertAndHeaderInfo.Certificate;

            // Create PCEHR header
            CommonPcehrHeader header = CertAndHeaderInfo.Header;

            // Create the client
            // SVT endpoint is https://b2b.ehealthvendortest.health.gov.au/uploadDocument
            // production endpoint is https://services.ehealth.gov.au/uploadDocument
            UploadDocumentClient uploadDocumentClient = new UploadDocumentClient(
                new Uri("https://b2b.ehealthvendortest.health.gov.au/uploadDocument"), cert, cert);

            // Add server certificate validation callback
            ServicePointManager.ServerCertificateValidationCallback += Support.CertificateHelper.ValidateServiceCertificate;

            byte[] packageBytes = File.ReadAllBytes(@"C:\temp\MyHealthRecordTools\CDAPackager\Output\LastOutputRun\CdaPackage.zip"); // Create a package

            // Create a request to register a new document on the PCEHR.
            // Create a request to register a new document on the PCEHR.
            // Format codes and format code names are not fixed, and it is recommended for them to be configurable.
            // formatCode is the Template Package ID for each clinical document, formatCodeName is the Document type
            // please find specific details for each clinical document type on https://digitalhealth.gov.au/implementation-resources/clinical-documents
            // formatCodeName can be read in Table 3 of the Document Exchange Service Technical Service Specification
            // For example (formateCodeName - formatCode):
            // "eHealth Dispense Record" - 1.2.36.1.2001.1006.1.171.5
            // "Pathology Report" - 1.2.36.1.2001.1006.1.220.4
            // "Diagnostic Imaging Report" - 1.2.36.1.2001.1006.1.222.4
            // "Discharge Summary" - 1.2.36.1.2001.1006.1.20000.18
            // "eHealth Dispense Record" - 1.2.36.1.2001.1006.1.171.4
            // "Goals of Care" - 1.2.36.1.2001.1006.1.100001.1
            // "Event Summary" - 1.2.36.1.2001.1006.1.16473.12
            ProvideAndRegisterDocumentSetRequestType request = uploadDocumentClient.CreateRequestForNewDocument(
                packageBytes,
                "1.2.36.1.2001.1006.1.16473.12",
                "Event Summary",
                //You must chooose a valid type below
                HealthcareFacilityTypeCodes.Hospitals,
                PracticeSettingTypes.GeneralHospital
                );

            // To supercede / amend an existing document, the same UploadDocument call is used. However, the request is
            // prepared using the CreateRequestForReplacement function.

            // Note that the new document must have a different UUID/GUID to the one it is replacing.
            // the uuidOfDocumentToReplace must be converted to OID format and include the repository OID.
            // (i.e. a document being replaced in the My Health Record repository is)

            //ProvideAndRegisterDocumentSetRequestType request = uploadDocumentClient.CreateRequestForReplacement(
            //   packageBytes,
            //   "1.2.36.1.2001.1006.1.220.4",
            //    "Pathology Report",
            //   HealthcareFacilityTypeCodes.Hospitals,
            //   PracticeSettingTypes.GeneralHospital,
            //   "2.25.311256170906902265756795034001543718058" //Document Id of doc to replace
            //   );

            // When uploading to the NPDR where the repository unique ID, document size and hash may need to be included
            // in the metadata, use the utility function below.

            // uploadDocumentClient.AddRepositoryIdAndCalculateHashAndSize(request, "REPOSITORY_UNIQUE_ID");

            try
            {
                // Invoke the service
                RegistryResponseType registryResponse = uploadDocumentClient.UploadDocument(header, request);

                // Get the soap request and response
                string soapRequest  = uploadDocumentClient.SoapMessages.SoapRequest;
                string soapResponse = uploadDocumentClient.SoapMessages.SoapResponse;
            }
            catch (FaultException fex)
            {
                // Handle any errors
            }
        }
Пример #3
0
        /// <summary>
        /// Uploads a document.
        /// </summary>
        /// <param name="documentUploadRequest"></param>
        /// <returns></returns>
        public async Task <DocumentUploadResult> UploadDocument(DocumentUploadRequest documentUploadRequest)
        {
            // Validate the request
            await _documentUploadRequestValidator.ValidateAndThrowAsync(documentUploadRequest);

            Log.Debug("Uploading to endpoint '{endpoint}' with '{certificate}'", _endpoint, _certificate.Subject);

            // Create the client
            var uploadDocumentClient = new UploadDocumentClient(new Uri(_endpoint), _certificate, _certificate);

            DocumentUploadResult documentUploadResult;

            try
            {
                // Create the request
                ProvideAndRegisterDocumentSetRequestType provideAndRegisterDocumentSetRequest;
                if (!string.IsNullOrWhiteSpace(documentUploadRequest.ReplaceDocumentId))
                {
                    // Replace request
                    provideAndRegisterDocumentSetRequest = uploadDocumentClient.CreateRequestForReplacement(
                        documentUploadRequest.DocumentData,
                        documentUploadRequest.FormatCode,
                        documentUploadRequest.FormatCodeName,
                        _facilityType,
                        _practiceSetting,
                        documentUploadRequest.ReplaceDocumentId);
                }
                else
                {
                    // New document request
                    provideAndRegisterDocumentSetRequest = uploadDocumentClient.CreateRequestForNewDocument(
                        documentUploadRequest.DocumentData,
                        documentUploadRequest.FormatCode,
                        documentUploadRequest.FormatCodeName,
                        _facilityType,
                        _practiceSetting);
                }

                if (Log.IsEnabled(LogEventLevel.Verbose))
                {
                    Log.Verbose("Upload request '{requestJson}'", JsonConvert.SerializeObject(provideAndRegisterDocumentSetRequest));
                }

                // Create the PCEHR header
                CommonPcehrHeader commonPcehrHeader = CreateCommonPcehrHeader(provideAndRegisterDocumentSetRequest.SubmitObjectsRequest);

                if (Log.IsEnabled(LogEventLevel.Verbose))
                {
                    Log.Verbose("PCEHR header {header}", JsonConvert.SerializeObject(commonPcehrHeader));
                }

                // Upload the document
                RegistryResponseType registryResponse = uploadDocumentClient.UploadDocument(commonPcehrHeader, provideAndRegisterDocumentSetRequest);

                LogSoapMessages(uploadDocumentClient.SoapMessages);

                if (Log.IsEnabled(LogEventLevel.Verbose))
                {
                    Log.Verbose("Upload response {responseJson}", JsonConvert.SerializeObject(registryResponse));
                }

                // Map the response
                documentUploadResult = DocumentUploadResultMapper.Map(registryResponse);
            }
            catch (Exception e)
            {
                Log.Error(e, "Error uploading document to endpoint '{endpoint}'", _endpoint);

                LogSoapMessages(uploadDocumentClient.SoapMessages);

                throw;
            }
            finally
            {
                uploadDocumentClient.Close();
            }

            return(documentUploadResult);
        }