blood_analyzer.services package
Submodules
blood_analyzer.services.create_graph module
blood_analyzer.services.login module
blood_analyzer.services.openpdf module
blood_analyzer.services.parsepdf module
- class blood_analyzer.services.parsepdf.BloodResults[source]
Bases:
object- blood_parameters: List[str] = ['WBC', 'NEU', 'LYM', 'MONO', 'BASO', 'EOS', 'RBC', 'HCT', 'HGB', 'MCV', 'MCH', 'MCHC', 'PLT', 'MPV', 'PCT', 'RET', 'RET%', 'IRF', 'RDW', 'RDW-SD']
- create_patient_id() None[source]
Function creates patient ID number using numbers from birth date and numbers converted from patient name using ASCII table. Next all numbers are summed up. :return: None
- extract_birth_date(text_line: str) None[source]
Function extracts birth date from PDF file :param text_line: parsed_pdfs line of text :return: None
- extract_blood_parameters_data(text_line: str) None[source]
Function tries to match each line to given regex definition. If success (True), parsed_pdfs line is passed to function which unify signatures (can be different for different laboratories). After unification, function filters from the whole list of parameters, only one which are required. Blood parameter and blood result is already split so those values are assigned directly to dictionary defined in __init__. Parsed text which is defining blood LIMITS in some cases is sticked to the UNITS. It is required to split those string, so next function pass parsed_pdfs text through two function for text normalization. After text normalization blood LIMITS and blood UNITS are assigned to dictionary defined in __init__. :param text_line: each line parsed_pdfs from PDF file. :return: None
- extract_date(text_line: str) None[source]
Function extracts exam date from PDF file. :param text_line: parsed_pdfs line of text :return: None
- extract_information(pdf_path: str) None[source]
Method opens one pdf defined by its path_uploads.
Module pdfplumber iterates over the pdf, analyzing each line of the text.
Separated methods are started in order to find required data using regex module.
Each method are assigning values to value names defined in class constructor.
5. At the end of this method, some of the data are stored into dictionary and are corrected, because of undesired extra characters.
- extract_patient_name(text_line: str) None[source]
Function extract patient name. :param text_line: parsed_pdfs line of text :return: None
- get_lab_code(text_line) None[source]
Function reads proper allowable lab code present in PDF file. It is further used to insert into database and dataframe. :param text_line: Parsed line of text. :return: None
- headers = ('DATE', 'LAB_CODE', 'WBC', 'NEU', 'LYM', 'MONO', 'BASO', 'EOS', 'RBC', 'HCT', 'HGB', 'MCV', 'MCH', 'MCHC', 'PLT', 'MPV', 'PCT', 'RET', 'RET_PERCENT', 'IRF', 'RDW', 'RDW_SD')
- limits = {'BASO': [0, 0.2], 'EOS': [0.05, 0.4], 'HCT': [34.5, 46.3], 'HGB': [11.7, 15.5], 'IRF': [0.2, 0.4], 'LYM': [1, 3], 'MCH': [27.2, 33.5], 'MCHC': [32.5, 35.2], 'MCV': [80.4, 95.9], 'MONO': [0.2, 1], 'MPV': [6.8, 11], 'NEU': [2, 7], 'PCT': [0.19, 0.33], 'PLT': [150, 400], 'RBC': [3.83, 5.1], 'RDW': [11.7, 14.6], 'RDW_SD': [36, 46], 'RET': [0.02, 0.13], 'RET_PERCENT': [0.2, 2.5], 'WBC': [4, 10]}
- reset_attributes() None[source]
Function resets all class attributes. It is required to avoid wrong results assignment when program is running and PDFs are analyzed in the loop. :return: None
- unify_signature(blood_result) str[source]
takes blood signature and unify its name as per unified signature dict {deviation : unified}. :param blood_result: one line of text parsed_pdfs from PDF. It contains signature, blood result, limit values and blood unit. :return: changed name of signature as stated in unified signatures
- units = {'BASO': '10´3/µl', 'EOS': '10´3/µl', 'HCT': '%', 'HGB': 'g/dl', 'IRF': '%', 'LYM': '10´3/µl', 'MCH': 'pg', 'MCHC': 'g/dl', 'MCV': 'fl', 'MONO': '10´3/µl', 'MPV': 'fl', 'NEU': '10´3/µl', 'PCT': '%', 'PLT': '10´3/µl', 'RBC': '10´6/µl', 'RDW': '%', 'RDW_SD': 'fl', 'RET': '10´6/µl', 'RET_PERCENT': '%', 'WBC': '10´3/µl'}