This page contains examples of use cases, ranging from simple to complex, that show when and how to configure a custom schema parser on an HL7v2 store. Each use case contains an HL7v2 message that the custom schema parser is based on.
Custom segment terminator and custom field
The samples in this section use a sample message that is nonstandard in the following ways:
- The sample message's segment delimiters are newlines (
\n) rather than the standard carriage returns (\r). - The sample message has a software (
SFT) segment with an additional sub-field: a custom field that specifies the URLhttps://example.com/healthcare-api/.
MSH|^~\&|My EHR|My Test Facility||My EHR Facility|20150926140551||ORU^R01^ORU_R01|My-LOI_5.0_1.1-NG|T|2.5.1|||AL|AL|||||\n
SFT|Google^D|v1|Healthcare API|1||20190601|https://example.com/healthcare-api/\n
PID|1||PATID5421^^^My MPI^MR||Zhang^Sally^Brian^^^^L||19840611|F||2106-3^White^HL70005|123 Main Street^^Mountain Springs^CO^80439^^H||^PRN^PH^^^203^2290210|||||||||N^Not Hispanic or Latino^HL70189\n
ORC|RE|833582639|3266238193||CM||||20101234567890\n
OBR|1|833582639|3266238193|us-0005^Vital Signs^WinPath^^||20101234567890|20101234567890|||||||20101234567890||||||||20101234567890|||F||1\n
OBX|1|NM|tt-0005-07^MDC_PULS_RATE_NON_INV^MDC^^||52.31|MDC_DIM_BEAT_PER_MIN|50-200||||F|||20101234567890||\n
OBX|2|NM|tt-0005-12^PAIN LEVEL^L^^||1.71|/10|1-10||||F|||20101234567890||\n
OBX|3|NM|tt-0005-09^MDC_TEMP^MDC^^||36.22|MDC_DIM_DEGC|36-38||||F|||20101234567890||\n
Update an HL7v2 store with the custom segment terminator
You must specify the
segment terminator
if your messages use a nonstandard terminator like the sample message provided
in Custom segment terminator and custom field.
The sample message uses the nonstandard \n as its segment terminator.
The following samples show how to configure segmentTerminator in
ParserConfig when you
create an HL7v2 store.
The segment terminator is set to Cg==, which is the base-64 encoding of
\n.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"parserConfig": {
"segmentTerminator": "Cg==""
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"parserConfig": {
"segmentTerminator": "Cg==""
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"parserConfig": {
"segmentTerminator": "Cg==""
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Update an HL7v2 store with the custom schema
You can update an HL7v2 store with a custom schema defined in JSON format.
After configuring a custom schema that includes the additional
field in the SFT segment, you can ingest the sample message.
For information about specifying a custom field, see
SchemaPackage.
The configuration specified in this sample has the following behavior:
- Rewrites the
SFTsegment definition to have the URL field as field7. - The
versionfilter determines which incoming messages the custom schema applies to based on a field in the message segment header (MSH). If you don't supply aversionfilter, the schema is applied to all HL7v2 messages in the HL7v2 store. In this sample, the customSFTsegment applies when the sending application field containsMy EHR. - The field for the additional field is named
7for consistency with the rest of the specification. You could also name itURLto be more descriptive.
To update the store with the custom schema, use the
projects.locations.datasets.hl7V2Stores.patch
method.
Before using any of the request data, make the following replacements:
- PROJECT_ID: the ID of your Google Cloud project
- LOCATION: the dataset location
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"types": [
{
"version": [
{
"mshField": "3.1",
"value": "My EHR"
}
],
"type": [
{
"name": "SFT",
"fields": [
{
"name": "1",
"type": "XON",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "2",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "3",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "4",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "5",
"type": "TX",
"maxOccurs": 1
},
{
"name": "6",
"type": "DTM",
"maxOccurs": 1
},
{
"name": "7",
"type": "ST",
"maxOccurs": 1
}
]
}
]
}
]
},
"version": "V3"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"types": [
{
"version": [
{
"mshField": "3.1",
"value": "My EHR"
}
],
"type": [
{
"name": "SFT",
"fields": [
{
"name": "1",
"type": "XON",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "2",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "3",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "4",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "5",
"type": "TX",
"maxOccurs": 1
},
{
"name": "6",
"type": "DTM",
"maxOccurs": 1
},
{
"name": "7",
"type": "ST",
"maxOccurs": 1
}
]
}
]
}
]
},
"version": "V3"
}
}
EOFThen execute the following command to send your REST request:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID?updateMask=parser_config.schema"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"types": [
{
"version": [
{
"mshField": "3.1",
"value": "My EHR"
}
],
"type": [
{
"name": "SFT",
"fields": [
{
"name": "1",
"type": "XON",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "2",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "3",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "4",
"type": "ST",
"minOccurs": 1,
"maxOccurs": 1
},
{
"name": "5",
"type": "TX",
"maxOccurs": 1
},
{
"name": "6",
"type": "DTM",
"maxOccurs": 1
},
{
"name": "7",
"type": "ST",
"maxOccurs": 1
}
]
}
]
}
]
},
"version": "V3"
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID?updateMask=parser_config.schema" | Select-Object -Expand Content
V3 version of the parser.
Ingest and parse the HL7v2 message using the custom schema
The following samples show how to ingest a base-64 encoded version of the HL7v2 message
from Custom segment terminator and custom field.
To ingest the HL7v2 message, you use the
projects.locations.datasets.hl7V2Stores.messages.ingest
method.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"message": {
"data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"message": {
"data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"message": {
"data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest" | Select-Object -Expand Content
ORU_R01.SFT.7 field.
Parser heuristics using a custom segment
The following sample shows how the HL7v2 parser uses heuristics to parse a message with minor configuration on the HL7v2 store.
The sample uses the following HL7v2 message:
MSH|^~\&$|||||||ADT^A01|||2.1
EVN|\P\\L\\H\\N\
PID|1
ZCD|1
The HL7v2 message is non-standard because the ZCD segment is not defined
in the HL7v2 standard.
Create an HL7v2 store with the custom schema
To create an HL7v2 store with the custom schema, use the
projects.locations.datasets.hl7V2Stores.create
method.
Note that the configuration only uses the following
three fields and no schemas or types array:
"unexpectedSegmentHandling": "PARSE""ignoreMinOccurs": "true""schematizedParsingType": "HARD_FAIL"
Without specifying anything else about the message definition or its types,
the HL7v2 parser determines that the message is an ADT_A01 message and
parses the MSH, EVN, and PID segments, and the custom ZCD segment.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"parserConfig": {
"schema": {
"unexpectedSegmentHandling": "PARSE",
"ignoreMinOccurs": "true",
"schematizedParsingType": "HARD_FAIL"
}
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"parserConfig": {
"schema": {
"unexpectedSegmentHandling": "PARSE",
"ignoreMinOccurs": "true",
"schematizedParsingType": "HARD_FAIL"
}
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"parserConfig": {
"schema": {
"unexpectedSegmentHandling": "PARSE",
"ignoreMinOccurs": "true",
"schematizedParsingType": "HARD_FAIL"
}
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Ingest and parse the HL7v2 message using the custom schema
Ingest the base 64-encoded version of the HL7v2 message.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"message": {
"data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"message": {
"data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"message": {
"data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Parser using an HL7v2 message with missing fields
The following sample shows how to use type and group definitions to parse this HL7v2 message:
MSH|^~\&|||||20100101000000||ORM^O01^O01|23701|1|2.3||
PID|11|SMITH
PV1|11
PID|22|JOHN
PV1|22
ORC|3
OBX|4
NTE|5
NTE|6
OBX|7
NTE|8
The HL7v2 message is non-standard because it only uses a few fields (in some cases a single field)
in all segments except MSH. For example, the HL7v2 standard requires the PID segment
to contain fields such as the patient's primary language, address, and
date of birth, but the PID segments in the sample message only contain
an ID for the patient and the patient's first or last name.
The HL7v2 message follows the HL7 syntax, but is otherwise nearly entirely customized.
Create an HL7v2 store with the custom schema
Before creating an HL7v2 store with the custom schema, read through the
following properties of the ParserConfig object which is used in the schema:
schemas array:
- The
mshFieldis set to the 12th field (separated by a pipe|character) of the first segment in the message. The value of the field is2.3. As a result, theschemayou supply to the HL7v2 store will apply to any HL7v2 message corresponding to themshFieldandvalue. - The message type,
ORM, is specified with amembersarray containing the following information:- The segment type for the
ORMmessage is the message segment header, orMSH - A group named "Patient" which has a
maxOccursof 2.- Another
membersgroup nested under the "Patient" group that contains the type of segment that matches to the "Patient" group. That segment type isPID. - Another group named "Patient Visit". Like "Patient", there is a segment matching "Patient Visit". That segment type is
PV1.
- Another
- A group named "Order" which has no maximum or minimum of occurrences.
- Another
membersgroup nested under the "Order" group that contains the type of segment that matches to the "Order" group. That segment type isORC. - Another group named "Observation", which has its own
membersarray.- The
membersarray contains two segments that map to "Observation":OBXandNTE.OBXhas amaxOccursof1.
- The
- Another
- The segment type for the
types array:
- Like the
schemasarray,mshFieldis set to the 12th field (separated by a pipe|character) of the first segment in the message. The value of the field is2.3. As a result, thetypesyou supply to the HL7v2 store will apply to any HL7v2 message corresponding to themshFieldandvalue. - The
STandSIdata types are declared asSTRINGprimitives. Because onlySTandSIare declared, you can tell that the message has no custom types. - The
Patientgroup has amaxOccursof2and a segment type ofPID, so two types are declared in the fieldsPID. Both types areSI. - The remaining segment types are listed with their relevant fields and types. All of the remaining segments have a single occurrence and use the
SItype.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"unexpectedSegmentHandling": "PARSE",
"schemas": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"messageSchemaConfigs": {
"ORM_O01": {
"name": "ORM_O01",
"members": [
{
"segment": {
"type": "MSH"
}
},
{
"group": {
"name": "Patient",
"maxOccurs": 2,
"members": [
{
"segment": {
"type": "PID"
}
},
{
"group": {
"name": "Patient Visit",
"members": [
{
"segment": {
"type": "PV1"
}
}
]
}
}
]
}
},
{
"group": {
"name": "Order",
"members": [
{
"segment": {
"type": "ORC"
}
},
{
"group": {
"name": "Observation",
"members": [
{
"segment": {
"type": "OBX",
"maxOccurs": 1
}
},
{
"segment": {
"type": "NTE"
}
}
]
}
}
]
}
}
]
}
}
}
],
"types": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"type": [
{
"name": "ST",
"primitive": "STRING"
},
{
"name": "SI",
"primitive": "STRING"
},
{
"name": "PID",
"fields": [
{
"name": "1",
"type": "SI"
},
{
"name": "2",
"type": "SI"
}
]
},
{
"name": "PV1",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "ORC",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "OBX",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "NTE",
"fields": [
{
"name": "1",
"type": "SI"
}
]
}
]
}
],
},
"version": "V3"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"unexpectedSegmentHandling": "PARSE",
"schemas": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"messageSchemaConfigs": {
"ORM_O01": {
"name": "ORM_O01",
"members": [
{
"segment": {
"type": "MSH"
}
},
{
"group": {
"name": "Patient",
"maxOccurs": 2,
"members": [
{
"segment": {
"type": "PID"
}
},
{
"group": {
"name": "Patient Visit",
"members": [
{
"segment": {
"type": "PV1"
}
}
]
}
}
]
}
},
{
"group": {
"name": "Order",
"members": [
{
"segment": {
"type": "ORC"
}
},
{
"group": {
"name": "Observation",
"members": [
{
"segment": {
"type": "OBX",
"maxOccurs": 1
}
},
{
"segment": {
"type": "NTE"
}
}
]
}
}
]
}
}
]
}
}
}
],
"types": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"type": [
{
"name": "ST",
"primitive": "STRING"
},
{
"name": "SI",
"primitive": "STRING"
},
{
"name": "PID",
"fields": [
{
"name": "1",
"type": "SI"
},
{
"name": "2",
"type": "SI"
}
]
},
{
"name": "PV1",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "ORC",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "OBX",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "NTE",
"fields": [
{
"name": "1",
"type": "SI"
}
]
}
]
}
],
},
"version": "V3"
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"parserConfig": {
"schema": {
"schematizedParsingType": "HARD_FAIL",
"unexpectedSegmentHandling": "PARSE",
"schemas": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"messageSchemaConfigs": {
"ORM_O01": {
"name": "ORM_O01",
"members": [
{
"segment": {
"type": "MSH"
}
},
{
"group": {
"name": "Patient",
"maxOccurs": 2,
"members": [
{
"segment": {
"type": "PID"
}
},
{
"group": {
"name": "Patient Visit",
"members": [
{
"segment": {
"type": "PV1"
}
}
]
}
}
]
}
},
{
"group": {
"name": "Order",
"members": [
{
"segment": {
"type": "ORC"
}
},
{
"group": {
"name": "Observation",
"members": [
{
"segment": {
"type": "OBX",
"maxOccurs": 1
}
},
{
"segment": {
"type": "NTE"
}
}
]
}
}
]
}
}
]
}
}
}
],
"types": [
{
"version": [
{
"mshField": "12",
"value": "2.3"
}
],
"type": [
{
"name": "ST",
"primitive": "STRING"
},
{
"name": "SI",
"primitive": "STRING"
},
{
"name": "PID",
"fields": [
{
"name": "1",
"type": "SI"
},
{
"name": "2",
"type": "SI"
}
]
},
{
"name": "PV1",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "ORC",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "OBX",
"fields": [
{
"name": "1",
"type": "SI"
}
]
},
{
"name": "NTE",
"fields": [
{
"name": "1",
"type": "SI"
}
]
}
]
}
],
},
"version": "V3"
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores?hl7V2StoreId=HL7V2_STORE_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
Ingest and parse the HL7v2 message using the custom schema
Ingest a base64-encoded version of the HL7v2 message.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- LOCATION: the location of the parent dataset
- DATASET_ID: the HL7v2 store's parent dataset
- HL7V2_STORE_ID: the HL7v2 store ID
Request JSON body:
{
"message": {
"data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
}
}
To send your request, choose one of these options:
curl
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
cat > request.json << 'EOF'
{
"message": {
"data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
}
}
EOFThen execute the following command to send your REST request:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest"
PowerShell
Save the request body in a file named request.json.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@'
{
"message": {
"data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
}
}
'@ | Out-File -FilePath request.json -Encoding utf8Then execute the following command to send your REST request:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/hl7V2Stores/HL7V2_STORE_ID/messages:ingest" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
For a more readable version of the data field in the response, expand the
following section:
Expand
{
"data": {
"ORM_O01": [
{
"MSH": [
{
"0": "MSH",
"1": "|",
"2": "^~\\\\\\u0026",
"3": null,
"4": null,
"5": null,
"6": null,
"7": "20100101000000",
"8": null,
"9": {
"1": "ORM",
"2": "O01",
"3": "O01"
},
"10": "23701",
"11": {
"1": "1"
},
"12": {
"1": "2.3"
},
"13": null,
"14": null
}
],
"Order": [
{
"ORC": [
{
"0": "ORC",
"1": [
"3"
]
}
],
"Observation": [
{
"NTE": [
{
"0": "NTE",
"1": [
"5"
]
},
{
"0": "NTE",
"1": [
"6"
]
}
],
"OBX": {
"0": "OBX",
"1": [
"4"
]
}
},
{
"NTE": [
{
"0": "NTE",
"1": [
"8"
]
}
],
"OBX": {
"0": "OBX",
"1": [
"7"
]
}
}
]
}
],
"Patient": [
{
"PID": [
{
"0": "PID",
"1": [
"11"
],
"2": [
"SMITH"
]
}
],
"Patient Visit": [
{
"PV1": [
{
"0": "PV1",
"1": [
"11"
]
}
]
}
]
},
{
"PID": [
{
"0": "PID",
"1": [
"22"
],
"2": [
"JOHN"
]
}
],
"Patient Visit": [
{
"PV1": [
{
"0": "PV1",
"1": [
"22"
]
}
]
}
]
}
]
}
]
}
}