/// <summary>
        /// This sample populates both the mandatory and optional Sections / Entries depending on the
        /// mandatorySectionsOnly Boolean
        /// </summary>
        internal static DiagnosticImagingReport PopulatedDiagnosticImagingReport(Boolean mandatorySectionsOnly)
        {
            var diagnosticImagingReport = DiagnosticImagingReport.CreateDiagnosticImagingReport();

            // Include Logo
            diagnosticImagingReport.IncludeLogo = true;
            diagnosticImagingReport.LogoPath    = OutputFolderPath;

            // Set Creation Time
            diagnosticImagingReport.DocumentCreationTime = new ISO8601DateTime(DateTime.Now);

            #region Setup and populate the CDA context model

            // Setup and populate the CDA context model
            var cdaContext = DiagnosticImagingReport.CreateCDAContext();
            // Document Id
            cdaContext.DocumentId = BaseCDAModel.CreateIdentifier(BaseCDAModel.CreateOid());
            // Set Id
            cdaContext.SetId = BaseCDAModel.CreateIdentifier(BaseCDAModel.CreateGuid());
            // CDA Context Version
            cdaContext.Version = "1";

            // Custodian
            cdaContext.Custodian = BaseCDAModel.CreateCustodian();
            GenericObjectReuseSample.HydrateCustodian(cdaContext.Custodian, "Queensland Diagnostic Services", mandatorySectionsOnly);

            // Legal Authenticator
            cdaContext.LegalAuthenticator = BaseCDAModel.CreateLegalAuthenticator();
            GenericObjectReuseSample.HydrateAuthenticator(cdaContext.LegalAuthenticator, mandatorySectionsOnly);

            diagnosticImagingReport.CDAContext = cdaContext;

            #endregion

            #region Setup and Populate the SCS Context model
            // Setup and Populate the SCS Context model

            diagnosticImagingReport.SCSContext = DiagnosticImagingReport.CreateSCSContext();

            // Reporting Radiologist
            diagnosticImagingReport.SCSContext.ReportingRadiologist = CreateReportingRadiologist(mandatorySectionsOnly);

            // Order Details
            diagnosticImagingReport.SCSContext.OrderDetails = CreateOrderDetails(mandatorySectionsOnly);

            // Author Health Care Provider
            diagnosticImagingReport.SCSContext.Author = BaseCDAModel.CreateAuthorHealthcareProvider();
            GenericObjectReuseSample.HydrateAuthorHealthcareProvider(diagnosticImagingReport.SCSContext.Author, "Queensland Diagnostic Services", mandatorySectionsOnly);

            // Subject Of Care
            diagnosticImagingReport.SCSContext.SubjectOfCare = BaseCDAModel.CreateSubjectOfCare();
            GenericObjectReuseSample.HydrateSubjectofCare(diagnosticImagingReport.SCSContext.SubjectOfCare, mandatorySectionsOnly);

            #endregion

            #region Setup and populate the SCS Content model

            // Setup and populate the SCS Content model
            diagnosticImagingReport.SCSContent = DiagnosticImagingReport.CreateSCSContent();

            // Imaging Examination Results
            diagnosticImagingReport.SCSContent.ImagingExaminationResults = new List <IDiagnosticImagingExaminationResult>
            {
                CreateDiagnosticImagingResults(mandatorySectionsOnly, true),
                CreateDiagnosticImagingResults(mandatorySectionsOnly, false)
            };

            // Related Information
            diagnosticImagingReport.SCSContent.RelatedDocument = CreateRelatedDocument(mandatorySectionsOnly);

            #endregion

            return(diagnosticImagingReport);
        }
        /// <summary>
        /// Create a DiagnosticImagingTransformResult instance (containing a DiagnosticImagingReport and a ReportAttachment instance) from a
        /// HL7 V2 diagnostic imaging message. The DiagnosticImagingTransformResult instance is then used to generate a CDA document.
        /// </summary>
        /// <param name="hl7GenericMessage">The HL7 V2 message to transform.</param>
        /// <param name="metadata">Mandatory information to supplement the transform.</param>
        /// <param name="reportData">Report data.</param>
        /// <returns></returns>
        internal DiagnosticImagingTransformResult Transform(HL7GenericMessage hl7GenericMessage, DiagnosticImagingMetadata metadata, byte[] reportData = null)
        {
            DiagnosticImagingReport diagnosticImagingReport = DiagnosticImagingReport.CreateDiagnosticImagingReport();

            // Include Logo
            diagnosticImagingReport.IncludeLogo = false;

            // Set Creation Time
            diagnosticImagingReport.DocumentCreationTime = GetResultsReportStatusChange(hl7GenericMessage);

            // Document Status
            diagnosticImagingReport.DocumentStatus = GetReportStatus(hl7GenericMessage);

            #region Setup and populate the CDA context model

            // CDA Context model
            var cdaContext = DiagnosticImagingReport.CreateCDAContext();

            // Document Id
            cdaContext.DocumentId = BaseCDAModel.CreateIdentifier(BaseCDAModel.CreateOid(), null);

            // Set Id
            cdaContext.SetId = BaseCDAModel.CreateIdentifier(BaseCDAModel.CreateGuid(), null);

            // CDA Context Version
            cdaContext.Version = "1";

            // Legal Authenticator
            cdaContext.LegalAuthenticator = CreateLegalAuthenticator(hl7GenericMessage);

            // Custodian
            cdaContext.Custodian = BaseCDAModel.CreateCustodian();
            ICustodian custodian = BaseCDAModel.CreateParticipantCustodian();
            cdaContext.Custodian.Participant = custodian;

            diagnosticImagingReport.CDAContext = cdaContext;

            #endregion

            #region Setup and Populate the SCS Context model

            // SCS Context model
            diagnosticImagingReport.SCSContext = DiagnosticImagingReport.CreateSCSContext();

            // Author Health Care Provider
            diagnosticImagingReport.SCSContext.Author = CreateAuthor(hl7GenericMessage);

            // The Reporting Radiologist
            diagnosticImagingReport.SCSContext.ReportingRadiologist = CreateReportingRadiologist(hl7GenericMessage);

            // Order Details
            diagnosticImagingReport.SCSContext.OrderDetails = CreateOrderDetails(hl7GenericMessage);

            // Subject Of Care
            diagnosticImagingReport.SCSContext.SubjectOfCare = CreateSubjectOfCare(hl7GenericMessage);

            #endregion

            #region Setup and populate the SCS Content model

            // SCS Content model
            diagnosticImagingReport.SCSContent = DiagnosticImagingReport.CreateSCSContent();

            ReportAttachment reportAttachment = GetReportAttachment(hl7GenericMessage, reportData);

            // Imaging Examination Results
            diagnosticImagingReport.SCSContent.ImagingExaminationResults = CreateImagingExaminationResults(hl7GenericMessage);

            // Related Document
            diagnosticImagingReport.SCSContent.RelatedDocument = CreateRelatedDocument(hl7GenericMessage, reportAttachment);

            #endregion

            FillInAdditionalMetadata(diagnosticImagingReport, metadata);

            return(new DiagnosticImagingTransformResult
            {
                DiagnosticImagingReport = diagnosticImagingReport,
                Attachment = reportAttachment
            });
        }