parsing-hl7v2-messages
하는 일
이 스킬은 에이전트에게 HL7 v2 메시지를 읽는 방법을 가르칩니다. HL7 v2는 병원이 검사 결과와 환자 이벤트에 쓰는 파이프(|)로 구분된 형식입니다. 검토할 수 있도록 메시지 안의 자유 텍스트 노트를 꺼냅니다.
사용하는 경우
- ✓사용자가 인터페이스 피드에서 검사나 병원 메시지를 받고 그 안의 노트 텍스트가 필요할 때.
- ✓검사 보고서 메시지의 결과 설명을 읽을 수 있는 텍스트로 바꾸고 싶을 때.
- ✓MDM 메시지에서 받아쓴 보고서를 코드와 분리해서 얻어야 할 때.
스킬 링크
https://github.com/maziyarpanahi/openmed/blob/master/skills/parsing-hl7v2-messages/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“병원 피드의 HL7 메시지에서 검사 설명과 노트를 뽑아 주실 수 있나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
에이전트는 각 메시지를 세그먼트와 필드로 나눈 다음, 노트 필드인 OBX와 NTE를 읽고, 거기에 담긴 일반 텍스트를 돌려줍니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
Parsing HL7 v2 Messages for OpenMed
HL7 v2.x is the workhorse of hospital interfacing — ADT (admit/discharge/ transfer), ORU (observation results), MDM (document management), and ORM (orders) messages flow continuously between EHR, lab, radiology, and ancillary systems. The clinical narrative you want for NLP is buried in OBX-5 (observation value) and NTE-3 (notes/comments) fields, wrapped in a pipe-and-caret encoding. This skill decodes that envelope and hands the free text to OpenMed.
When to use
- You receive HL7 v2 messages from an interface engine (Mirth/NextGen Connect, Rhapsody, Cloverleaf) and want to mine embedded note/result text.
- A lab feed (ORU^R01) carries impression/comment narrative in OBX/NTE.
- An MDM^T02 transcription message carries a full report in OBX-5.
- You need a de-identified, structured feed into
openmed.analyze_text.
HL7 v2 structure in one minute
A message is segments separated by \r (carriage return). Each segment is
3-letter-named, then fields split by |, components by ^,
repetitions by ~, sub-components by &, with \ as escape. The
encoding characters are declared in MSH-1 (the field separator) and
MSH-2 (^~\&). Field positions are one-based, and MSH is special:
MSH-1 is the separator, so MSH-2 is the first real field.
MSH|^~\&|LAB|HOSP|EHR|HOSP|20240302101500||ORU^R01|MSG0001|P|2.5
PID|1||MRN12345^^^HOSP^MR||DOE^JANE^Q||19700115|F|||1 FAKE ST^^SPRINGFIELD^IL^62704
OBR|1||ORD9|CBC^Complete Blood Count
OBX|1|TX|IMPRESSION||Mild leukocytosis; clinically correlate.||||||F
NTE|1||Patient reports fatigue x1 week. Dr. Smith notified.
Quick start
Parse the envelope and pull narrative from OBX-5 / NTE-3, then hand off:
import openmed
from openmed.interop.hl7v2 import parse_hl7v2
raw = open("results.hl7", encoding="utf-8").read()
msg = parse_hl7v2(raw) # -> HL7Message (segments preserved)
narrative_chunks = []
for seg in msg.segments:
if seg.name == "OBX":
# OBX-2 is the value type; OBX-5 is the observation value.
value_type = seg.get_field(2)
if value_type in {"TX", "FT", "CE", "ST"}:
narrative_chunks.append(seg.get_field(5) or "")
elif seg.name == "NTE":
narrative_chunks.append(seg.get_field(3) or "")
# Decode component delimiters into plain text before NLP.
flat = "\n".join(c.replace("^", " ").replace("&", " ") for c in narrative_chunks if c)
# Hand the narrative to OpenMed.
deid = openmed.deidentify(flat, method="replace", policy="hipaa_safe_harbor")
result = openmed.analyze_text(deid.text, output_format="dict")
HL7Segment.get_field(position) uses one-based HL7 positions and returns
None for absent fields. HL7Message.segment_names() lists segments in order.
Whole-message segment-aware de-identification
When you need to redact the entire message (structured PID/NK1/GT1 fields and OBX/NTE free text) while preserving HL7 framing, use the bundled redactor instead of hand-rolling it:
from openmed.interop.hl7v2 import redact_hl7v2
safe = redact_hl7v2("results.hl7") # path or message text
# PID-3 hashed, PID-5 name surrogated, PID-7 DOB date-shifted, OBX-5/NTE-3
# free text masked via openmed.deidentify — delimiters and segment order kept.
redact_hl7v2 applies DEFAULT_FIELD_MAP (PID, PD1, NK1, GT1, IN1/IN2, OBX,
NTE). Extend or override it with field_map={("ZPS", 4): {"action": "hash"}}
for site-specific Z-segments, and pass date_shift_days= for a fixed,
interval-preserving shift.
Workflow
- Frame-split safely. Real feeds use
\r,\r\n, or MLLP framing (\x0b…\x1c\r).parse_hl7v2auto-detects the segment separator; strip MLLP control bytes before parsing. - Read encoding from MSH — never assume
|^~\&. The adapter derives the delimiter set from MSH-1/MSH-2 (HL7V2Encoding.from_msh_segment). - Locate narrative. OBX-5 (gated by OBX-2 value type), NTE-3, and
report-bearing segments. Concatenate repetitions (
~) and components (^). - De-identify, then analyze with OpenMed.
- Rejoin results to the patient/encounter via PID-3 (patient id) and PV1-19 (visit number) — but redact those identifiers in anything you persist.
Hand-off to / from OpenMed
- To OpenMed: flattened OBX-5/NTE-3 text →
openmed.deidentify→openmed.analyze_text. - Adapter:
openmed.interop.hl7v2providesparse_hl7v2,redact_hl7v2, `HL7
자주 묻는 질문
HL7 v2가 무엇인가요?
병원 시스템이 검사 결과, 입원, 주문을 주고받을 때 쓰는 흔한 메시지 형식입니다.
필드 코드를 알아야 하나요?
아니요. 에이전트가 구조를 알고 텍스트 필드를 쉬운 말로 보고합니다.
어떤 메시지 종류를 다루나요?
ADT, ORU, MDM, ORM 같은 흔한 종류를 다룹니다.
상세 정보
작성자의 원본 설명
Decodes pipe-delimited HL7 v2.x messages (ADT, ORU, MDM, ORM) into structured segments/fields/components and surfaces OBX-5 and NTE-3 free-text narrative for OpenMed. Use before OpenMed processing when ingesting HL7 v2 feeds from an interface engine, lab/results system, or ADT stream and you need the embedded clinical note text de-identified and analyzed. Flatten OBX/NTE text then call openmed.deidentify and openmed.analyze_text; segment-aware redaction is available via openmed.interop.hl7v2. Trigger keywords: HL7, HL7 v2, ADT, ORU, OBX, MSH, PID, pipe-delimited, interface engine, Mirth, lab r
repo: maziyarpanahi/openmed
인기도
- GitHub 스타
- 5.8k
- 순위
- #14716
- 라이선스
- Apache-2.0
- 업데이트
- 2026. 11. 2.
댓글
- …
이 저장소의 다른 스킬
annotating-variants
5.8k에이전트가 유전 변이의 효과를 예측하고, HGVS 이름을 게놈 위치로 바꾸고, 무료 공개 주석 도구를 사용해 인구 빈도를 붙이도록 돕습니다.
ask-openmed
5.8k에이전트가 임상 텍스트 요청에 맞는 OpenMed 워크플로를 고르도록 돕되, 환자 데이터가 있을 수 있으면 먼저 개인 정보 확인을 거치게 합니다.
assembling-fhir-bundles
5.8k여러 FHIR 건강 기록을 EHR로 보낼 수 있도록 하나의 트랜잭션 Bundle로 묶고, 내부 참조를 올바르게 연결하도록 에이전트를 돕습니다.
auditing-deid-leakage
5.8k비식별화된 임상 텍스트에 남은 SSN, 카드 번호, 이메일, 날짜 같은 식별자를 검사하고, 남은 것이 있으면 공개를 막도록 돕습니다.
비슷한 스킬
gitcrawl
394k에이전트가 저장된 GitHub 이슈와 풀 리퀘스트 보관본을 검색하고, 중복 항목을 묶고, GitHub에서 현재 상태를 확인하도록 돕습니다.
slacrawl
394k에이전트가 로컬 Slack 보관본에서 메시지를 검색하고 개수를 세며, 보관본이 얼마나 최신인지 확인하고 필요할 때 새로 고치도록 돕습니다.
goplaces
394k에이전트가 Google Places로 장소를 검색하고, 세부 정보와 리뷰를 가져오고, 장소 이름을 확인하며, 스크립트용 JSON을 출력하도록 돕습니다.