Question
· Jul 2

Help Needed: Empty Bundle When Converting CCDA to FHIR in InterSystems IRIS

Hello Community,

I'm a beginner and currently working on a project to convert CCDA files to FHIR using InterSystems IRIS. I have developed a web form to upload CCDA files, and I'm attempting to convert the uploaded CCDA files to FHIR. However, I am encountering an issue where the conversion process results in an empty entry.
Here's the Output it displays on HTML page:

Size of CCDA Stream: 74152
vR4
{"resourceType":"Bundle","type":"transaction","entry":[]}

Here is my code: CCDtoFHIR.csp

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CCDA to FHIR Converter</title>
</head>
<body>
    <section>
        <div>
            <p>CCDA to FHIR Converter</p>
            <div>
                <div>
                    <h1>Upload CCDA File</h1>
                    <form id="fileUploadForm" enctype="multipart/form-data" method="post" action="CCDtoFHIR.csp">
                        <div>
                            <label for="file">Upload CCDA File</label>
                            <input type="file" name="file" id="file" required>
                        </div>
                        <div>
                            <button type="submit">Upload</button>
                        </div>
                    </form>
                    <csp:if condition='($data(%request.MimeData("file",1)))'>
                        <hr><br>
                        <b>FHIR Conversion Result:</b><br>
                        <ul>
                            <script language="cache" runat="server">
                                try {
                                    // Read the uploaded file stream
                                    set ccdaStream = ##class(%Stream.TmpBinary).%New()
                                    do ccdaStream.CopyFrom(%request.MimeData("file",1))
                                    
                                    // Ensure the stream is an object
                                    if ('$isobject(ccdaStream)) {
                                        write "Failed to read uploaded file stream"
                                        quit
                                    }
                                    
                                    // Debug: Output the size of the CCDA stream
                                    write "Size of CCDA Stream: ", ccdaStream.Size, "<br>"
                                    
                                    // Read some content from the stream for debugging
                                    do ccdaStream.Rewind()

                                    // Determine the appropriate XSLT transform based on the document type
                                    set xsltTransform = "SDA3/CCDA-to-SDA.xsl"  // Default to CCDA-to-SDA
                                    
                                    // Convert CCDA to SDA3 using HealthShare's built-in methods
                                    set tTransformer = ##class(HS.Util.XSLTTransformer).%New()
                                    set tSC = tTransformer.Transform(ccdaStream, xsltTransform, .tSDA3Stream)

                                    if $$$ISERR(tSC) {
                                        write "Transformation to SDA3 failed", "<br>"
                                        quit
                                    }
                                    
                                    set sdaStream = ##class(%Stream.TmpBinary).%New()
                                    do tSDA3Stream.Rewind()
                                    do sdaStream.CopyFrom(tSDA3Stream)
                                    
                                    // Convert SDA3 to FHIR using HealthShare's built-in methods
                                    set fhirStream = ##class(%Stream.TmpBinary).%New()
                                    set SDA3ToFHIRObject = ##class(HS.FHIR.DTL.Util.API.Transform.SDA3ToFHIR).TransformStream(tSDA3Stream, "HS.SDA3.Container", "R4")

                                    // Check if the transformation returned a valid bundle
                                    if '$isobject(SDA3ToFHIRObject.bundle) {
                                        write "Failed to transform SDA3 to FHIR", "<br>"
                                        quit
                                    }

                                    // Serialize the FHIR bundle to JSON
                                    do SDA3ToFHIRObject.bundle.%ToJSON(fhirStream)
                                    do fhirStream.Rewind()

                                    // Write the FHIR data to the response
                                    while ('fhirStream.AtEnd) {
                                        write fhirStream.ReadLine(), "<br>"
                                    }
                                } catch (ex) {
                                    // Handle exceptions
                                    write "Error during conversion: ", ex.DisplayString(), "<br>"
                                }
                            </script>
                        </ul>
                    </csp:if>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

 

Problem Description:

  • The CCDA file uploads successfully, and I can see the size of the uploaded stream.
  • The transformation to SDA3 seems to work fine without errors.
  • The conversion from SDA3 to FHIR appears to be successful, but the resulting FHIR bundle is empty.

Debugging Steps:

  • I've ensured that the CCDA stream is read correctly.
  • I confirmed that the transformation to SDA3 does not produce any errors.
  • I attempted to output some content from the SDA3 stream, which seems fine.
  • The FHIR transformation does not produce any errors, but the resulting FHIR bundle is empty.

Questions:

  1. What could be the reason for obtaining an empty FHIR bundle after the transformation?
  2. Are there any additional debugging steps or checks I can perform to identify the issue?
  3. Is there a specific configuration or additional steps required for the HS.FHIR.DTL.Util.API.Transform.SDA3ToFHIR transformation process?
Product version: IRIS 2022.2
Discussion (9)2
Log in or sign up to continue

Using your code (simplified by me) from terminal it works fine using a sample CCDA from here.

set ccdaStream = ##class(%Stream.FileBinary).%OpenId("c:\temp\CCDA_CCD_b1_Ambulatory_v2.xml")
write "Size of CCDA Stream: ", ccdaStream.Size,!
set xsltTransform = "SDA3/CCDA-to-SDA.xsl"
set tTransformer = ##class(HS.Util.XSLTTransformer).%New()
set tSC = tTransformer.Transform(ccdaStream, xsltTransform, .sdaStream)
if 'tSC write "Transformation to SDA3 failed with error ",$system.Status.GetErrorText(tSC),!
set fhirStream = ##class(%Stream.TmpBinary).%New()
set SDA3ToFHIRObject = ##class(HS.FHIR.DTL.Util.API.Transform.SDA3ToFHIR).TransformStream(sdaStream, "HS.SDA3.Container", "R4")
if '$isobject(SDA3ToFHIRObject.bundle) write "Failed to transform SDA3 to FHIR",!
do SDA3ToFHIRObject.bundle.%ToJSON()

The result/output is a pretty long JSON FHIR bundle with CCDA data (I didn't check the content!)

Does your code works with that sample CCDA?

If not, then maybe there is something wrong in your CCDA.

For my test I used: IRIS for Windows (x86-64) 2024.1 (Build 267_2U) Tue Apr 30 2024 16:35:10 EDT

I am using studio's terminal to run the code.

set ccdaStream = ##class(%Stream.FileBinary).%OpenId("/tmp/CCDA_CCD_b1_Ambulatory_v2.xml")

write "Size of CCDA Stream: ", ccdaStream.Size,!
Size of CCDA Stream: 171823
set xsltTransform = "SDA3/CCDA-to-SDA.xsl"
set tTransformer = ##class(HS.Util.XSLTTransformer).%New()

set tSC = tTransformer.Transform(ccdaStream, xsltTransform, .sdaStream)

if 'tSC write "Transformation to SDA3 failed with error ",$system.Status.GetErrorText(tSC),!

set fhirStream = ##class(%Stream.TmpBinary).%New()

set SDA3ToFHIRObject = ##class(HS.FHIR.DTL.Util.API.Transform.SDA3ToFHIR).TransformStream(sdaStream, "HS.SDA3.Container", "R4")

if '$isobject(SDA3ToFHIRObject.bundle) write "Failed to transform SDA3 to FHIR",!

do SDA3ToFHIRObject.bundle.%ToJSON()
{"resourceType":"Bundle","type":"transaction","entry":[]}