15.2.124. camcops_server.cc_modules.cc_hl7¶
camcops_server/cc_modules/cc_hl7.py
Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
Core HL7 functions, e.g. to build HL7 v2 messages.
General HL7 sources:
http://www.interfaceware.com/manual/v3gen_python_library_details.html
https://www.hl7.org/special/committees/vocab/v26_appendix_a.pdf
To consider
batched messages (HL7 batching protocol); https://docs.oracle.com/cd/E23943_01/user.1111/e23486/app_hl7batching.htm
note: DG1 segment = diagnosis
Basic HL7 message structure:
can package into HL7 2.X message as encapsulated PDF; https://www.hl7standards.com/blog/2007/11/27/pdf-attachment-in-hl7-message/
message ORU^R01 https://www.corepointhealth.com/resource-center/hl7-resources/hl7-messages
MESSAGES: http://www.interfaceware.com/hl7-standard/hl7-messages.html
OBX segment = observation/result segment; https://www.corepointhealth.com/resource-center/hl7-resources/hl7-obx-segment; http://www.interfaceware.com/hl7-standard/hl7-segment-OBX.html
SEGMENTS: https://www.corepointhealth.com/resource-center/hl7-resources/hl7-segments
ED field (= encapsulated data); http://www.interfaceware.com/hl7-standard/hl7-fields.html
base-64 encoding
We can then add an option for structure (XML), HTML, PDF export.
- class camcops_server.cc_modules.cc_hl7.MLLPTimeoutClient(host: str, port: int, timeout_ms: Optional[int] = None)[source]¶
Class for MLLP TCP/IP transmission that implements timeouts.
- __init__(host: str, port: int, timeout_ms: Optional[int] = None) None [source]¶
Creates MLLP client and opens socket.
- camcops_server.cc_modules.cc_hl7.escape_hl7_text(s: str) str [source]¶
Escapes HL7 special characters.
- camcops_server.cc_modules.cc_hl7.get_mod11_checkdigit(strnum: str) str [source]¶
Input: string containing integer. Output: MOD11 check digit (string).
See:
- camcops_server.cc_modules.cc_hl7.make_dg1_segment(set_id: int, diagnosis_datetime: pendulum.datetime.DateTime, coding_system: str, diagnosis_identifier: str, diagnosis_text: str, alternate_coding_system: str = '', alternate_diagnosis_identifier: str = '', alternate_diagnosis_text: str = '', diagnosis_type: str = 'F', diagnosis_classification: str = 'D', confidential_indicator: str = 'N', clinician_id_number: Optional[Union[str, int]] = None, clinician_surname: str = '', clinician_forename: str = '', clinician_middle_name_or_initial: str = '', clinician_suffix: str = '', clinician_prefix: str = '', clinician_degree: str = '', clinician_source_table: str = '', clinician_assigning_authority: str = '', clinician_name_type_code: str = '', clinician_identifier_type_code: str = '', clinician_assigning_facility: str = '', attestation_datetime: Optional[pendulum.datetime.DateTime] = None) hl7.containers.Segment [source]¶
Creates an HL7 diagnosis (DG1) segment.
Args:
set_id: Diagnosis sequence number, starting with 1 (use higher numbers for >1 diagnosis). diagnosis_datetime: Date/time diagnosis was made. coding_system: E.g. "I9C" for ICD9-CM; "I10" for ICD10. diagnosis_identifier: Code. diagnosis_text: Text. alternate_coding_system: Optional alternate coding system. alternate_diagnosis_identifier: Optional alternate code. alternate_diagnosis_text: Optional alternate text. diagnosis_type: A admitting, W working, F final. diagnosis_classification: C consultation, D diagnosis, M medication, O other, R radiological scheduling, S sign and symptom, T tissue diagnosis, I invasive procedure not classified elsewhere. confidential_indicator: Y yes, N no clinician_id_number: } Diagnosing clinician. clinician_surname: } clinician_forename: } clinician_middle_name_or_initial: } clinician_suffix: } clinician_prefix: } clinician_degree: } clinician_source_table: } clinician_assigning_authority: } clinician_name_type_code: } clinician_identifier_type_code: } clinician_assigning_facility: } attestation_datetime: Date/time the diagnosis was attested.
- camcops_server.cc_modules.cc_hl7.make_msh_segment(message_datetime: pendulum.datetime.DateTime, message_control_id: str) hl7.containers.Segment [source]¶
Creates an HL7 message header (MSH) segment.
MSH: https://www.hl7.org/documentcenter/public/wg/conf/HL7MSH.htm
We’re making an ORU^R01 message = unsolicited result.
ORU = Observational Report - Unsolicited
ORU^R01 = Unsolicited transmission of an observation message
https://www.corepointhealth.com/resource-center/hl7-resources/hl7-oru-message
https://www.hl7kit.com/joomla/index.php/hl7resources/examples/107-orur01
- camcops_server.cc_modules.cc_hl7.make_obr_segment(task: Task) hl7.containers.Segment [source]¶
Creates an HL7 observation request (OBR) segment.
- camcops_server.cc_modules.cc_hl7.make_obx_segment(req: CamcopsRequest, task: Task, task_format: str, observation_identifier: str, observation_datetime: pendulum.datetime.DateTime, responsible_observer: str, export_options: TaskExportOptions) hl7.containers.Segment [source]¶
Creates an HL7 observation result (OBX) segment.
http://www.hl7standards.com/blog/2006/10/18/how-do-i-send-a-binary-file-inside-of-an-hl7-message
http://www.hl7standards.com/blog/2007/11/27/pdf-attachment-in-hl7-message/
http://www.hl7standards.com/blog/2006/12/01/sending-images-or-formatted-documents-via-hl7-messaging/
https://www.hl7.org/documentcenter/public/wg/ca/HL7ClmAttIG.PDF
type of data: https://www.hl7.org/implement/standards/fhir/v2/0191/index.html
subtype of data: https://www.hl7.org/implement/standards/fhir/v2/0291/index.html
- camcops_server.cc_modules.cc_hl7.make_pid_segment(forename: str, surname: str, dob: pendulum.date.Date, sex: str, address: str, patient_id_list: Optional[List[camcops_server.cc_modules.cc_simpleobjects.HL7PatientIdentifier]] = None) hl7.containers.Segment [source]¶
Creates an HL7 patient identification (PID) segment.