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,46 +69,56 @@ mps_to_parse = set()
restrictions_to_parse = set() restrictions_to_parse = set()
criteria_to_parse = set() criteria_to_parse = set()
# Get schedule items (prescribing-rule) in schedule def parse_program(program_code):
for item in program.findall('pbs:prescribing-rule', ns): # Get program
code = item.find('pbs:code', ns).text 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)
# Only get benefits available to medical practitioners # Get schedule items (prescribing-rule) in schedule
benefits = [b for b in item.find('pbs:benefit-types-list', ns).findall('pbs:benefit-type', ns) if b.find('pbs:member-of-list', ns).find('pbs:member-of[@rdf:resource="http://pbs.gov.au/prescriber/medical"]', ns)] for item in program.findall('pbs:prescribing-rule', ns):
code = item.find('pbs:code', ns).text
if not benefits:
continue # Only get benefits available to medical practitioners
benefits = [b for b in item.find('pbs:benefit-types-list', ns).findall('pbs:benefit-type', ns) if b.find('pbs:member-of-list', ns).find('pbs:member-of[@rdf:resource="http://pbs.gov.au/prescriber/medical"]', ns)]
assert len(benefits) == 1
benefit = benefits[0] if not benefits:
continue
mpp_id = item.find('pbs:ready-prepared', ns).find('pbs:mpp-reference', ns).get('{http://www.w3.org/1999/xlink}href').lstrip('#')
mpp_code = item.find('pbs:ready-prepared', ns).find('pbs:mpp-reference', ns).find('pbs:code', ns).text assert len(benefits) == 1
benefit = benefits[0]
max_units = item.find('pbs:ready-prepared', ns).find('pbs:maximum-prescribable[@rdf:resource="http://pbs.gov.au/reference/unit-of-use"]', ns).find('pbs:value', ns).text
max_repeats = item.find('pbs:ready-prepared', ns).find('pbs:number-repeats', ns).find('pbs:value', ns).text mpp_id = item.find('pbs:ready-prepared', ns).find('pbs:mpp-reference', ns).get('{http://www.w3.org/1999/xlink}href').lstrip('#')
mpp_code = item.find('pbs:ready-prepared', ns).find('pbs:mpp-reference', ns).find('pbs:code', ns).text
benefit_type = {
'http://pbs.gov.au/benefit-type/unrestricted': 'unrestricted', max_units = item.find('pbs:ready-prepared', ns).find('pbs:maximum-prescribable[@rdf:resource="http://pbs.gov.au/reference/unit-of-use"]', ns).find('pbs:value', ns).text
'http://pbs.gov.au/benefit-type/restricted': 'restricted', max_repeats = item.find('pbs:ready-prepared', ns).find('pbs:number-repeats', ns).find('pbs:value', ns).text
'http://pbs.gov.au/benefit-type/streamlined': 'streamlined',
'http://pbs.gov.au/benefit-type/authority-required': 'authority', benefit_type = {
}[benefit.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')] 'http://pbs.gov.au/benefit-type/unrestricted': 'unrestricted',
'http://pbs.gov.au/benefit-type/restricted': 'restricted',
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)) 'http://pbs.gov.au/benefit-type/streamlined': 'streamlined',
'http://pbs.gov.au/benefit-type/authority-required': 'authority',
# Get restrictions }[benefit.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')]
if restrictions := benefit.find('pbs:restriction-references-list', ns):
for restriction_reference in restrictions.findall('pbs:restriction-reference', ns): 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))
restriction_id = restriction_reference.get('{http://www.w3.org/1999/xlink}href').lstrip('#')
restriction_code = restriction_reference.find('pbs:code', ns).text # Get restrictions
cur.execute('INSERT INTO pbs_item_restriction (item_code, restriction_code) VALUES (?, ?)', (code, restriction_code)) if restrictions := benefit.find('pbs:restriction-references-list', ns):
for restriction_reference in restrictions.findall('pbs:restriction-reference', ns):
# Queue this restriction for parsing restriction_id = restriction_reference.get('{http://www.w3.org/1999/xlink}href').lstrip('#')
restrictions_to_parse.add(restriction_id) restriction_code = restriction_reference.find('pbs:code', ns).text
cur.execute('INSERT INTO pbs_item_restriction (item_code, restriction_code) VALUES (?, ?)', (code, restriction_code))
# Queue the MPP for parsing
mpps_to_parse.add(mpp_id) # Queue this restriction for parsing
restrictions_to_parse.add(restriction_id)
# Queue the MPP for parsing
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)):
@ -171,10 +181,15 @@ 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 = root.find('pbs:prescribing-texts-list', ns).find('pbs:condition[@xml:id="' + condition_id + '"]', ns) condition_id = condition_reference.get('{http://www.w3.org/1999/xlink}href').lstrip('#')
condition_term = condition.find('pbs:preferred-term', ns).text.strip() condition = root.find('pbs:prescribing-texts-list', ns).find('pbs:condition[@xml:id="' + condition_id + '"]', ns)
indication_strings.append(condition_term) condition_term = condition.find('pbs:preferred-term', ns).text.strip()
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)