#!/usr/bin/env python3 import re import datetime import util import autoproc units = { 'P': 'bpm', 'R': 'bpm', 'B/P': 'mmHg', 'Body Mass Index': 'kg/m²' } local_tzinfo = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo async def cmd_entries(proc, mrn, alpha, omega): """Fetch measurements""" async with proc.sendline, autoproc.expect_async(proc) as expect: proc.sendline('^Results Reporting Menu') async for prompt, response in expect.promptmatches( ( (' Press return to continue ', None), ('Select Patient(s): ', mrn, True), ('Select Patient: ', mrn, True), ), ('Select Item(s): ', '7'), # Vitals Cumulative Report ('Start Date [Time]: T// ', util.vista_strftime(alpha)), (re.compile(r'^Ending Date \[Time\] \(inclusive\): (.*?)// $'), util.vista_strftime(omega)), ('DEVICE: HOME// ', 'HOME;;1023'), timeout_settle=2, throw=True): proc.sendline(response) assert await expect.earliest(' HOME(CRT)\r\n') pages = [] async for prompt, response in expect.promptmatches(( ('Press return to continue "^" to escape ', None), ('Press RETURN to continue or \'^\' to exit: ', None), ('Select Clinician Menu Option: ', None, True), ), throw=True): 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: ') 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') for m_time in re.finditer(r'^(?P