Include RPBS items

This commit is contained in:
RunasSudo 2023-02-04 14:09:58 +11:00
parent f5bdc0d3cb
commit 78e43cd45e
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 77 additions and 47 deletions

View File

@ -71,6 +71,10 @@ for mp_code in sorted(brand_names.keys()):
# Conflict # Conflict
continue continue
# Exceptions
if short_name == 'Coloxyl with':
continue
# Can shorten # Can shorten
if brand_name in brand_names[mp_code]: if brand_name in brand_names[mp_code]:
brand_names[mp_code].remove(brand_name) brand_names[mp_code].remove(brand_name)

View File

@ -170,7 +170,10 @@
td = document.createElement('td'); td.innerText = item['maximum_prescribable_units']; tr.appendChild(td); td = document.createElement('td'); td.innerText = item['maximum_prescribable_units']; tr.appendChild(td);
td = document.createElement('td'); td.innerText = item['number_repeats']; tr.appendChild(td); td = document.createElement('td'); td.innerText = item['number_repeats']; tr.appendChild(td);
if (item['benefit_type'] === 'unrestricted') { if (item['program'] === 'R1') {
td = document.createElement('td'); td.innerHTML = '<a href="https://www.pbs.gov.au/medicine/item/' + item['code'] + '" target="_blank">RPBS</a>'; tr.appendChild(td);
tr.classList.add('table-secondary');
} else if (item['benefit_type'] === 'unrestricted') {
td = document.createElement('td'); tr.appendChild(td); td = document.createElement('td'); tr.appendChild(td);
} else if (item['benefit_type'] === 'restricted') { } else if (item['benefit_type'] === 'restricted') {
td = document.createElement('td'); td.innerHTML = '<a href="https://www.pbs.gov.au/medicine/item/' + item['code'] + '" target="_blank">Restricted</a>'; tr.appendChild(td); td = document.createElement('td'); td.innerHTML = '<a href="https://www.pbs.gov.au/medicine/item/' + item['code'] + '" target="_blank">Restricted</a>'; tr.appendChild(td);
@ -193,6 +196,14 @@
const regexIsNumber = /^[0-9]+$/.compile(); const regexIsNumber = /^[0-9]+$/.compile();
function comparePBSItems(item1, item2) { function comparePBSItems(item1, item2) {
// Sort RPBS, etc. benefits after other items
if (item1['program'] === 'GE' && item2['program'] !== 'GE') {
return -1;
}
if (item2['program'] === 'GE' && item1['program'] !== 'GE') {
return 1;
}
// Sort tablets/capsules before other forms // Sort tablets/capsules before other forms
if ((item1['mpp_preferred_term'].indexOf(' tablet, ') >= 0 || item1['mpp_preferred_term'].indexOf(' capsule, ') >= 0) && !(item2['mpp_preferred_term'].indexOf(' tablet, ') >= 0 || item2['mpp_preferred_term'].indexOf(' capsule, ') >= 0)) { if ((item1['mpp_preferred_term'].indexOf(' tablet, ') >= 0 || item1['mpp_preferred_term'].indexOf(' capsule, ') >= 0) && !(item2['mpp_preferred_term'].indexOf(' tablet, ') >= 0 || item2['mpp_preferred_term'].indexOf(' capsule, ') >= 0)) {

View File

@ -24,7 +24,7 @@ cur = con.cursor()
# Init schema # Init schema
cur.execute('DROP TABLE IF EXISTS pbs_item') 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)') 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)')
cur.execute('DROP TABLE IF EXISTS pbs_mpp') cur.execute('DROP TABLE IF EXISTS pbs_mpp')
cur.execute('CREATE TABLE pbs_mpp (code TEXT PRIMARY KEY, mp_code TEXT, preferred_term TEXT)') cur.execute('CREATE TABLE pbs_mpp (code TEXT PRIMARY KEY, mp_code TEXT, preferred_term TEXT)')
@ -60,8 +60,8 @@ print('Parsed XML')
root = tree.getroot() 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'}
# Get General Schedule # -----------------------------------------
program = next(p for p in root.find('pbs:schedule', ns).findall('pbs:program', ns) if p.find('pbs:info', ns).find('pbs:code', ns).text == 'GE') # Parse items from each desired PBS program
mpps_to_parse = set() mpps_to_parse = set()
tpps_to_parse = set() tpps_to_parse = set()
@ -69,6 +69,10 @@ mps_to_parse = set()
restrictions_to_parse = set() restrictions_to_parse = set()
criteria_to_parse = set() criteria_to_parse = set()
def parse_program(program_code):
# Get program
program = next(p for p in root.find('pbs:schedule', ns).findall('pbs:program', ns) if p.find('pbs:info', ns).find('pbs:code', ns).text == program_code)
# Get schedule items (prescribing-rule) in schedule # Get schedule items (prescribing-rule) in schedule
for item in program.findall('pbs:prescribing-rule', ns): for item in program.findall('pbs:prescribing-rule', ns):
code = item.find('pbs:code', ns).text code = item.find('pbs:code', ns).text
@ -95,7 +99,7 @@ for item in program.findall('pbs:prescribing-rule', ns):
'http://pbs.gov.au/benefit-type/authority-required': 'authority', 'http://pbs.gov.au/benefit-type/authority-required': 'authority',
}[benefit.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')] }[benefit.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')]
cur.execute('INSERT INTO pbs_item (code, mpp_code, maximum_prescribable_units, number_repeats, benefit_type) VALUES (?, ?, ?, ?, ?)', (code, mpp_code, max_units, max_repeats, benefit_type)) cur.execute('INSERT INTO pbs_item (code, mpp_code, maximum_prescribable_units, number_repeats, benefit_type, program) VALUES (?, ?, ?, ?, ?, ?)', (code, mpp_code, max_units, max_repeats, benefit_type, program_code))
# Get restrictions # Get restrictions
if restrictions := benefit.find('pbs:restriction-references-list', ns): if restrictions := benefit.find('pbs:restriction-references-list', ns):
@ -110,6 +114,12 @@ for item in program.findall('pbs:prescribing-rule', ns):
# Queue the MPP for parsing # Queue the MPP for parsing
mpps_to_parse.add(mpp_id) mpps_to_parse.add(mpp_id)
parse_program('GE') # General Schedule
parse_program('R1') # Repatriation PBS
# ----------------
# Parse MPPs, etc.
# Parse MPPs # Parse MPPs
for mpp_id in sorted(list(mpps_to_parse)): for mpp_id in sorted(list(mpps_to_parse)):
mpp = root.find('pbs:drugs-list', ns).find('pbs:mpp[@xml:id="' + mpp_id + '"]', ns) mpp = root.find('pbs:drugs-list', ns).find('pbs:mpp[@xml:id="' + mpp_id + '"]', ns)
@ -171,11 +181,16 @@ for restriction_id in sorted(list(restrictions_to_parse)):
severity_term = severity.find('pbs:preferred-term', ns).text.strip() severity_term = severity.find('pbs:preferred-term', ns).text.strip()
indication_strings.append(severity_term) indication_strings.append(severity_term)
condition_id = indication.find('pbs:condition-reference', ns).get('{http://www.w3.org/1999/xlink}href').lstrip('#') if condition_reference := indication.find('pbs:condition-reference', ns):
condition_id = condition_reference.get('{http://www.w3.org/1999/xlink}href').lstrip('#')
condition = root.find('pbs:prescribing-texts-list', ns).find('pbs:condition[@xml:id="' + condition_id + '"]', ns) condition = root.find('pbs:prescribing-texts-list', ns).find('pbs:condition[@xml:id="' + condition_id + '"]', ns)
condition_term = condition.find('pbs:preferred-term', ns).text.strip() condition_term = condition.find('pbs:preferred-term', ns).text.strip()
indication_strings.append(condition_term) indication_strings.append(condition_term)
if not indication_strings:
# TODO: Might have a <block-container>
indication_strings = ['Unknown indication']
# Get operator and criteria # Get operator and criteria
operators = restriction.findall('pbs:any', ns) + restriction.findall('pbs:all', ns) + restriction.findall('pbs:one-of', ns) operators = restriction.findall('pbs:any', ns) + restriction.findall('pbs:all', ns) + restriction.findall('pbs:one-of', ns)
if operators: if operators: