Pesquisar

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
お知らせ
· 2026年1月10日

Videos for InterSystems Developers, December 2025 Recap

Hello and welcome to the December 2025 Developer Community YouTube Recap.
InterSystems Ready 2025
By Jeffrey Fried, Dr Sankalp Khanna PhD
By Brenna Quirk, Jim Breen, Kim Koehler
By Thomas Dyar, Fernando Ferreira, Djeniffer Greffin, Claudio Laudeauzer, Holger Müller, Fabio Caré
By Boya Song
By Sean Kennedy
 
"Code to Care" videos
Using GenAI in Real Life: Daily Use Cases That Work
By Don Woodlock, Head of Global Healthcare Solutions, InterSystems
More from InterSystems Developers
SQL Tricks and Tips
By Ismail Ben Atitallah, Yiwen Huang
Smarter Table Statistics
By Yuchen Liu, Minhao Li
10th Anniversary of the InterSystems Developer Community
By InterSystems Developer Community Team
Developer Community Timeline - 10th Anniversary Edition
By InterSystems Developer Community Team
ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
記事
· 2026年1月10日 5m read

Exemplo de API REST para decodificar dados em base64

Olá a todos,

Sou eu de novo 😁. No artigo anterior, Writing a REST api service for exporting the generated FHIR bundle in JSON, nós geramos um recurso DocumentReference, com o conteúdo codificados em Base64.

 

Question!! Is it possible to write a REST service for decoding it? Because I am very curious what is the message data talking about🤔🤔🤔

Duvida!! É possível escrever um serviço REST para decodificar isso? Porque estou muito curioso para saber o conteúdo da mensagem 🤔🤔🤔

OK, Vamos começar!

1. Crie uma nova classe utilitária datagen.utli.decodefhirjson.cls para decodificar os dados dentro de DocumentReference
 

Class datagen.utli.decodefhirjson Extends %RegisteredObject
{
}

2. Escreva uma função Python decodebase64docref para
a. percorrer o bundle FHIR
b. encontrar o recurso DocumentReference
  -pegar o primeiro elemento em content
   - pegar o attachment do content
     - recuperar o data do attachment
c. decodificar os dados em Base64
 (essa parte pedi ajuda ao chatGPT😂🤫) 

Class datagen.utli.decodefhirjson Extends %RegisteredObject
{

ClassMethod decodebase64docref(fhirbundle = "") As %String [ Language = python ]
{
    # w ##class(datagen.utli.decodefhirjson).decodebase64docref()
    import base64
    import json

    def decode_discharge_summary(bundle_json):
        """
        Extracts and decodes the Base64-encoded discharge summary note
        from a FHIR Bundle containing a DocumentReference.
        """
        for entry in bundle_json.get("entry", []):
            resource = entry.get("resource", {})
            if resource.get("resourceType") == "DocumentReference":
                # Traverse to the attachment
                content_list = resource.get("content", [])
                if not content_list:
                    continue
                attachment = content_list[0].get("attachment", {})
                base64_data = attachment.get("data")
                if base64_data:
                    decoded_text = base64.b64decode(base64_data).decode("utf-8")
                    return decoded_text
        return None


    # Example usage
    # Load your FHIR Bundle JSON from a file or object
    #with open("fhir_bundle.json", "r") as f:
    #    fhir_bundle = json.loads(f)
    if fhirbundle=="":
        rtstr=f"⚠️ No input found - JSON string is required."
        jsstr={"operation_outcome" : rtstr}
        return json.dumps(jsstr, indent=2)

    fhir_bundle = json.loads(fhirbundle)
    decoded_note = decode_discharge_summary(fhir_bundle)

    if decoded_note:
        #print("📝 Decoded Discharge Summary:\n")
        #print(decoded_note)
        rtstr=f"📝 Decoded Discharge Summary:\n {decoded_note}"
    else:
        #print("⚠️ No DocumentReference with Base64 note found.")
        rtstr=f"⚠️ No DocumentReference with Base64 note found."
    jsstr={"data" : rtstr}
    return json.dumps(jsstr, indent=2)
}

}

 

Para testar essa função, eu tentei fazer um pequeno truque, que é usar a função genfhirbundle para gerar um bundle FHIR em string JSON, conforme mostrado no artigo anterior Writing a REST api service for exporting the generated FHIR bundle in JSON 
 

Vamos gerar um bundle FHIR e armazená-lo em uma variável chamada jsonstr.
 

set jsonstr=##class(datagen.utli.genfhirjson).genfhirbundle(1)

Depois, teste a função de decodificação decodebase64docref   usando jsonstr.

w ##class(datagen.utli.decodefhirjson).decodebase64docref(jsonstr)

OK 😉. Parece tudo certo. Agora posso ler a mensagem decodificada.


 

Agora, voltando ao artigo anterior e ao anterior a esse, Writing a REST api service for exporting the generated patient data in .csv.

Gostaríamos de adicionar uma nova função e atualizar a rota da classe datagen.restservice.

1. Adicionar uma nova função DecodeDocRef, que deverá processar o bundle FHIR enviado no corpo da requisição em formato JSON.

Ou seja, neste caso esperamos um POST.

O conteúdo do corpo é empacotado por padrão como %CSP.BinaryStream e armazenado na variável %request.Content, então podemos usar o método .Read()   da classe %CSP.BinaryStream para ler o BinaryStream.

ClassMethod DecodeDocRef() As %Status
{
    // get body - json string
    #dim bistream As %CSP.BinaryStream =""
    set bistream=%request.Content
    set jsstr=bistream.Read()
    
    //decode the Document Reference data
    w ##class(datagen.utli.decodefhirjson).decodebase64docref(jsstr)
    return $$$OK
}

 

2. Depois, adicionamos uma rota para o REST service e compilamos 😀

<Route Url="/decode/docref" Method="POST" Call="DecodeDocRef" />

 

a classe  datagen.restservice atualizada ficará parecida com o seguinte:

 


Perfeito!😁

Vamnos testar no postman!!

Envie uma chamada POST para o seguinte caminho:

localhost/irishealth/csp/mpapp/decode/docref

com o seguinte corpo (eu simplifiquei o bundle FHIR, você pode testar com o completo 😀)

{
    "resourceType": "Bundle",
    "type": "transaction",
    "id": "98bfce83-7eb1-4afe-bf2b-42916512244e",
    "meta": {
        "lastUpdated": "2025-10-13T05:49:07Z"
    },
    "entry": [
        {
            "fullUrl": "urn:uuid:5be1037d-a481-45ca-aea9-2034e27ebdcd",
            "resource": {
                "resourceType": "DocumentReference",
                "id": "5be1037d-a481-45ca-aea9-2034e27ebdcd",
                "status": "current",
                "type": {
                    "coding": [
                        {
                            "system": "http://loinc.org",
                            "code": "18842-5",
                            "display": "Discharge summary"
                        }
                    ]
                },
                "subject": {
                    "reference": "9e3a2636-4e87-4dee-b202-709d6f94ed18"
                },
                "author": [
                    {
                        "reference": "2aa54642-6743-4153-a171-7b8a8004ce5b"
                    }
                ],
                "context": {
                    "encounter": [
                        {
                            "reference": "98cd848b-251f-4d0b-bf36-e35c9fe68956"
                        }
                    ]
                },
                "content": [
                    {
                        "attachment": {
                            "contentType": "text/plain",
                            "language": "en",
                            "data": "RGlzY2hhcmdlIHN1bW1hcnkgZm9yIHBhdGllbnQgOWUzYTI2MzYtNGU4Ny00ZGVlLWIyMDItNzA5ZDZmOTRlZDE4LiBEaWFnbm9zaXM6IFN0YWJsZS4gRm9sbG93LXVwIGluIDIgd2Vla3Mu",
                            "title": "Discharge Summary Note"
                        }
                    }
                ]
            },
            "request": {
                "method": "POST",
                "url": "DocumentReference"
            }
        }
    ]
}

Funcionou bem!!!😆😉

Muito obrigado pela leitura. 😘

ディスカッション (0)1
続けるにはログインするか新規登録を行ってください
ディスカッション (2)3
続けるにはログインするか新規登録を行ってください
お知らせ
· 2026年1月9日

InterSystems Developer Ecosystem News, Q4 2025

Hello and welcome to the Developer Ecosystem News!

The fourth quarter of the year was full of exciting activities in the InterSystems Developer Ecosystem. In case you missed something, we've prepared a selection of the hottest news and topics for you to catch up on!

News

🎇 2025 in Review - Celebrate Your Year with Developer Community!

🎆 Season’s Greetings to the Developer Community

🔔 New interface of the DC AI Chat!

📝 InterSystems Platforms Update Q4-2025

👨‍💻 Free Hands-On Online Tutorials for New InterSystems IRIS Developers

🔔 How to submit Bug Reports via the Ideas Portal

⌨ October and November Article Bounty on Global Masters

📝 InterSystems Developer Community GitHub

🎃 Halloween on Global Masters

🔧 Developer Community AI Is Taking a Break

🔧 Developer Community Search Update

🛠️ Maintenance Notice Dec 26, 2025

📝 Celebrating 1,000 Certifications

Contests & Events

 
InterSystems .Net, Java, Python, and JavaScript Contest
 
"Improving the Initial Developer Experience" Sweepstakes

🤝 Security & AI Meetup for Developers and Startups

🤝 AI Meetup for Developers and Startups

📺 [Webinar in Spanish] From Data to Knowledge: Harnessing Clinical Information with InterSystems and AI

📺 [Webinar in Dutch] Data exchange in healthcare according to the FHIR standard with Python

👩‍💻 InterSystems at Hack Jak Brno Healthcare Hackathon 2025

Latest Releases

⬇️ InterSystems Announces General Availability of InterSystems IRIS, InterSystems IRIS for Health, and HealthShare Health Connect 2025.3

⬇️ Maintenance Releases 2025.1.2 and 2024.1.5 of InterSystems IRIS, IRIS for Health, & HealthShare HealthConnect are now available

⬇️ Announcing Availability of Adaptive Analytics 2025.4.1

⬇️ Release Notes: InterSystems Cloud Services – Version 25.24.1 (November 2025)

⬇️ 2025.3 Modernizing Interoperability User Experience

⬇️ Client SDKs available on external repositories

⬇️ "IntegratedML Custom Models" Early Access Program

Best Practices & Key Questions

❓ Key Questions: October, November, December (TBA)

People and Companies to Know About 

👩‍🏫 Meet Henry Hamon Rodrigues Pereira - New Developer Community Moderator!

👩‍🏫 Celebrating a Guiding Voice in the Developer Community

👩‍🏫 Celebrating a Curious Mind of the Developer Community

So...

Here is our take on the most interesting and important things! 

What were your highlights from this past quarter? Share them in the comments section, and let's remember the fun we've had!

ディスカッション (0)2
続けるにはログインするか新規登録を行ってください