Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
7
70102 Peace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Midha, Rohit
70102 Peace
Commits
fed72bef
Commit
fed72bef
authored
1 year ago
by
ur23
Browse files
Options
Downloads
Patches
Plain Diff
parsing_msg_types
parent
3fd05f5c
No related branches found
No related tags found
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
main.py
+6
-4
6 additions, 4 deletions
main.py
utils.py
+43
-0
43 additions, 0 deletions
utils.py
with
49 additions
and
4 deletions
main.py
+
6
−
4
View file @
fed72bef
import
socket
from
joblib
import
load
from
utils
import
process_mllp_message
,
parse_hl7_message
,
create_acknowledgement
from
utils
import
process_mllp_message
,
parse_hl7_message
,
create_acknowledgement
,
parse_system_message
from
constants
import
DT_MODEL_PATH
,
REVERSE_LABELS_MAP
...
...
@@ -28,9 +28,11 @@ def start_server(host="0.0.0.0", port=8440):
if
hl7_data
:
message
=
parse_hl7_message
(
hl7_data
)
print
(
"
Parsed HL7 Message:
"
)
print
(
message
)
print
(
type
(
message
))
# print(message)
# print(type(message))
category
,
mrn
,
data
=
parse_system_message
(
message
)
#category is type of system message and data consists of age sex if PAS admit or date of blood test and creatanine result
print
(
category
,
mrn
,
data
,
'
\n
'
)
# Create and send ACK message
ack_message
=
create_acknowledgement
(
message
)
sock
.
sendall
(
ack_message
)
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
43
−
0
View file @
fed72bef
...
...
@@ -84,3 +84,46 @@ def populate_test_results_table(db, path):
date
=
row
[
j
]
result
=
float
(
row
[
j
+
1
])
db
.
insert_test_result
(
mrn
,
date
,
result
)
def
parse_system_message
(
message
):
"""
Parses the HL7 message and returns the parsed message object.
"""
mrn
=
0
category
=
''
data
=
[
''
]
*
2
segments
=
str
(
message
).
split
(
'
\n
'
)
if
len
(
segments
)
<
4
:
parsed_seg
=
segments
[
1
].
split
(
'
|
'
)
if
len
(
parsed_seg
)
>
4
:
mrn
=
parsed_seg
[
3
]
category
=
'
PAS-admit
'
date_of_birth
=
parsed_seg
[
7
]
data
[
0
]
=
calculate_age
(
date_of_birth
)
data
[
1
]
=
parsed_seg
[
8
][
0
]
else
:
mrn
=
parsed_seg
[
3
].
replace
(
'
\r
'
,
''
)
category
=
'
PAS-discharge
'
else
:
mrn
=
segments
[
1
].
split
(
'
|
'
)[
3
]
category
=
'
LIMS
'
data
[
0
]
=
segments
[
2
].
split
(
'
|
'
)[
7
]
#date of blood test
data
[
1
]
=
float
(
segments
[
3
].
split
(
'
|
'
)[
5
])
return
category
,
mrn
,
data
def
calculate_age
(
date_of_birth
):
"""
Calculate age based on the date of birth provided in the format YYYYMMDD.
"""
# Parse the date of birth string into a datetime object
dob
=
datetime
.
datetime
.
strptime
(
date_of_birth
,
"
%Y%m%d
"
)
# Get the current date
current_date
=
datetime
.
datetime
.
now
()
# Calculate the difference between the current date and the date of birth
age
=
current_date
.
year
-
dob
.
year
-
((
current_date
.
month
,
current_date
.
day
)
<
(
dob
.
month
,
dob
.
day
))
return
age
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment