Hl7 to fhir conversation

74 views
Skip to first unread message

ashok...@gmail.com

unread,
Aug 18, 2025, 8:07:26 AMAug 18
to Hardhats
Hello Team,

Are there any packages available to convert HL7 message to FHIR resources?

Thank you!

Regards,
Ashok

Sam Habiel

unread,
Aug 18, 2025, 8:13:01 AMAug 18
to hard...@googlegroups.com
> Are there any packages available to convert HL7 message to FHIR resources?

There is no such thing. They serve different purposes. HL7 messages are for medical communication with devices; FHIR for representing a patient record. They are not interchangeable.

--Sam

--
--
http://groups.google.com/group/Hardhats
To unsubscribe, send email to Hardhats+u...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "Hardhats" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hardhats+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/hardhats/d14fdfcd-eb66-4b27-a321-80e815615087n%40googlegroups.com.

Kimball Bighorse

unread,
Aug 20, 2025, 4:07:56 PMAug 20
to Hardhats
I'm no expert, but this looks like something?


Kimball

Michael O'Neill

unread,
Aug 20, 2025, 5:09:36 PMAug 20
to hard...@googlegroups.com
As Sam said, HL7 messages and FHIR resources aren’t interchangeable, and thinking of it as the conversion of one message to one FHIR resource wouldn’t be the way to think of it. But it’s definitely possible to parse HL7 messages and map data elements to FHIR resources. Same with CCDA documents. My company (MedicaSoft) does this as part of our data platform (NXT Platform). I don’t know that there is an open source package for this but other companies also parse messages/documents and create FHIR resources. 

Depending on the use case, it can get a little complicated. If you have messages from different organizations you will have to decide how to match patients. You may need to do some code set mapping. There may be decisions that need to be made in the FHIR mapping; the mapping is not always a simple one-message-segment-to-one-FHIR-resource-field exercise. You may need to think about deduplication. And so on.

Mike

Benjamin Irwin

unread,
Aug 20, 2025, 5:20:43 PMAug 20
to Hardhats
I know that I am getting a little old, but this conversation doesn't seem to make sense to me.

When I retired the HL7 standard was moving from the segment structure to the FHIR structure.

The following two links seem to show that.  The HL7 and FHIR go hand in hand.

I would think that Ashok's question would be asking it there was a conversion tool to convert HL7 segments into a FHIR formatted HL7 message.


Benjamin Irwin

unread,
Aug 20, 2025, 8:32:54 PMAug 20
to Hardhats
I just asked ChatGPT "Can you write code to convert a segmented HL7 message to FHIR?"  It actually provided a reasonable response written in Python.

Benjamin Irwin

unread,
Aug 21, 2025, 7:45:33 PMAug 21
to Hardhats
I spent a couple hours with my new friend, ChatGPT and "We" came up with the following routine as a starting point for HL7 to FHIR conversion.  I had to teach it my formatting style of spelled out mixed case commands.  At first it got the $Piece command numbering incorrect, starting at "0" instead of "1". I taught it that and it thanked me for catching that.  Made me feel a little needed.  It also initially wrote the routine to call from the top; we corrected that.


HL7FHIRAI ; HL7 v2.x → FHIR Bundle Converter
 Quit  ; prevent accidental execution if called with Do ^HL7FHIRAI

 ; --- Test driver ---
Test
 New HL7MSG,OUTJSON
 ; Example HL7 message segments
 Set HL7MSG(1)="MSH|^~\&|LABSYS|LAB|EHR|HOSP|202501011200||ADT^A01|123456|P|2.3"
 Set HL7MSG(2)="PID|1||12345^^^HOSP^MR||Doe^Jane||19851105|F|||123 Main St^^Metropolis^NY^10001||555-1234"
 Set HL7MSG(3)="PV1|1|I|2000^2012^01||||1234^Smith^John|||||||||||98765"
 Set HL7MSG(4)="OBX|1|NM|GLUCOSE^GLU||120|mg/dL|70-110|H|||F"
 Do Convert(.HL7MSG,.OUTJSON)
 Write !,"--- FHIR Bundle JSON Output ---",!
 Write OUTJSON,!
 Quit

 ; --- Main converter ---
Convert(HL7MSG,OUTJSON)
 New FS,CS,RS,EC,SS,SEG,I,TYPE,ENTRY,IDX
 Set FS="|"
 Set CS=$Extract(HL7MSG(1),5)
 Set RS=$Extract(HL7MSG(1),6)
 Set EC=$Extract(HL7MSG(1),7)
 Set SS=$Extract(HL7MSG(1),8)
 Set OUTJSON="{""resourceType"":""Bundle"",""type"":""collection"",""entry"":["
 Set IDX=0
 For I=1:1 Quit:'$Data(HL7MSG(I))  Do
 . Set SEG=HL7MSG(I)
 . Set TYPE=$Piece(SEG,FS,1)
 . Set ENTRY=""
 . Do Dispatch(TYPE,SEG,.ENTRY,FS,RS,CS,SS)
 . If ENTRY'="" Do
 . . If IDX>0 Set OUTJSON=OUTJSON_","
 . . Set OUTJSON=OUTJSON_"{""resource"":"_ENTRY_"}"
 . . Set IDX=IDX+1
 Set OUTJSON=OUTJSON_"]}"
 Quit

 ; --- Dispatcher ---
Dispatch(TYPE,SEG,OUT,FS,RS,CS,SS)
 If TYPE="PID" Do PID(.OUT,SEG,FS,RS,CS,SS) Quit
 If TYPE="PV1" Do PV1(.OUT,SEG,FS,RS,CS,SS) Quit
 If TYPE="OBX" Do OBX(.OUT,SEG,FS,RS,CS,SS) Quit
 Quit

 ; --- Patient (PID → Patient) ---
PID(OUT,SEG,FS,RS,CS,SS)
 New NAME,FAMILY,GIVEN,BIRTH,GENDER
 Set NAME=$$FldOne(5,SEG,FS,RS,CS,SS)
 Set FAMILY=$Piece(NAME,CS,1)
 Set GIVEN=$Piece(NAME,CS,2)
 Set BIRTH=$$FldOne(7,SEG,FS,RS,CS,SS)
 If $Length(BIRTH)=8 Set BIRTH=$Extract(BIRTH,1,4)_"-"_$Extract(BIRTH,5,6)_"-"_$Extract(BIRTH,7,8)
 Set GENDER=$$FldOne(8,SEG,FS,RS,CS,SS)
 If GENDER="M" Set GENDER="male"
 If GENDER="F" Set GENDER="female"
 If GENDER="O" Set GENDER="other"
 If GENDER="U" Set GENDER="unknown"
 Set OUT="{""resourceType"":""Patient"",""identifier"":[{""value"":"""_$$FldOne(3,SEG,FS,RS,CS,SS)_"""}],""name"":[{""family"":"""_FAMILY_""",""given"":["""_GIVEN_"""]}],""birthDate"":"""_BIRTH_""",""gender"":"""_GENDER_"""}"
 Quit

 ; --- Encounter (PV1 → Encounter) ---
PV1(OUT,SEG,FS,RS,CS,SS)
 New VISITNO,CLASSTYP
 Set CLASSTYP=$$FldOne(2,SEG,FS,RS,CS,SS)
 Set VISITNO=$$FldOne(19,SEG,FS,RS,CS,SS)
 Set OUT="{""resourceType"":""Encounter"",""identifier"":[{""value"":"""_VISITNO_"""}],""class"":{""code"":"""_CLASSTYP_"""}}"
 Quit

 ; --- Observation (OBX → Observation) ---
OBX(OUT,SEG,FS,RS,CS,SS)
 New ID,VAL,UNIT
 Set ID=$$FldOne(3,SEG,FS,RS,CS,SS)
 Set VAL=$$FldOne(5,SEG,FS,RS,CS,SS)
 Set UNIT=$$FldOne(6,SEG,FS,RS,CS,SS)
 Set OUT="{""resourceType"":""Observation"",""code"":{""text"":"""_ID_"""},"
 Set OUT=OUT_"""valueQuantity"":{""value"":"""_VAL_""",""unit"":"""_UNIT_"""}}"
 Quit

 ; --- Helpers ---
Fld(N,SEG,OUT,FS,RS,CS,SS)
 New FIELD,I
 Kill OUT
 Set FIELD=$Piece(SEG,FS,N+1)
 For I=1:1:$Length(FIELD,RS) Set OUT(I)=$Piece(FIELD,RS,I)
 Quit

FldOne(N,SEG,FS,RS,CS,SS)
 Quit $Piece(SEG,FS,N+1)

arun kumar

unread,
Aug 22, 2025, 8:28:25 AMAug 22
to hard...@googlegroups.com
We used to develop the HL7 v2.x version to FHIR resources through intersystems IRIS for health for USA market. There is a SDA3 architecture in Intersystems to convert data from Flatfile, HL7 v2.x, ccda, FHIR to FHIR resources, HL7 v2.x, ccda documents, or any formats. 

This info may help to your query?


Best Regards,
Arun Kumar Durairaj,

Reply all
Reply to author
Forward
0 new messages