自定义架构解析器示例

本页面介绍从简单到复杂的各种用例示例,展示了在 HL7v2 存储区中配置自定义架构解析器的时间和方式。每个用例均包含自定义架构解析器所基于的 HL7v2 消息。

自定义细分终止符和自定义字段

本部分中的示例使用非标准消息示例,具体示例如下:

  • 示例消息的细分终止符是换行符 (\n),而不是标准回车符 (\r)。
  • 示例消息包含一个软件 SFT 细分,其中有一个额外的子字段:指定网址 https://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

使用自定义细分终止符更新 HL7v2 存储区

如果您的消息使用非标准终止符(如自定义细分终止符和自定义字段中提供的示例消息),您必须指定细分终止符。示例消息使用非标准 \n 作为其细分终止符。

以下示例展示了在创建 HL7v2 存储区时,如何在在 ParserConfig 中配置 segmentTerminator。 细分终止符设置为 Cg==,即 \n 的 base-64 编码。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

{
  "parserConfig": {
    "segmentTerminator": "Cg==""
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "parserConfig": {
    "segmentTerminator": "Cg==""
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "parserConfig": {
    "segmentTerminator": "Cg==""
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$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

您应该收到类似以下内容的 JSON 响应:

使用自定义架构更新 HL7v2 存储区

您可以使用以 JSON 格式定义的自定义架构更新 HL7v2 存储区。在配置 SFT 细分中包含额外字段的自定义架构后,您可以注入示例消息。如需了解如何指定自定义元素,请参阅 SchemaPackage

此示例中指定的配置具有以下行为:

  • 重写 SFT 细分定义,使其网址字段为字段 7
  • version 过滤条件根据消息细分标头 (MSH) 中的字段确定自定义架构适用于哪些传入消息。如果未提供 version 过滤条件,则该架构适用于 HL7v2 存储区中的所有 HL7v2 消息。在此示例中,如果发送应用字段包含 My EHR,则自定义 SFT 细分适用。
  • 此额外字段命名为 7,以便与规范的其余部分保持一致。您也可以将其命名为 URL,使其更具描述性。

要使用自定义架构更新存储区,请使用 projects.locations.datasets.hl7V2Stores.patch 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目的 ID
  • LOCATION:数据集位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

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

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

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"
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "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 utf8

然后,执行以下命令以发送 REST 请求:

$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 版本的解析器。

使用自定义架构注入和解析 HL7v2 消息

以下示例展示了如何从自定义细分终止符和自定义字段中注入 base-64 编码版本的 HL7v2 消息。如需注入 HL7v2 消息,请使用 projects.locations.datasets.hl7V2Stores.messages.ingest 方法。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

{
  "message": {
    "data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "message": {
    "data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "message": {
    "data": "TVNIfF5+XCZ8TXkgRUhSfE15IFRlc3QgRmFjaWxpdHl8fE15IEVIUiBGYWNpbGl0eXwyMDE1MDkyNjE0MDU1MXx8T1JVXlIwMV5PUlVfUjAxfE15LUxPSV81LjBfMS4xLU5HfFR8Mi41LjF8fHxBTHxBTHx8fHx8ClNGVHxHb29nbGVeRHx2MXxIZWFsdGhjYXJlIEFQSXwxfHwyMDE5MDYwMXxodHRwczovL2V4YW1wbGUuY29tL2hlYWx0aGNhcmUvClBJRHwxfDQwOTAzMzEzMjBeXl5TSU1VTEFUT1IgTVJOXk1STnw0MDkwMzMxMzIwXl5eU0lNVUxBVE9SIE1STl5NUk5+Mjg4ODUyNzE1NF5eXk5IU05CUl5OSFNOTUJSfHxEYXZpc15DaGVsc2VhXl5eTWlzc15eQ1VSUkVOVHx8MjAwOTEwMTcwMDAwMDB8Rnx8fDE4MSBUcmFuc21pc3Npb24gUm9hZF5eTG9uZG9uXl5LRzIyIDlIWF5HQlJeSE9NRXx8MDIwIDgxMjIgOTk0N15IT01FfHx8fHx8fHx8SF5Bc2lhbiBvciBBc2lhbiBCcml0aXNoIC0gSW5kaWFuXl5efHx8fHx8fHwKUFYxfDF8SXxPdGhlcldhcmReTWFpblJvb21eQmVkIDFeU2ltdWxhdGVkIEhvc3BpdGFsXl5CRUReTWFpbiBCdWlsZGluZ140fDI4Ynx8fEMwMDNeQ3VkZHleS2V2aW5eXl5Ecl5eXkRSTkJSXlBSU05MXl5eT1JHRFJ8fHxVUk98fHx8fHx8fHwxMjUxMzI0NzIzMjIzODk0ODc4M15eXl52aXNpdGlkfHx8fHx8fHx8fHx8fHx8fHx8fHx8fEFSUklWRUR8fHwyMDIwMDUwNjE3MDgyMnx8Ck9SQ3xSRXw4MzM1ODI2Mzl8MzI2NjIzODE5M3x8Q018fHx8MjAyMDA1MDYxNzA4MjIKT0JSfDF8ODMzNTgyNjM5fDMyNjYyMzgxOTN8dXMtMDAwNV5WaXRhbCBTaWduc15XaW5QYXRoXl58fDIwMjAwNTA2MTcwODIyfDIwMjAwNTA2MTcwODIyfHx8fHx8fDIwMjAwNTA2MTcwODIyfHx8fHx8fHwyMDIwMDUwNjE3MDgyMnx8fEZ8fDEKT0JYfDF8VFh8dHQtMDAwNS0xMV5PeHlnZW5EZXZeV2VsY2hBbGx5bl5efHxWZW50dXJpfHx8fHx8Rnx8fDIwMjAwNTA2MTcwODIyfHwK"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$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
由于 HL7v2 消息的架构与 HL7v2 存储区的架构相匹配,因此响应会包含一个在 ORU_R01.SFT.7 字段中具有自定义网址的 JSON 字符串。

解析器启发法使用自定义细分

以下示例展示了 HL7v2 解析器如何使用启发法解析在 HL7v2 存储区中具有次要配置的消息。

该示例使用以下 HL7v2 消息:

MSH|^~\&$|||||||ADT^A01|||2.1
EVN|\P\\L\\H\\N\
PID|1
ZCD|1

HL7v2 消息是非标准的,因为未在 HL7v2 标准中定义 ZCD 细分。

创建使用自定义架构的 HL7v2 存储区

如需使用自定义架构创建 HL7v2 存储区,请使用 projects.locations.datasets.hl7V2Stores.create 方法。

请注意,该配置仅使用以下三个字段,且不包含 schemastypes 数组:

  • "unexpectedSegmentHandling": "PARSE"
  • "ignoreMinOccurs": "true"
  • "schematizedParsingType": "HARD_FAIL"

如果未指定有关消息定义或其类型的任何内容,则 HL7v2 解析器会确定消息是 ADT_A01 消息,并解析 MSHEVNPID 细分以及自定义 ZCD 细分。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

{
  "parserConfig": {
    "schema": {
      "unexpectedSegmentHandling": "PARSE",
      "ignoreMinOccurs": "true",
      "schematizedParsingType": "HARD_FAIL"
    }
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "parserConfig": {
    "schema": {
      "unexpectedSegmentHandling": "PARSE",
      "ignoreMinOccurs": "true",
      "schematizedParsingType": "HARD_FAIL"
    }
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "parserConfig": {
    "schema": {
      "unexpectedSegmentHandling": "PARSE",
      "ignoreMinOccurs": "true",
      "schematizedParsingType": "HARD_FAIL"
    }
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$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

您应该收到类似以下内容的 JSON 响应:

使用自定义架构注入和解析 HL7v2 消息

注入 base 64 编码版本的 HL7v2 消息。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

{
  "message": {
    "data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "message": {
    "data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "message": {
    "data": "TVNIfF5+XCYkfHx8fHx8fEFEVF5BMDF8fHwyLjENRVZOfFxQXExcSFxOXA1QSUR8MQ1aQ0R8MQ=="
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$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

您应该收到类似以下内容的 JSON 响应:

解析器使用缺少字段的 HL7v2 消息

以下示例展示了如何使用类型和组定义来解析 HL7v2 消息:

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

HL7v2 消息是非标准的,因为它仅使用除 MSH 之外的其他所有细分中的几个字段(在某些情况下是单个字段)。例如,HL7v2 标准要求 PID 细分包含患者的主要语言、地址和出生日期等字段,但示例消息中的 PID 细分仅包含患者的 ID 以及患者的名字或姓氏。

HL7v2 消息遵循 HL7 语法,但几乎完全自定义。

创建使用自定义架构的 HL7v2 存储区

在使用自定义架构创建 HL7v2 存储区之前,请仔细查看架构中使用的 ParserConfig 对象的以下属性:

schemas 数组:

  • mshField 设置为消息中第一个细分的第 12 个字段(由竖线 | 字符分隔)。该字段的值为 2.3。因此,为 HL7v2 存储区提供的 schema 将应用于任何与 mshFieldvalue 对应的 HL7v2 消息。
  • 消息类型 ORM 通过包含以下信息的 members 数组指定:
    • ORM 消息的细分类型为消息细分标头,或 MSH
    • 一个名为“患者”的组,其 maxOccurs 为 2。
      • 另一个嵌套在“患者”组下的 members 组,其中包含与“患者”组匹配的细分类型。该细分类型为 PID
      • 另一个名为“患者就诊”的组。与“患者”类似,存在与“患者就诊”匹配的细分。该细分类型为 PV1
    • 一个名为“订单”的组,其出现次数没有上限或下限。
      • 另一个嵌套在“订单”组下的 members 组,其中包含与“订单”组匹配的细分类型。该细分类型为 ORC
      • 另一个名为“观察对象”的组,它有自己的 members 数组。
        • members 数组包含两个映射到“观察对象”的细分:OBXNTEOBXmaxOccurs1

types 数组:

  • schemas 数组类似,mshField 设置为消息中第一个细分的第 12 个字段(由竖线 | 字符分隔)。该字段的值为 2.3。因此,为 HL7v2 存储区提供的 types 将应用于任何与 mshFieldvalue 对应的 HL7v2 消息。
  • STSI 数据类型声明为 STRING 基元。由于系统只声明了 STSI,因此可以确定消息没有自定义类型。
  • Patient 组的 maxOccurs2,细分类型为 PID,因此字段 PID 中声明了两种类型。这两种类型均为 SI
  • 系统会列出其余细分受众群类型及其相关字段和类型。其余的所有细分只出现一次,并使用 SI 类型。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

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

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

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"
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "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 utf8

然后,执行以下命令以发送 REST 请求:

$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

您应该收到类似以下内容的 JSON 响应:

使用自定义架构注入和解析 HL7v2 消息

注入 base64 编码版本的 HL7v2 消息。

在使用任何请求数据之前,请先进行以下替换:

  • PROJECT_ID:您的 Google Cloud 项目 ID
  • LOCATION:父级数据集的位置
  • DATASET_ID:HL7v2 存储区的父数据集
  • HL7V2_STORE_ID:HL7v2 存储区 ID

请求 JSON 正文:

{
  "message": {
    "data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

cat > request.json << 'EOF'
{
  "message": {
    "data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
  }
}
EOF

然后,执行以下命令以发送 REST 请求:

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

将请求正文保存在名为 request.json 的文件中。在终端中运行以下命令,在当前目录中创建或覆盖此文件:

@'
{
  "message": {
    "data": "TVNIfF5+XCZ8fHx8fDIwMTAwMTAxMDAwMDAwfHxPUk1eTzAxXk8wMXwyMzcwMXwxfDIuM3x8DVBJRHwxMXxTTUlUSA1QVjF8MTENUElEfDIyfEpPSE4NUFYxfDIyDU9SQ3wzDU9CWHw0DU5URXw1DU5URXw2DU9CWHw3DU5URXw4"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

然后,执行以下命令以发送 REST 请求:

$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

您应该收到类似以下内容的 JSON 响应:

如需查看响应中 data 字段的可读版本,请展开以下部分:

展开

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