diff --git a/ext_discovery.py b/ext_discovery.py index c78fede..3488e28 100644 --- a/ext_discovery.py +++ b/ext_discovery.py @@ -26,5 +26,11 @@ async def cmd_listclinics(proc): proc.sendline('^') break proc.sendline('^Patient information AND OE/RR') - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() diff --git a/ext_lab.py b/ext_lab.py index 16246c9..2c373bb 100644 --- a/ext_lab.py +++ b/ext_lab.py @@ -74,7 +74,13 @@ async def cmd_reports(proc, mrn, alpha, omega): else: print(repr(before)) assert False - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() text = re.sub(r'\r\n\s+>> CONTINUATION OF .+? <<(?:(?:\r\n)|(?:\s+page \d+))', '', '\r\n'.join(pages)) positions = [m.start() for m in re.finditer(r'(?:(?:[ ]+----MICROBIOLOGY----[ ]+page \d+\r\n\r\n)|(?:[ ]+))Reporting Lab:', text)] diff --git a/ext_measurement.py b/ext_measurement.py index 90daba6..a585d3c 100644 --- a/ext_measurement.py +++ b/ext_measurement.py @@ -39,7 +39,13 @@ async def cmd_entries(proc, mrn, alpha, omega): proc.sendline(response) if prompt.index == 0 or prompt.index == 1: pages.append(re.sub(r'^\x1b\[H\x1b\[J\x1b\[2J\x1b\[H\r\n[^\r\n]+? Cumulative Vitals\/Measurements Report[ ]+Page \d+\r\n\r\n-{10,}\r\n(?:\d{2}\/\d{2}\/\d{2} \(continued\)\r\n\r\n)?|\r\n\r\n\*\*\*[^\r\n]+\r\n\r\n[^\r\n]+?VAF 10-7987j\r\nUnit:[^\r\n]+\r\nDivision:[^\r\n]+(?:\r\n)?$', '', prompt.before)) - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() for m_date in re.finditer(r'^(?P\d{2}\/\d{2}\/\d{2})\r\n(?P.*?\r\n)(?:(?=\d{2}\/)|\r\n|$)', '\r\n'.join(pages), re.DOTALL|re.MULTILINE): g_date = m_date.group('date') diff --git a/ext_note.py b/ext_note.py index 963edb4..46f008e 100644 --- a/ext_note.py +++ b/ext_note.py @@ -68,5 +68,11 @@ async def cmd_reports(proc, mrn, alpha, omega): case _: assert False proc.sendline('^') proc.sendline('^Patient information AND OE/RR') - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() diff --git a/ext_order.py b/ext_order.py index eb6f703..e32a612 100644 --- a/ext_order.py +++ b/ext_order.py @@ -77,7 +77,13 @@ async def cmd_entries(proc, mrn, alpha, omega): break case _: assert False proc.sendline('^Patient information AND OE/RR') - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() prev = None for m in re.finditer(r'\b\d{2}/\d{2}/\d{2}.*?\r\n\r\n', '\r\n'.join(pages).replace('\x1b[1m', '').replace('\x1b[m', ''), re.DOTALL): diff --git a/ext_patient.py b/ext_patient.py index a5e873e..fba021f 100644 --- a/ext_patient.py +++ b/ext_patient.py @@ -25,7 +25,13 @@ async def cmd_lookup_patient(proc, query): res.append(prompt.before[:-24] if prompt.index == 0 and prompt.before.endswith('\r\nENTER \'^\' TO STOP, OR \r\n') else prompt.before) if 0 < prompt.index < 4: single = True - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() if single: return [re.search(r'[ ]{2}(?P.+?)[ ]{2}(?:\((?P[^\)]*?)\))?[ ]{6}(?P\S+)[ ]{4}(?P\S+(?:P \*\*Pseudo SSN\*\*)?)[ ]{5}(?P\S+)[ ]{5}(?P.+?)[ ]{6}(?P[^\r\n]*)', res[0].replace('\r\n', '', 1)).groupdict()] @@ -65,6 +71,12 @@ async def cmd_lookup_patient_ordinal(proc, query, ordinal, force=False): proc.sendline(response) case autoproc.ExpectMatch(index=5): proc.sendline() - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() return re.sub(r'\r\n\r\n(?:[^\r\n;]+);(?:\([^\)]*?\))? (?:\d+ )?(?:\d{3}-\d{2}-\d{4}P?) (?:[^\r\n]+?)[ ]*?(\r\n={10,}\r\n)\r\n', r'\1', '\r\n'.join(res)) diff --git a/ext_rcrs.py b/ext_rcrs.py index b2f367f..c24b60c 100644 --- a/ext_rcrs.py +++ b/ext_rcrs.py @@ -58,7 +58,13 @@ async def cmd_patients(proc, alpha, omega): summary.extend({k.strip(): v.strip() for k, v in row.groupdict().items()} for row in re.finditer(r'(?P[A-Z]\d{4}) (?P[^\r\n]{30}) (?P[^ \r\n]+) (?P[^ \r\n]+) (?P\d{2}/\d{2}/\d{4}) (?P\d{2}/\d{2}/\d{4})', prompt.before)) elif prompt.index == 4: break - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() for item in parse_xml_rcrs(doc_rcrs, summary): yield item diff --git a/ext_scheduling.py b/ext_scheduling.py index 12aa033..8d4f2fd 100644 --- a/ext_scheduling.py +++ b/ext_scheduling.py @@ -63,7 +63,13 @@ async def cmd_appointments(proc, clinics='NPT-HEM/ONC ATTENDING', date='T', stor item['comment'] = '\r\n'.join(m.group(1) for m in re.finditer(r'^\s{15}(\w.*?)$', detail, re.MULTILINE)) yield item proc.sendline('^Patient information AND OE/RR') - assert await expect.endswith('\r\nSelect Patient Information and OE/RR Option: ', '\r\nSelect Patient Information and OE/RR Option: ') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) expect.clear() async def vista_appointment_clinics(proc, expect): diff --git a/ext_session.py b/ext_session.py index dc174dd..cba9d32 100644 --- a/ext_session.py +++ b/ext_session.py @@ -23,6 +23,13 @@ async def task_smartcard(proc, config: Optional[configparser.ConfigParser]=None) if certificate: config.set('auth', 'certificate', certificate) proc.create_task(task_keepalive(proc, True), name='@task:keepalive') + async for prompt, response in expect.promptmatches(( + (re.compile(r' Press \'RETURN\' to continue, \'\^\' to stop: $'), None), + ('Select Patient Information and OE/RR Option: ', None, True), + ('Select Patient Information and OE/RR Option: ', None, True), + ), throw=True): + if prompt.index == 0: + proc.sendline(response) return True async def task_keepalive(proc, suppress=False):