Written by

Question Aman · Jul 2, 2024

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><htmllang="en"><head><metacharset="UTF-8"><metaname="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><formid="fileUploadForm"enctype="multipart/form-data"method="post"action="CCDtoFHIR.csp"><div><labelfor="file">Upload CCDA File</label><inputtype="file"name="file"id="file"required></div><div><buttontype="submit">Upload</button></div></form><csp:ifcondition='($data(%request.MimeData("file",1)))'><hr><br><b>FHIR Conversion Result:</b><br><ul><scriptlanguage="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

Comments

Enrico Parisi · Jul 2, 2024

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

0
Aman  Jul 2, 2024 to Enrico Parisi

Thanks, Enrico Parisi for your reply, I tried using the sample CCDA from here, but it's still showing empty entry for me.

0
Enrico Parisi  Jul 2, 2024 to Aman

Did you try from terminal using the EXACT code I posted?

What product are you using? You mention "IRIS 2022.2" is it IRIS for Health?

0
Aman  Jul 2, 2024 to Enrico Parisi

Yes, I tried the exact code just instead of "c:\temp\CCDA_CCD_b1_Ambulatory_v2.xml" I gave the location of same CCDA on my server.
Yes, it is IRIS for Health.

0
Enrico Parisi  Jul 2, 2024 to Aman

Just tested using IRIS for Health 2022.2 installed in a temp VM and it works fine.

Can you share the terminal output when you run that code?

0
Aman  Jul 2, 2024 to Enrico Parisi

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: 171823set 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":[]}
0
Enrico Parisi  Jul 2, 2024 to Aman

Can you please run it from a regular terminal/session?

0
Aman  Jul 2, 2024 to Enrico Parisi

Hey @Enrico Parisi I don't have access to a regular terminal, but I tried doing that using a web terminal provided by InterSystems online course, it's working fine. I am getting the complete bundle.
Can you tell what is the issue? Why am I not able to get the same through my CSP page?

0
Aman  Jul 3, 2024 to Enrico Parisi

.

0