发布新帖

検索

讨论 (2)2
登录或注册以继续
讨论
· 四月 16

%Library.File and no Character Encoding Option

I have written a new script for csv file export, which writes lines to a %Library.File file based on a SQL query.

The code is simplified into the following as 

try {
    // set up file as %Libary.File
    set f = ##class(%Library.File).%New()
    set f.Name = "export.csv"
    if (##class(%File).Exists(f.Name)) { $$$ThrowOnError(##class(%File).Delete(f.Name)) }
    $$$ThrowOnError(f.Open("WUN"))
    $$$ThrowOnError(f.LineTerminatorSet($C(13,10)))
    
    // Write lines from SQL 
    &sql(DECLARE cur CURSOR FOR SELECT a, b into :a, :b	FROM table)
    &sql(OPEN cur)
    &sql(FETCH cur)
    do f.Write("a col, b col"_$C(13,10))
    while (SQLCODE = 0) {
        s line = ""_a_","_b_""
        do f.Write(line) // NOTE: workaround here of do f.Write($zconvert(line,"O","UTF8"))
        do f.Write($C(13,10))
        &sql(FETCH cur)
    }
    &sql(CLOSE cur)
    
    // Clean up
    do f.Close()
    $$$ThrowOnError(f.%Save())
    return 1
} catch err {
    do err.Log()
    write "Error exporting file."
}

The SQL table has two columns a and b, whose values can contain special characters. For the example, say the characters are エッジ

I ran into an issue here that special characters were not properly handled in the exported file. I expected to be able to set a standard character encoding of UTF-8 on the file itself, but after a deep dive into %Library.File in the documents, and all the classes it inherits from, I was unable to find anything regarding character encoding or any conversation on this.

I ended up using a $zconvert with "O" mode to "UTF8" on each line to ensure on a line by line basis the proper encoding was used as

do f.Write($zconvert(line,"O","UTF8"))

This works perfectly well. But, I remain curious if anyone is aware of character encoding, historically or currently, for a File type. And/or knows or has opinions on why this is not a property of the File. Just wanted to open this up for discussion.

Thanks anyone for your thoughts!

2 条新评论
讨论 (2)2
登录或注册以继续
公告
· 四月 16

[Video] How to Build a Scalable Network for Seamless Healthcare Data Exchange

Hey Community!

We're happy to share the next video in the "Code to Care" series on our InterSystems Developers YouTube:

⏯  How to Build a Scalable Network for Seamless Healthcare Data Exchange

In this episode of the Code to Care video series, Don Woodlock speaks with Jay Nakashima, President of eHealth Exchange, about how his organization has improved healthcare data interoperability across the U.S. Jay explains how eHealth Exchange replaced the impractical point-to-point data sharing model with a centralized “hub and spoke” approach using InterSystems technology. This allows providers to connect once and gain access to thousands of other trusted organizations, enabling the exchange of 25 billion transactions annually.

Presenters:
🗣 @Don Woodlock, Head of Global Healthcare Solutions, InterSystems
🗣 Jay Nakashima, President, eHealth Exchange, Board Member

Enjoy watching, and look forward to more videos! 👍

讨论 (0)1
登录或注册以继续
公告
· 四月 16

Building and Managing HL7 Integrations – IN PERSON May 5-9, 2025 / Registration space available

  • Building and Managing HL7 Integrations – In Person May 5-9, 2025 9:00am-5:00pm EDT
    • Build, configure, and manage HL7® V2 interfaces using InterSystems integration technologies.
    • This healthcare-focused 5-day course teaches implementation partners, integrators and analysts how to rapidly build HL7 integration solutions.
    • Students build a production that processes and routes HL7 messages.
    • Students learn how to work with the pre-built HL7 business services, business processes and business operations to receive and send HL7 messages.
    • Students also learn how to transform HL7 messages using graphical tools in the Management Portal.
    • This course teaches students how to monitor, manage, and troubleshoot Productions. Students also learn how to use the Management Portal for viewing, searching, and resending messages.
    • This course is applicable for users of InterSystems IRIS for Health, Ensemble, and HealthShare.
  • Self-Register Here
讨论 (0)1
登录或注册以继续
讨论
· 四月 16

Code Golf - Cobertura Máxima

Existe uma lista de números de 1 a 190.

ListaCompleta="1,2,3,4,5,6,7,8,9,.....,187,188,189,190"

Existe uma coleção de conjuntos desses valores:

Lista(1)="3,5,6,7,9"
Lista(2)="1,2,6,9"
Lista(3)="5,8,9"
Lista(4)="2,4,6,8"
Lista(5)="4,7,9"

Qual é uma abordagem elegante em ObjectScript para selecionar o menor número de itens da lista

  • Lista(1)
  • Lista(5)
  • Lista(n)

Que, juntos, cobririam o máximo de números possível da ListaCompleta.

Estou interessado na melhor cobertura, e não na eficiência.

讨论 (0)1
登录或注册以继续