Created
November 10, 2017 03:11
-
-
Save schlerp/a879a91d4b7fedd135c3bad83bd355e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from hl7apy.parser import parse_message | |
input_folder_prod = '' | |
input_folder_test = '' | |
def get_fnames(folder): | |
ret = [] | |
for f in os.listdir(folder): | |
f_path = os.path.join(folder, f) | |
if os.path.isfile(f_path): | |
ret.append(f_path) | |
return ret | |
input_files_prod = get_fnames(input_folder_prod) | |
input_files_test = get_fnames(input_folder_test) | |
def parse_msg(f_path): | |
with open(f_path, 'r') as f: | |
raw_hl7 = f.read() | |
hl7_msg = parse_message(raw_hl7, find_groups=False) | |
return hl7_msg | |
def get_ids(input_files): | |
ret = [] | |
for f_path in input_files: | |
hl7_msg = parse_msg(f_path) | |
msg_id = hl7_msg.msh.msh_10.value | |
ret.append(msg_id) | |
return ret | |
input_ids_prod = get_ids(input_files_prod) | |
input_ids_test = get_ids(input_files_test) | |
def compare_msg_ids(ids_prod, ids_test): | |
only_prod = [] | |
only_test = [] | |
both = [] | |
for id_prod in ids_prod: | |
if id_prod in ids_test: | |
both.append(id_prod) | |
else: | |
only_prod.append(id_prod) | |
for id_test in ids_test: | |
if id_test in ids_prod: | |
if id_test not in both: | |
both.append(id_test) | |
else: | |
only_test.append(id_test) | |
return both, only_prod, only_test | |
results = compare_msg_ids(input_ids_prod, input_ids_test) | |
both, only_prod, only_test = results | |
def output(f_path, ids): | |
with open(f_path, 'w+') as f: | |
for _id in ids: | |
f.write(_id + '\n') | |
output_folder = './' | |
file_pre = 'wdp_' | |
output_file_both = os.path.join(output_folder, file_pre + 'both.csv') | |
output_file_only_prod = os.path.join(output_folder, file_pre + 'only_prod.csv') | |
output_file_only_test = os.path.join(output_folder, file_pre + 'only_test.csv') | |
output(output_file_both, both) | |
output(output_file_only_prod, only_prod) | |
output(output_file_only_test, only_test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment