Last active
January 18, 2021 03:27
-
-
Save ilius/7379ad90fefeb35a52ea4a39df8c22e8 to your computer and use it in GitHub Desktop.
pharmaplus
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from formats_common import * | |
import html | |
enable = True | |
format = 'Pharmaplus' | |
description = 'Pharmaplus (SQLite3)' | |
extensions = () | |
readOptions = [] | |
writeOptions = [] | |
tools = [ | |
{ | |
"name": "Pharmaplus", | |
"web": "", | |
"platforms": ["Android"], | |
# "license": "", | |
}, | |
] | |
class Reader(object): | |
def __init__(self, glos): | |
self._glos = glos | |
self._clear() | |
def _clear(self): | |
self._filename = '' | |
self._con = None | |
self._cur = None | |
def open(self, filename): | |
from sqlite3 import connect | |
self._filename = filename | |
self._con = connect(filename) | |
self._cur = self._con.cursor() | |
self._glos.setDefaultDefiFormat("h") | |
def __len__(self): | |
self._cur.execute("select count(*) from book_contents") | |
return self._cur.fetchone()[0] | |
def __iter__(self): | |
self._cur.execute( | |
"select generic_name, drug_category, theraputic_group, content, pregnancy, lactation, indication_dosage, administration, contra_indications, precautions, interactions, side_effects, compatibility, stability from book_contents" | |
" order by id" | |
) | |
glos = self._glos | |
wordSet = set() | |
# FIXME: iteration over self._cur stops after one entry | |
# and self._cur.fetchone() returns None | |
# for row in self._cur: | |
for row in self._cur.fetchall(): | |
generic_name = row[0] | |
theraputic_group = row[1] | |
drug_category = row[2] | |
content = row[3] | |
pregnancy = row[4] | |
lactation = row[5] | |
indication_dosage = row[6] | |
administration = row[7] | |
contra_indications = row[8] | |
precautions = row[9] | |
interactions = row[10] | |
side_effects = row[11] | |
compatibility = row[12] | |
stability = row[13] | |
word = generic_name | |
if word is None: | |
continue | |
if word in wordSet: | |
continue | |
wordSet.add(word) | |
word = word.capitalize() | |
definition = theraputic_group | |
if definition is None: | |
definition = "" | |
definition = glos.wordTitleStr(word) + f"<br><br><b>Theraputic Group:</b><br>" + definition | |
if drug_category: | |
definition += f'<br><b>Category:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{drug_category}</div></a>' | |
if content: | |
definition += f'<br><b>Content:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{content}</div></a>' | |
if pregnancy: | |
definition += f'<br><b>Pregnancy:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{pregnancy}</div></a>' | |
if lactation: | |
definition += f'<br><b>Lactation:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{lactation}</div></a>' | |
if indication_dosage: | |
definition += f'<br><b>Indication and dosage:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{indication_dosage}</div></a>' | |
if administration: | |
definition += f'<br><b>Administration:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{administration}</div></a>' | |
if contra_indications: | |
definition += f'<br><b>Contraindications:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{contra_indications}</div></a>' | |
if precautions: | |
definition += f'<br><b>Precautions:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{precautions}</div></a>' | |
if interactions: | |
definition += f'<br><b>Interactions:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{interactions}</div></a>' | |
if side_effects: | |
definition += f'<br><b>Side effects:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{side_effects}</div></a>' | |
if compatibility: | |
definition += f'<br><b>Compatibility:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{compatibility}</div></a>' | |
if stability: | |
definition += f'<br><b>Stability:</b> <a> <div style="white-space: pre-wrap; word-break: keep-all;">{stability}</div></a>' | |
yield self._glos.newEntry( | |
word, | |
definition, | |
defiFormat="h", | |
) | |
def close(self): | |
if self._cur: | |
self._cur.close() | |
if self._con: | |
self._con.close() | |
self._clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment