Pesquisar

Artigo
· Out. 13 4min de leitura

Comment interagir avec les CSV (importer)

Bonjour

Je vous soumets cet article en tant qu’état de l’art enrichi.
L’objectif est de réunir les différentes façons d’importer et d’exporter des CSV en un seul endroit.
Cet article est basé sur InterSystems 2024.1 .
N'hésitez pas à commenter pour rajouter des précisions.
Si vous voulez une deuxième partie sur l'export de CSV, faites le moi savoir.

Contexte

Le format CSV (pour Comma Separated Values)  est un format texte représentant des données tabulaires.
Voici le lien wikipédia pour les curieux : https://fr.wikipedia.org/wiki/Comma-separated_value
On peut donc l'importer : le programme lit le fichier CSV et récupère les données; et l'exporter : le programme génère un fichier CSV avec certaines données. 

 

Le plus efficace : Python

La façon la plus simple pour manipuler le format CSV est d'utiliser les library Python :

  1. csv : https://docs.python.org/fr/3.13/library/csv.html
  2. pandas : https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

Hélas, certains d'entre nous sont ophiophobes. C'est pourquoi le reste de l'article se concentre sur l'ObjectScript.

 

Importer un CSV

do ##class(%SQL.Util.Procedures).CSVTOCLASS()

La classMéthode CSVTOCLASS va recevoir en entrée un fichier et le type des colonnes.
Elle va créer la classe "Test.CSV" correspondante et insérer les données du CSV dans la table associée.
https://docs.intersystems.com/iris20252/csp/documatic/%25CSP.Documatic.c...

set rowtype = "Code VARCHAR(2),Name VARCHAR(9)"
set filename = "c:\temp\Country.csv"
do ##class(%SQL.Util.Procedures).CSVTOCLASS(2, .rowtype, filename,,,,"Test.CSV")

Son avantage : cette méthode créée la nouvelle classe et les méthodes associées ce qui permet un gain de temps et une adaptabilité.

 

LOAD DATA

LOAD DATA est une requête SQL recevant un CSV et insérant les données dans la table.
https://docs.intersystems.com/iris20252/csp/docbook/DocBook.UI.Page.cls?...

>>> CREATE TABLE Sample.Person (
        Name VARCHAR(25),
        Age INT,
        DOB DATE)
        
>>> LOAD DATA FROM FILE 'C://sampledata/people.csv' INTO Sample.Person

Un article en parle très bien : https://community.intersystems.com/post/tips-and-tricks-brand-new-load-d...

 

%SQL.Import.Mgr

Une instanciation de la classe %SQL.Import.Mgr permet de définir beaucoup de paramètres afin de lire un CSV avec beaucoup de nuances.

https://docs.intersystems.com/iris20252/csp/documatic/%25CSP.Documatic.c...

//start of the transaction
TSTART
set SQLImport = ##class(%SQL.Import.Mgr).%New()

set SQLImport.HasHeaders = 1
set SQLImport.FileName = "$CSV_FILE"
set SQLImport.TableName = "$TABLE"
set SQLImport.ClassName = "$CLASS"
// add columns of the table
do SQLImport.ColumnNames.Insert("Code")
do SQLImport.ColumnNames.Insert("Name")

set SQLImport.Delimiter = ";"
// add of the escape character
set SQLImport.StringQuote = """"
do SQLImport.GenerateImportRoutine()

set tSC = SQLImport.Import()
// end of the transaction
if 'tSC { TROLLBACK } else { TCOMMIT }

Avantage : cela permet de choisir le format de date, le séparateur, si les valeurs sont entre quotes ...
 

CUSTOM

Pourquoi utiliser des méthodes existantes quand on peut faire son propre code?
Je vous propose cette méthode que j'ai créée. Il suffit de créer une classe avec les propriétés dans le même ordre que les colonnes du CSV.


/// Reçoit en entrée le stream d'un csv et le nom de classe associée
/// Renvoie la liste des objets
/// separator définit le séparateur du CSV
/// skipLine définit le nombre de ligne à passer au début du CSV
ClassMethod StreamToObjectList(stream As %Stream.TmpCharacter, className As %String, ByRef listObject, separator As %String = ";", skipLine As %Integer = 0) As %Status
{
    Set status = $$$OK
    Try {
        Set listObject = ##class(%Library.ListOfObjects).%New()

        Set sqlQuery = "SELECT * FROM %Dictionary.PropertyDefinition WHERE parent = ? ORDER BY SequenceNumber"
        Set resultSet = ##class(%SQL.Statement).%New()
        Set status = resultSet.%Prepare(sqlQuery)
        $$$ThrowOnError(status)
		
        Do stream.Rewind()
        /// On parcourt le stream
        While ('stream.AtEnd) {
            Set line = stream.ReadLine() // on lit chaque ligne du CSV
            If skipLine > 0
            {
                Set skipLine = skipLine - 1 // le nombre de ligne qu'il reste à passer diminue
            }ElseIf($LENGTH(line)>0){ // pour ignorer les lignes vides
                Set object = $CLASSMETHOD(className,"%New")
				Set ii = 1
                Set tResult = resultSet.%Execute(className)
				While tResult.%Next() {
					Set Name = tResult.%Get("Name")
					Set $PROPERTY(object,Name) = $PIECE(line,separator,ii)
					Set ii = ii + 1
				}
                Set status = listObject.Insert(object)
                $$$ThrowOnError(status)
            }
        }
    }
    Catch exception {
        Set status = exception.AsStatus()
    }
    Quit status
}

Avantage : Son but est de retourner la liste des données du CSV et de ne pas les enregistrer dans une table SQL.. La méthode custom qui peut être modifié par les différents besoins.

3 Comments
Discussão (3)3
Entre ou crie uma conta para continuar
Anúncio
· Out. 13

Resumen de la Comunidad de Desarrolladores: Septiembre 2025

¿No habéis podido entrar en la Comunidad todo lo que os gustaría? ¡No os preocupéis! Os traemos un resumen de todo lo que hemos publicado en el mes de septiembre. Seguid leyendo y no os lo perdáis ⬇️⬇️
Estadísticas generales
✓ publicaciones nuevas:
 18 artículos
 18 anuncios
 3 nuevas preguntas
Top 10 publicaciones populares
Implementando un proyecto FHIR - ÚNICAS
Por Luis Angel Pérez Ramos
Top Autores populares
Todos los artículos
#InterSystems IRIS
Crea un agente de IA para atención al cliente con smolagents + InterSystems IRIS (SQL, RAG e interoperabilidad)
Por Alberto Fuentes
Programación práctica en ObjectScript: de JSON a Globals a SQL
Por Ricardo Paiva
IRIS in Docker para principiantes
Por Robert Cemper
Convertir lista de Python %SYS.Python a %Library.DynamicArray en ObjectScript
Por Sammy Lee
Poner (o quitar) esos guiones (-) en vuestra operación FHIR personalizada
Por Ricardo Paiva
Generar documentación de clases en PDF utilizando Doxygenerate
Por Jose-Tomas Salvador
Ejecuta tu Agente de IA con InterSystems IRIS y modelos locales con Ollama
Por Alberto Fuentes
Cómo acceder a InterSystems IRIS Community Edition
Por Derek Gervais
Abordando consultas SQL lentas en InterSystems IRIS: una solución práctica
Por Ricardo Paiva
Compartir volúmenes entre pods y zonas en AKS
Por Ricardo Paiva
Importar datos CSV en InterSystems IRIS y preservar los IDs
Por Luis Angel Pérez Ramos
InterSystems para Dummies – Record Map
Por Kurro Lopez
Aprendiendo ObjectScript como un Desarrollador Nuevo: Lo que me Habría Gustado Saber
Por Beatrice Zorzoli
 
#HealthShare
 
#InterSystems IRIS for Health
 
#Comunidad de Desarrolladores Oficial
 
#Caché
Todos cometemos errores
Por Ricardo Paiva
 
#Health Connect
Implementando un proyecto FHIR - ÚNICAS
Por Luis Angel Pérez Ramos
 
Todos los anuncios
#InterSystems IRIS
¡Se viene un webinar increíble! De los datos al conocimiento: Sacando provecho a la Información Clínica con InterSystems e IA
Por Sergio Farago
¡Van subiendo los registros! Webinar en español "De los datos al conocimiento: Sacando provecho a la Información Clínica con InterSystems e IA"
Por Sergio Farago
¡Nos lo quitan de las manos! Webinar "De los datos al conocimiento: Sacando provecho a la Información Clínica con InterSystems e IA"
Por Sergio Farago
Queda una semana para el webinar "De los datos al conocimiento: Sacando provecho a la Información Clínica con InterSystems e IA"
Por Sergio Farago
Crear modelos de predicción automaticamente desde tus datos SQL
Por Alberto Fuentes
Nuevo tutorial práctico: RAG usando la búsqueda vectorial de InterSystems IRIS
Por Sergio Farago
 
#InterSystems IRIS for Health
 
#Comunidad de Desarrolladores Oficial
 
#Global Masters
 
#IRIS contest
 
#Summit
 
Todas las preguntas
septiembre, 2025Month at a GlanceInterSystems Developer Community
Discussão (0)1
Entre ou crie uma conta para continuar
Resumo
· Out. 13

Resumen de la Comunidad de Desarrolladores, septiembre 2025

Hola y bienvenidos al boletín de la comunidad de desarrolladores septiembre 2025.
Estadísticas generales
✓ publicaciones nuevas:
 18 artículos
 18 anuncios
 3 nuevas preguntas
6 nuevos miembros se unieron en septiembre
2,240 contenidos publicados de forma constante
865 miembros se unieron de forma constante
Publicaciones populares
Implementando un proyecto FHIR - ÚNICAS
Por Luis Angel Pérez Ramos
Autores populares
Artículos
#InterSystems IRIS
Crea un agente de IA para atención al cliente con smolagents + InterSystems IRIS (SQL, RAG e interoperabilidad)
Por Alberto Fuentes
Programación práctica en ObjectScript: de JSON a Globals a SQL
Por Ricardo Paiva
IRIS in Docker para principiantes
Por Robert Cemper
Convertir lista de Python %SYS.Python a %Library.DynamicArray en ObjectScript
Por Sammy Lee
Poner (o quitar) esos guiones (-) en vuestra operación FHIR personalizada
Por Ricardo Paiva
Generar documentación de clases en PDF utilizando Doxygenerate
Por Jose-Tomas Salvador
Ejecuta tu Agente de IA con InterSystems IRIS y modelos locales con Ollama
Por Alberto Fuentes
Cómo acceder a InterSystems IRIS Community Edition
Por Derek Gervais
Abordando consultas SQL lentas en InterSystems IRIS: una solución práctica
Por Ricardo Paiva
Compartir volúmenes entre pods y zonas en AKS
Por Ricardo Paiva
Importar datos CSV en InterSystems IRIS y preservar los IDs
Por Luis Angel Pérez Ramos
InterSystems para Dummies – Record Map
Por Kurro Lopez
Aprendiendo ObjectScript como un Desarrollador Nuevo: Lo que me Habría Gustado Saber
Por Beatrice Zorzoli
#HealthShare
#InterSystems IRIS for Health
#Comunidad de Desarrolladores Oficial
#Caché
Todos cometemos errores
Por Ricardo Paiva
#Health Connect
Implementando un proyecto FHIR - ÚNICAS
Por Luis Angel Pérez Ramos
Anuncios
#InterSystems IRIS
#InterSystems IRIS for Health
#Comunidad de Desarrolladores Oficial
#Global Masters
#IRIS contest
#Summit
Preguntas
septiembre, 2025Month at a GlanceInterSystems Developer Community
Artigo
· Out. 13 5min de leitura

REST api example for decode a Base64 data

Hi all,

 

It's me again 😁. In the pervious article Writing a REST api service for exporting the generated FHIR bundle in JSON, we actually generated a resource DocumentReference, with the content data encoded in 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🤔🤔🤔

OK, Let's start!

1. Create a new utility class datagen.utli.decodefhirjson.cls for decoding the data inside the DocumentReference
 

Class datagen.utli.decodefhirjson Extends %RegisteredObject
{
}

2. Write a Python function decodebase64docref to 
a. loop through the FHIR bundle
b. find out the resource DocumentReference
  - get the 1st element in the content
   - get the attachment from the content
     - get the data from the attachment
c. decode the data by Base64
 (this part I asked Chat-GPT to help me😂🤫) 

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)
}

}

 

For testing this function, I try do some trick, which is making use of the function genfhirbundle to generate FHIR bundle in JSON string,  in the pervious article Writing a REST api service for exporting the generated FHIR bundle in JSON 

Let's generated a FHIR bundle and store into a variable jsonstr

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

The test the decode function decodebase64docref  with the jsonstr

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

OK 😉 Looks good. Now I can read the decode message.


 

Now, go back the pervious and pervious article Writing a REST api service for exporting the generated patient data in .csv

We would like to add a new function and update the route for the datagen.restservice class.

1. Add a new function DecodeDocRef, which is expecting to handle the FHIR bundle  attached in the body in JSON format.

i.e. In this case, we are expecting a POST.

the body content is packaged as %CSP.BinaryStream by default and stored in the variable %request.Content, so we can use the .Read() function  from the class %CSP.BinaryStream to read the 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. Then we add a route for the REST service and compile😀

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

the updated  datagen.restservice class will look like the following.

 


Great!! That's all we need to do!😁

Let's test in postman!!

POST the following path

localhost/irishealth/csp/mpapp/decode/docref

with the following body ( I simplified FHIR bundle, you may test the full one😀)

{
    "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"
            }
        }
    ]
}

Works well!!!😆😉

Thank you very much for reading. 😘

2 Comments
Discussão (2)1
Entre ou crie uma conta para continuar
Pergunta
· Out. 13

GOOG vs GOOGL: Understanding the Real Difference for Investors in 2025

 

Goog Vs Googl

 

When it comes to investing in tech giants, Google’s parent company, Alphabet Inc., continues to be one of the most discussed names in the stock market. However, new and even experienced investors often face confusion when they see two ticker symbols — GOOG and GOOGL — representing the same company. If both are Alphabet Inc. shares, what makes them different? Which one should you invest in? This detailed GOOG vs GOOGL review for 2025 breaks down the differences, ownership structures, and performance insights to help investors make informed decisions.

Introduction to Alphabet Inc. and Its Dual-Class Shares

Alphabet Inc. is the parent company of Google, the global leader in search engines, online advertising, and digital innovation. When Alphabet restructured in 2015, it introduced a dual-class share system to maintain control among its founders while still allowing public investment. This system gave birth to two major types of publicly traded shares — GOOG and GOOGL. The goal was simple: allow outside investors to buy into the company while ensuring that co-founders Larry Page and Sergey Brin retain decision-making authority.

GOOG vs GOOGL: The Core Difference

The primary difference between GOOG and GOOGL stocks lies in their voting rights. Both represent ownership in Alphabet Inc., but not all shares are created equal.

  • GOOGL (Class A) shares carry voting rights, allowing shareholders to have a say in company decisions, such as electing board members and approving major corporate policies.
  • GOOG (Class C) shares do not include voting rights, meaning investors can benefit financially but have no influence over company governance.

To summarize in simple terms, GOOGL gives you a voice, while GOOG gives you returns without a vote.

This dual-class structure was introduced in 2014 after a stock split designed to ensure that founders maintained control over company direction even as Alphabet grew into a trillion-dollar entity.

Why Alphabet Created Two Classes of Shares

The introduction of two types of shares wasn’t random. Alphabet’s leadership wanted to prevent the dilution of control that typically occurs when companies expand ownership.

By creating Class B shares (held only by insiders with ten times the voting power of Class A shares), Alphabet secured the founders’ dominance over strategic decisions.

Public investors could choose between GOOG and GOOGL, depending on whether they valued voting rights or slightly better liquidity and price efficiency. This structure mirrors a growing trend among major tech firms, where founders want to maintain long-term vision control while giving investors access to growth opportunities.

Price Differences Between GOOG and GOOGL

Though GOOG and GOOGL stocks represent the same company, their prices often differ slightly. The difference—usually a few dollars per share—arises mainly from investor demand for voting rights. Historically, GOOGL tends to trade at a small premium because of its voting privilege, though market conditions and investor sentiment can occasionally flip that.

Over time, price variations have narrowed as investors realized that the lack of voting rights in GOOG doesn’t impact their financial gains significantly. For many retail investors, performance, dividends, and company growth matter far more than voting power.

Which One Is Better: GOOG or GOOGL?

When comparing GOOG vs GOOGL, the choice depends on your investment priorities.

  • If you value having a say in company decisions and plan to hold long-term, GOOGL might suit you better.
  • If you’re focused on returns, liquidity, and ease of trading, GOOG is equally strong, often trading in higher volume.

From a purely financial perspective, the returns on GOOG and GOOGL have historically been nearly identical. The differences lie in governance rights, not performance. For institutional investors or those holding large volumes, GOOGL may seem slightly more attractive. But for retail investors, GOOG’s flexibility and minimal price difference make it a great choice.

Ultimately, neither is “better” in terms of returns; it depends on what kind of investor you are — a decision-maker or a profit-seeker.

Alphabet’s Stock Performance and Investor Outlook in 2025

As of 2025, Alphabet remains one of the most dominant players in the technology and advertising sectors. The company’s growth is fueled by advancements in artificial intelligence, cloud computing, YouTube, and autonomous vehicle projects.

Both GOOG and GOOGL stocks have continued to reward investors with strong financial results, consistent revenue growth, and expanding profit margins. Alphabet’s focus on innovation, strategic acquisitions, and AI leadership has made both tickers popular among institutional and retail investors alike.

Even during periods of market volatility, Alphabet’s diversified revenue sources — particularly through Google Search and YouTube Ads — have provided stability. With strong fundamentals, both GOOG and GOOGL remain long-term growth investments rather than short-term trades.

Investor Sentiment: How the Market Views GOOG vs GOOGL

Investor sentiment around GOOG vs GOOGL stock has remained positive. Analysts continue to rate Alphabet as a buy or strong buy, citing its dominance in digital advertising and its rapid integration of AI into core products.

However, some investors prefer GOOGL for its symbolic participation in corporate governance, even if voting power is limited in practice. Others view GOOG as slightly more convenient for trading or for inclusion in certain index funds that prefer non-voting shares.

Both versions benefit equally from Alphabet’s continued stock buybacks, which help boost shareholder value and earnings per share.

Tax Implications and Dividends

Currently, Alphabet does not pay dividends, meaning investors rely solely on capital appreciation for returns. Tax treatment for GOOG and GOOGL is identical because they represent the same company ownership.

When Alphabet eventually considers dividends in the future, both classes are expected to receive equal payouts. Thus, tax planning doesn’t need to factor into whether you choose GOOG or GOOGL.

The Role of Index Funds and ETFs

Another interesting aspect of GOOG vs GOOGL is their presence in index funds and ETFs. Some funds may prefer GOOG because of its higher liquidity and slightly lower trading costs. Others, like governance-oriented funds, may hold GOOGL to represent shareholder voting rights.

Regardless of which fund you invest in, both share classes contribute equally to Alphabet’s market capitalization, ensuring that the company remains among the most influential stocks in major indices like the S&P 500 and NASDAQ-100.

Alphabet’s Future and Long-Term Outlook

Looking ahead, Alphabet’s growth potential remains strong. The company continues to dominate search and advertising, while expanding into AI, quantum computing, cloud technology, and hardware innovation. Its recent focus on integrating generative AI into Google Search and Workspace products positions it as a leader in the next technological revolution. For investors, this means both GOOG and GOOGL are strategic long-term holdings that could deliver sustained growth in the coming years. As Alphabet expands further into diverse business areas, its dual-share structure ensures leadership stability while offering the public a chance to share in its success.

Final Thoughts: GOOG vs GOOGL – Which Should You Choose in 2025?

Choosing between GOOG vs GOOGL ultimately depends on your investment goals:

  • Choose GOOGL if you prefer to have voting rights and want to feel part of the company decision-making, even if your influence is small.
  • Choose GOOG if you focus purely on financial returns, liquidity, and ease of trading.

From a long-term investor’s perspective, both stocks are virtually identical in performance. The distinction is more about governance preference than profitability. Alphabet remains one of the world’s most innovative and financially sound companies. Whether you pick GOOG or GOOGL, you’re investing in a company shaping the future of digital technology.

Discussão (0)1
Entre ou crie uma conta para continuar