Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/loaders/Poland_medcine_parser-main/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Vlad Maevski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
55 changes: 55 additions & 0 deletions src/loaders/Poland_medcine_parser-main/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Poland_medcine_parser

This repository contains a Python script, translator.py, which provides functions for translating and processing medicine data from an Excel file. The script utilizes the openpyxl library for reading Excel files and the googletrans library for translating text.

## Requirements

To run the script, you need to have the following dependencies installed:

- openpyxl: A library for reading and writing Excel files.

- googletrans: A library for Google Translate API.

You can install these dependencies using the following command:

pip install openpyxl googletrans
## Usage

1. Clone the repository to your local machine.

2. Install the required dependencies as mentioned above.

3. Open the translator.py file in a text editor.

4. Modify the excel_file variable to specify the path to your Excel file containing medicine data.

5. Adjust the number_of_files and number_of_scs variables according to your desired configuration.

6. Run the script using the following command:

python translator.py
The script will parse the medicine data from the Excel file, translate relevant information to English, and generate multiple .scs files based on the specified configuration.

## File Structure

The script generates multiple .scs files, each containing the translated and processed medicine data. The number of files and the number of records per file are determined by the number_of_files and number_of_scs variables, respectively.

## Translation and Processing

The script performs the following translation and processing tasks:

- Translates medicine names and other text fields from Polish to English using the Google Translate API.

- Fixes and standardizes various fields, such as medicine names, dosages, alternative names, pharmaceutical forms, and routes of administration.

- Extracts information such as ATC codes, marketing authorization holders, active substances, countries of sale, and dosage forms.

- Generates a template for each medicine record in the form of an .scs file, following a specific structure.

## Note

Please note that the script relies on the Google Translate API for translation. Make sure to comply with the terms of service and usage limits of the API to avoid any issues.

## License

This project is licensed under the [MIT License](LICENSE). Feel free to modify and distribute the code as per the terms of the license.
165 changes: 165 additions & 0 deletions src/loaders/Poland_medcine_parser-main/translator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import openpyxl
from googletrans import Translator


def translator(text, lang):
ts= Translator()
T = ts.translate(text, dest = lang)
return T.text

def fix_name(name):
name = name.replace(" ","_")
return name

def fix_dose(dose):
if dose == '-':
result = ["",""]
return result
dose = dose.replace(",",".")
dose = dose.replace(" ","")
dose = dose.replace("(","")
dose = dose.replace('niemniejniż','')
if 'mg' in dose or 'mcg' in dose:
dose = dose[0:dose.find('g')+1]
elif 'j.m.' in dose:
dose = dose[0:dose.find('j.m.')+1]
dose = dose.replace(".","")
dose1 = "_" + dose
dose2 = "(" + dose + ")"
result = [dose1,dose2]
return result

def fix_P_name(P_name, name):
if '+' in P_name:
result = ""
sp = P_name.split(sep = '+')
for n in sp:
result = result + "["
result = result + n + "]; "
else: result = '['+ P_name +'];'
if P_name == '-':
result = name + ';'
return result


def fix_atc(atc):
if atc == '':
return ''
else:
return '=> nrel_atc_code: ' + atc + ';'

def fix_country(country):
sp = country.split()
st = set(sp)
result = ""
for n in st:
result = result + n + "; "
return result

def fix_active(active):
if '+' in active:
result = ""
sp = active.split(sep = '+')
for n in sp:
n = n.replace(" ","_")
for n in sp:
result = result + "["
result = result + n + "]; "
else:
result = '[' + active + "];"
return result

def fix_dosage_form(dosage_form):
dosage_form = dosage_form.replace("/","")
dosage_form = dosage_form.replace(" ","_")
dosage_form = dosage_form.replace(",","")
return dosage_form

def fix_route(dosage_form):
result = ""
dosage_form_low = dosage_form.lower()
if 'injection' in dosage_form_low or 'infusion' in dosage_form_low:
result = 'concept_parenteral_route;;'
if 'cream' in dosage_form_low or 'gel'in dosage_form_low or 'transdermal' in dosage_form_low:
result = 'concept_transdermal_route;;'
if 'drops' in dosage_form_low or 'eyes'in dosage_form_low:
result = 'concept_intra_ocular_route;;'
if 'capsules' in dosage_form_low or 'pills' in dosage_form_low or 'tablets' in dosage_form_low:
result = 'concept_oral_route;;'
if result != "":
result = '=> nrel_route_of_administration:' + result
return result

def create_file(templates, c_files, c_scs):
count = 0
for i in range(c_files):
file = open(f"{i}.scs","a+",encoding="utf-8")
for j in range(c_scs):
count+=1
file.write(templates[count])
file.close()

def parse_and_input(excel_file, number_of_files, number_of_scs):
workbook = openpyxl.open(excel_file, read_only = True)
sheet = workbook.active
templates = []
for row in range(2,number_of_scs * number_of_files + 1):
name_pl = sheet[row][1].value
name_en = translator(name_pl, 'en')
dose0 = sheet[row][4].value
ATC = sheet[row][6].value
ATC = fix_atc(ATC)
P_name0 = sheet[row][2].value
company = translator(sheet[row][7].value, 'en')
dosage_form0 = translator(sheet[row][5].value, 'en')

country_test = sheet[row][10].value
if country_test == "":
country_test = "Polska"
country0 = translator(country_test, 'en')

name = fix_name(name_en).lower().replace('%','')
dose = fix_dose(dose0)
dose1 = dose[0]
dose2 = dose[1]
P_name = fix_P_name(P_name0, name_en)

active_test = sheet[row][8].value
if active_test == "":
active_test = P_name
active0 = translator(active_test, 'en')

active = fix_active(active0)
country = fix_country(country0)
dosage_form = fix_dosage_form(dosage_form0)
route = fix_route(dosage_form0)
end =''
if route == "":
end = ';'

template = f"""
medication_{name}{dose1}
<-sc_node_not_relation;
=> nrel_main_idtf:
[{name_en} {dose2}] (* <- lang_en;;*);
[{name_pl} {dose2}] (* <- lang_pl;;*);
{ATC}
=> nrel_international_non_proprietary_name: {P_name}
=> nrel_company: [{company}];
=> nrel_countries_of_sale: {country}
=> nrel_active_substances: {active}
=> nrel_dosage_form:{dosage_form};{end}
{route}
"""
templates.append(template)
create_file(templates, number_of_files, number_of_scs)


excel_file = 'C:\work\Course\Med.xlsx'
values = parse_and_input(excel_file, 5, 10)