Not a professional coder, but my current hospital position is allowing me to code some workarounds for our abysmal EHR system. The following is part of my Python project to visualize laboratory data.
The following code snippet works, but I haven’t figured out a way with list comprehensions or np.where to streamline it and potentially improve performance. I haven’t found any posts yet to answer this, including among those suggested during question submission.
This code tests tuple(0) in a list of tuples (test_and_value) comprised of (lab test names, test values), searching for misspelled lab test names and replacing them with standardized lab test names.
Common misspellings and their replacement terms live in another list of tuples (chem_fix) to preserve the order in which they are checked. Some word fragments of misspellings are used in lieu of full words, therefore testing cannot be a simple == statement.
Final product is a list of tuples, test_and_value_f, with correctly spelled lab tests.
Pertinent code excerpts:
chem_fix = (('A/G RATIO', 'A:G RATIO'), ('ALK', 'ALKALINE PHOSPHATASE'), ('ALT', 'ALT'), ('AST', 'AST'), ('BILI', 'BILIRUBIN,TOTAL'), ('BLIL', 'BILIRUBIN,TOTAL'), ('BUN/CREAT', 'BUN/CREAT RATIO'), ('BUN', 'BLOOD UREA NITROGEN'), ('CARBON', 'CO2'), ('GLOB', 'GLOBULIN'), ('RANDOM', 'GLUCOSE'), ('PROTEIN', 'TOTAL PROTEIN'))
fix_terms = (x(0) for x in chem_fix)
test_and_value_f = ()
replaced = False
for lab_test, value in test_and_value:
for count, term_needing_fix in enumerate(fix_terms):
if term_needing_fix in lab_test:
replaced = True
if replaced == False:
replaced = False
Is there a more efficient way to do this?