Read effective date from PBS XML

This commit is contained in:
RunasSudo 2023-02-04 14:28:11 +11:00
parent 78e43cd45e
commit cd33823cc7
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 24 additions and 10 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
rm html/database.db
sqlite3 database.db '.dump pbs_item pbs_mp pbs_mp_brand_name pbs_mpp pbs_item_restriction pbs_restriction pbs_restriction_criteria pbs_criteria pbs_criteria_parameter' | sqlite3 html/database.db
sqlite3 database.db '.dump meta pbs_item pbs_mp pbs_mp_brand_name pbs_mpp pbs_item_restriction pbs_restriction pbs_restriction_criteria pbs_criteria pbs_criteria_parameter' | sqlite3 html/database.db

View File

@ -1,6 +1,6 @@
#!/bin/bash
./import_pbs_xml.py
./render_pbs_criteria.py
./find_pbs_brand_names.py
./import_pbs_xml.py || exit 1
./render_pbs_criteria.py || exit 1
./find_pbs_brand_names.py || exit 1
./export_db.sh

View File

@ -69,10 +69,10 @@
</tbody>
</table>
</div>
<footer class="border-top pt-4 mt-4">
<p class="text-muted">Results sourced from the PBS database as at <span id="pbs-date"></span>. This tool is made available in the hope that it will be useful, but <b>WITHOUT ANY WARRANTY</b>; without even the implied warranty of <b>MERCHANTABILITY</b> or <b>FITNESS FOR A PARTICULAR PURPOSE</b>. Information provided in this tool is intended for reference by medical professionals. Nothing in this tool is intended to constitute medical advice.</p>
</footer>
</div>
<footer class="border-top pt-4 mt-4">
<p class="text-muted">Results sourced from the PBS database as at January 2023. This tool is made available in the hope that it will be useful, but <b>WITHOUT ANY WARRANTY</b>; without even the implied warranty of <b>MERCHANTABILITY</b> or <b>FITNESS FOR A PARTICULAR PURPOSE</b>. Information provided in this tool is intended for reference by medical professionals. Nothing in this tool is intended to constitute medical advice.</p>
</footer>
</div>
<!--<script src="https://cdn.jsdelivr.net/npm/jquery@3.6.3/dist/jquery.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>-->
@ -92,6 +92,10 @@
const [SQL, buf] = await Promise.all([sqlPromise, dataPromise])
db = new SQL.Database(new Uint8Array(buf));
// Display date
const pbs_date_bits = execAsScalars(db.prepare('SELECT value FROM meta WHERE key = "pbs_date"'))[0].split('-');
document.getElementById('pbs-date').innerText = {'01': 'January', '02': 'February', '03': 'March', '04': 'April', '05': 'May', '06': 'June', '07': 'July', '08': 'August', '09': 'September', '10': 'October', '11': 'November', '12': 'December'}[pbs_date_bits[1]] + ' ' + pbs_date_bits[0];
// Initialise search bar
const mp_preferred_terms = execAsScalars(db.prepare('SELECT preferred_term FROM pbs_mp ORDER BY LOWER(preferred_term)'));
let data = mp_preferred_terms.map(mp_preferred_term => ({'label': mp_preferred_term, 'preview': mp_preferred_term, 'value': mp_preferred_term}));

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import sqlite3
import zipfile
from xml.etree import ElementTree as ET
@ -23,6 +24,9 @@ con = sqlite3.connect('database.db')
cur = con.cursor()
# Init schema
cur.execute('DROP TABLE IF EXISTS meta')
cur.execute('CREATE TABLE meta (key TEXT PRIMARY KEY, value TEXT)')
cur.execute('DROP TABLE IF EXISTS pbs_item')
cur.execute('CREATE TABLE pbs_item (code TEXT PRIMARY KEY, mpp_code TEXT, maximum_prescribable_units INTEGER, number_repeats INTEGER, benefit_type TEXT, program TEXT)')
@ -51,14 +55,20 @@ cur.execute('DROP TABLE IF EXISTS pbs_criteria_parameter')
cur.execute('CREATE TABLE pbs_criteria_parameter (id INTEGER PRIMARY KEY AUTOINCREMENT, criteria_code INTEGER, text TEXT)')
# Parse XML
with zipfile.ZipFile('data/2023-01-01-xml-V3.zip', 'r') as zipf:
with zipf.open('sch-2023-01-01-r1.xml', 'r') as f:
pbs_zip_file = sorted([f for f in os.listdir('data') if f.endswith('-xml-V3.zip')])[-1]
with zipfile.ZipFile('data/' + pbs_zip_file, 'r') as zipf:
pbs_xml_file = next(f for f in zipf.namelist() if f.endswith('.xml'))
with zipf.open(pbs_xml_file, 'r') as f:
tree = ET.parse(f)
print('Parsed XML')
root = tree.getroot()
ns = {'pbs': 'http://schema.pbs.gov.au/', 'xlink': 'http://www.w3.org/1999/xlink', 'xml': 'http://www.w3.org/XML/1998/namespace', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'dbk': 'http://docbook.org/ns/docbook'}
ns = {'pbs': 'http://schema.pbs.gov.au/', 'xlink': 'http://www.w3.org/1999/xlink', 'xml': 'http://www.w3.org/XML/1998/namespace', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'dbk': 'http://docbook.org/ns/docbook', 'dct': 'http://purl.org/dc/terms/'}
# Write meta
cur.execute('INSERT INTO meta (key, value) VALUES (?, ?)', ('pbs_date', root.find('pbs:info', ns).find('dct:valid', ns).text))
# -----------------------------------------
# Parse items from each desired PBS program