health.hl7v2.utils.v2tofhirr4
Module health.hl7v2.utils.v2tofhirr4
API
ballerinax/health.hl7v2.utils.v2tofhirr4 Ballerina library
HL7v2 to FHIR Package
Usage
To use the package add following import to your Ballerina program.
import ballerinax/health.hl7v2.utils.v2tofhirr4
Sample: This sample showcase how you can pass a HL7 version 2 message and get a FHIR R4 Bundle in return. In addition to that, we are demonstrating how you could use the library to transform HL7 segments to FHIR.
import ballerina/io; import ballerinax/health.hl7v2.utils.v2tofhirr4; import ballerinax/health.hl7v2 as hl7; import ballerinax/health.hl7v23; import ballerinax/health.fhir.r4 as r4; final string msg = "MSH|^~\\&|ADT1|GOOD HEALTH HOSPITAL|GHH LAB, INC.|GOOD HEALTH" + "HOSPITAL|198808181126|SECURITY|ADT^A01^ADT_A01|MSG00001|P|2.3||\rEVN|A01|" + "200708181123||\rPID|1||PATID1234^5^M11^ADT1^MR^GOOD HEALTH"+ "HOSPITAL~123456789^^^USSSA^SS||" + "BATMAN^ADAM^A^III||19610615|M||C|2222 HOME STREET^^GREENSBORO^NC^27401-1020|GL|" + "(555)555-2004|(555)555-2004||S||PATID12345001^2^M10^ADT1^AN^A|444333333|987654^NC|" + "\rNK1|1|NUCLEAR^NELDA^W|SPO^SPOUSE||||NK^NEXT OF KIN$\rPV1|1|I|2000^2012^01||||" + "004777^ATTEND^AARON^A|||SUR||||ADM|A0|"; public function main() returns error? { // Transform HL7v2 message to FHIR R4. // You can pass a HL7v2 message and get a FHIR R4 Bundle based on // the mappings defined at // https://build.fhir.org/ig/HL7/v2-to-fhir/branches/master/datatype_maps.html. json v2tofhirResult = check v2tofhirr4:v2ToFhir(msg); io:println("Transformed FHIR message: ", v2tofhirResult.toString()); io:println("------------------------------------------------------------------"); hl7:Message hl7msg = check v2tofhirr4:stringToHl7(msg); if (hl7msg is hl7v23:ADT_A01) { // v2tofhirr4 library exposes these low level functions as well, // if you want to work with HL7v2 segments directly. // Transform HL7v2 PID to FHIR R4 Patient Name. r4:HumanName[] patientName = v2tofhirr4:pidToPatientName(hl7msg.pid.pid5, hl7msg.pid.pid9); io:println("HL7v23 PID Patient Name: ", patientName[0].toString()); } }
Functions![](/images/permalink.svg)
al1ToAllerygyIntolerance![](/images/permalink.svg)
function al1ToAllerygyIntolerance(Al1 al1) returns AllergyIntolerance
Parameters
- al1 Al1 -
ceToCode![](/images/permalink.svg)
Parameters
- ce Ce -
ceToCodeableConcept![](/images/permalink.svg)
function ceToCodeableConcept(Ce ce) returns CodeableConcept
Parameters
- ce Ce -
ceToCodeableConcepts![](/images/permalink.svg)
function ceToCodeableConcepts(Ce|CWE ce) returns CodeableConcept[]
ceToCoding![](/images/permalink.svg)
Parameters
- ce Ce -
ceToCodings![](/images/permalink.svg)
Parameters
- ce Ce -
ceToUri![](/images/permalink.svg)
Parameters
- ce Ce -
cweToCode![](/images/permalink.svg)
Parameters
- cwe Cwe -
cweToCodeableConcept![](/images/permalink.svg)
function cweToCodeableConcept(Cwe cwe) returns CodeableConcept
Parameters
- cwe Cwe -
cweToCoding![](/images/permalink.svg)
Parameters
- cwe Cwe -
cweToCodings![](/images/permalink.svg)
Parameters
- ce Cwe -
cweToUri![](/images/permalink.svg)
Parameters
- cwe Cwe -
dg1ToCondition![](/images/permalink.svg)
Parameters
- dg1 Dg1 -
dtmToDateTime![](/images/permalink.svg)
Parameters
- ts Dtm -
dtmToInstant![](/images/permalink.svg)
Parameters
- ts Dtm -
eiToCoding![](/images/permalink.svg)
Parameters
- ei Ei -
eiToIdentifier![](/images/permalink.svg)
function eiToIdentifier(Ei ei) returns Identifier
Parameters
- ei Ei -
evnToProvenance![](/images/permalink.svg)
function evnToProvenance(Evn evn) returns Provenance
Parameters
- evn Evn -
hdToMessageHeaderDestination![](/images/permalink.svg)
function hdToMessageHeaderDestination(Hd hd) returns MessageHeaderDestination
Parameters
- hd Hd -
hdToMessageHeaderSource![](/images/permalink.svg)
function hdToMessageHeaderSource(Hd hd) returns MessageHeaderSource
Parameters
- hd Hd -
idToAddressType![](/images/permalink.svg)
function idToAddressType(Id id) returns AddressType
Parameters
- id Id -
idToAddressUse![](/images/permalink.svg)
function idToAddressUse(Id id) returns AddressUse?
Parameters
- id Id -
idToCodeableConcept![](/images/permalink.svg)
function idToCodeableConcept(ID id) returns CodeableConcept
Parameters
- id ID -
idToCodeableConceptArray![](/images/permalink.svg)
function idToCodeableConceptArray(Id id) returns CodeableConcept[]
Parameters
- id Id -
idToCoding![](/images/permalink.svg)
Parameters
- id ID -
idToContactPointSystem![](/images/permalink.svg)
function idToContactPointSystem(Id id) returns ContactPointSystem
Parameters
- id Id -
idToContactPointUse![](/images/permalink.svg)
function idToContactPointUse(Id id) returns ContactPointUse
Parameters
- id Id -
idToDiagnosticReportStatus![](/images/permalink.svg)
function idToDiagnosticReportStatus(ID id) returns DiagnosticReportStatus
Parameters
- id ID -
idToHumanNameUse![](/images/permalink.svg)
function idToHumanNameUse(Id id) returns HumanNameUse
Parameters
- id Id -
idToServiceRequestPriority![](/images/permalink.svg)
function idToServiceRequestPriority(ID id) returns ServiceRequestPriority
Parameters
- id ID -
isToAllergyIntoleranceCategory![](/images/permalink.svg)
function isToAllergyIntoleranceCategory(Is 'is) returns AllergyIntoleranceCategory
Parameters
- 'is Is -
isToAllergyIntoleranceCriticality![](/images/permalink.svg)
function isToAllergyIntoleranceCriticality(Is 'is) returns AllergyIntoleranceCriticality
Parameters
- 'is Is -
isToAllergyIntoleranceType![](/images/permalink.svg)
function isToAllergyIntoleranceType(string 'is) returns AllergyIntoleranceType
Parameters
- 'is string -
msgToCoding![](/images/permalink.svg)
Parameters
- msg CM_MSG -
mshToMessageHeader![](/images/permalink.svg)
function mshToMessageHeader(Msh msh) returns MessageHeader
Parameters
- msh Msh -
nameToServiceRequestIntent![](/images/permalink.svg)
function nameToServiceRequestIntent(string name) returns ServiceRequestIntent
Parameters
- name string -
nk1ToContact![](/images/permalink.svg)
nk1ToPatient![](/images/permalink.svg)
Parameters
- nk1 Nk1 -
obrToDiagnosticReport![](/images/permalink.svg)
function obrToDiagnosticReport(Obr obr) returns DiagnosticReport
Parameters
- obr Obr -
obrToServiceRequest![](/images/permalink.svg)
function obrToServiceRequest(Obr obr) returns ServiceRequest
Parameters
- obr Obr -
obxToObservation![](/images/permalink.svg)
function obxToObservation(Obx obx) returns Observation
Parameters
- obx Obx -
orcToDiagnosticReport![](/images/permalink.svg)
function orcToDiagnosticReport(Orc orc) returns DiagnosticReport
Parameters
- orc Orc -
orcToImmunization![](/images/permalink.svg)
function orcToImmunization(Orc orc) returns Immunization
Parameters
- orc Orc -
pd1ToExtension![](/images/permalink.svg)
Parameters
- pd16 string -
pd1ToGeneralPractitioner![](/images/permalink.svg)
pd1ToPatient![](/images/permalink.svg)
Parameters
- pd1 Pd1 -
pidToAddress![](/images/permalink.svg)
pidToAdministrativeSex![](/images/permalink.svg)
function pidToAdministrativeSex(string pid8) returns PatientGender
Parameters
- pid8 string -
pidToBirthOrder![](/images/permalink.svg)
pidToBirthPlace![](/images/permalink.svg)
Parameters
- pid23 string -
pidToMaritalStatus![](/images/permalink.svg)
Parameters
- pid16 Pid16 -
pidToMultipleBirthIndicator![](/images/permalink.svg)
Parameters
- pid24 string -
pidToPatient![](/images/permalink.svg)
Parameters
- pid Pid -
pidToPatientDeathIndicator![](/images/permalink.svg)
Parameters
- pid30 string -
pidToPatientName![](/images/permalink.svg)
pidToPhoneNumber![](/images/permalink.svg)
function pidToPhoneNumber(Pid13 pid13, Pid14 pid14) returns ContactPoint[]
pidToPrimaryLanguage![](/images/permalink.svg)
function pidToPrimaryLanguage(Pid15 pid15) returns PatientCommunication[]
Parameters
- pid15 Pid15 -
pidToSsnNumberIdentifier![](/images/permalink.svg)
function pidToSsnNumberIdentifier(string pid19) returns Identifier[]
Parameters
- pid19 string -
ptToMeta![](/images/permalink.svg)
Parameters
- pt Pt -
pv1ToEncounter![](/images/permalink.svg)
Parameters
- pv1 Pv1 -
pv1ToExtension![](/images/permalink.svg)
Parameters
- pv116 string -
pv1ToPatient![](/images/permalink.svg)
Parameters
- pv1 Pv1 -
pv2ToEncounter![](/images/permalink.svg)
Parameters
- pv2 Pv2 -
segmentToFhir![](/images/permalink.svg)
function segmentToFhir(string segmentName, Segment segment, V2SegmentToFhirMapper? customMapper) returns BundleEntry[]
Transform an HL7 segment to FHIR Bundle.
Parameters
- segmentName string - Name of the HL7 segment
- segment Segment - HL7 segment
- customMapper V2SegmentToFhirMapper? - Custom mapper implementation
Return Type
- BundleEntry[] - FHIR Bundle
stringToHl7![](/images/permalink.svg)
Parse a string to an HL7 message.
Parameters
- msg string - HL7 message as a string
tsToDateTime![](/images/permalink.svg)
Parameters
- ts Ts -
tsToInstant![](/images/permalink.svg)
Parameters
- ts Ts -
v2ToFhir![](/images/permalink.svg)
function v2ToFhir(string|Message hl7, V2SegmentToFhirMapper? customMapper) returns json|error
Transform an HL7 message to FHIR.
Parameters
- customMapper V2SegmentToFhirMapper? (default ()) - Custom mapper implementation
Return Type
- json|error - FHIR Bundle as a json
xadToAddress![](/images/permalink.svg)
Parameters
- xad Xad -
xcnToCodeableConcept![](/images/permalink.svg)
function xcnToCodeableConcept(Xcn xcn) returns CodeableConcept
Parameters
- xcn Xcn -
xcnToReference![](/images/permalink.svg)
Parameters
- xcn Xcn -
xonToOrganization![](/images/permalink.svg)
function xonToOrganization(Xon xon) returns Organization
Parameters
- xon Xon -
xpnToHumanName![](/images/permalink.svg)
Parameters
- xpn Xpn -
xtnToContactPoint![](/images/permalink.svg)
function xtnToContactPoint(Xtn xtn) returns ContactPoint
Parameters
- xtn Xtn -
Records![](/images/permalink.svg)
health.hl7v2.utils.v2tofhirr4: V2SegmentToFhirMapper![](/images/permalink.svg)
V2toFHIR Mapper function implementation holder record.
Fields
- pv1ToPatient Pv1ToPatient? - PV1 segment to Patient FHIR resource mapping function
- pv1ToEncounter Pv1ToEncounter? - PV1 segment to Encounter FHIR resource mapping function
- nk1ToPatient Nk1ToPatient? - NK1 segment to Patient FHIR resource mapping function
- pd1ToPatient Pd1ToPatient? - PD1 segment to Patient FHIR resource mapping function
- pidToPatient PidToPatient? - PID segment to Patient FHIR resource mapping function
- dg1ToCondition Dg1ToCondition? - DG1 segment to Condition FHIR resource mapping function
- obxToObservation ObxToObservation? - OBX segment to Observation FHIR resource mapping function
- obrToDiagnosticReport ObrToDiagnosticReport? - OBR segment to DiagnosticReport FHIR resource mapping function
- al1ToAllerygyIntolerance Al1ToAllerygyIntolerance? - AL1 segment to AllergyIntolerance FHIR resource mapping function
- evnToProvenance EvnToProvenance? - EVN segment to Provenance FHIR resource mapping function
- mshToMessageHeader MshToMessageHeader? - MSH segment to MessageHeader FHIR resource mapping function
- pv2ToEncounter Pv2ToEncounter? - PV2 segment to Encounter FHIR resource mapping function
- orcToImmunization OrcToImmunization? - ORC segment to Immunization FHIR resource mapping function
Union types![](/images/permalink.svg)
health.hl7v2.utils.v2tofhirr4: Al1![](/images/permalink.svg)
DeprecatedAl1
Union type for holding patient allergy information segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Ce![](/images/permalink.svg)
Ce
Union type for CE data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Cwe![](/images/permalink.svg)
Cwe
Union type for CWE data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Dg1![](/images/permalink.svg)
DeprecatedDg1
Union type for holding patient visit segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Dtm![](/images/permalink.svg)
Dtm
Union type for DTM data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Ei![](/images/permalink.svg)
Ei
Union type for EI data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Evn![](/images/permalink.svg)
DeprecatedEvn
Union type for holding event type segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Hd![](/images/permalink.svg)
Hd
Union type for HD data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Id![](/images/permalink.svg)
Id
Union type for ID data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Is![](/images/permalink.svg)
Is
Union type for IS data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Msh![](/images/permalink.svg)
DeprecatedMsh
Union types for holding hl7 segments for supported hl7 versions.
######################################################################## Union type for holding message header segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk1![](/images/permalink.svg)
DeprecatedNk1
Union type for holding next of kin segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk113![](/images/permalink.svg)
DeprecatedNk113
Union type for patient's extended person's organization name for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk115![](/images/permalink.svg)
DeprecatedNk115
Union type for patient's extended person's gender for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk12![](/images/permalink.svg)
DeprecatedNk12
Union type for patient's extended person's name for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk130![](/images/permalink.svg)
DeprecatedNk130
Union type for patient's extended person's contact person name for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk131![](/images/permalink.svg)
DeprecatedNk131
Union type for patient's extended person's contact person phone number for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk132![](/images/permalink.svg)
DeprecatedNk132
Union type for patient's extended person's contact person address for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk14![](/images/permalink.svg)
DeprecatedNk14
Union type for patient's extended person's address for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk15![](/images/permalink.svg)
DeprecatedNk15
Union type for patient's extended person's home phone number for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk16![](/images/permalink.svg)
DeprecatedNk16
Union type for patient's extended person's business phone number for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk17![](/images/permalink.svg)
DeprecatedNk17
Union type for patient's extended person's contact role for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk18![](/images/permalink.svg)
DeprecatedNk18
Union type for patient's extended person's start date for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Nk19![](/images/permalink.svg)
DeprecatedNk19
Union type for patient's extended person's end date for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Obr![](/images/permalink.svg)
DeprecatedObr
Union type for holding observation request segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Obx![](/images/permalink.svg)
DeprecatedObx
Union type for holding observation segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Orc![](/images/permalink.svg)
DeprecatedOrc
Union type for holding common order segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pd1![](/images/permalink.svg)
DeprecatedPd1
Union type for holding patient identification segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pd13![](/images/permalink.svg)
DeprecatedPd13
Union type for patient primary facility for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pd14![](/images/permalink.svg)
DeprecatedPd14
Union type for patient primary care provider for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid![](/images/permalink.svg)
DeprecatedPid
Union type for holding patient identification segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid11![](/images/permalink.svg)
DeprecatedPid11
Union type for holding patient address for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid13![](/images/permalink.svg)
DeprecatedPid13
Union type for holding patient home phone number for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid14![](/images/permalink.svg)
DeprecatedPid14
Union type for holding patient business phone number for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid15![](/images/permalink.svg)
DeprecatedPid15
Union type for holding patient primary language for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid16![](/images/permalink.svg)
DeprecatedPid16
Union type for holding patient marital status for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid5![](/images/permalink.svg)
DeprecatedPid5
Union types defined for data types for supported hl7 versions.
###################################################################### Union type for holding patient name for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pid9![](/images/permalink.svg)
DeprecatedPid9
Union type for holding patient alias name for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pt![](/images/permalink.svg)
Pt
Union type for PT data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Pv1![](/images/permalink.svg)
DeprecatedPv1
Union type for holding patient visit segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Pv2![](/images/permalink.svg)
DeprecatedPv2
Union type for holding patient visit additional information segment for all supported hl7 versions.
Deprecated
health.hl7v2.utils.v2tofhirr4: Ts![](/images/permalink.svg)
Ts
Union type for TS data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Xad![](/images/permalink.svg)
Xad
Union type for XAD data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Xcn![](/images/permalink.svg)
Xcn
Union type for XCN data type for all supported hl7 versions.
health.hl7v2.utils.v2tofhirr4: Xon![](/images/permalink.svg)
Xon
Union type for XON data type for all supported hl7 versions.
Import
import ballerinax/health.hl7v2.utils.v2tofhirr4;
Metadata
Released date: 11 months ago
Version: 2.0.2
Compatibility
Platform: any
Ballerina version: 2201.7.0
Pull count
Total: 27
Current verison: 4
Weekly downloads
Keywords
Healthcare
HL7
FHIR
Contributors