def test_normalise_day() -> None: one = normalise_day(datetime(2021, 3, 26, 0, 0, 0, 647241)) two = normalise_day(datetime(2021, 3, 26, 0, 0, 0, 565704)) result = one == two assert result
def patient_by_btfdot_wear_period(device_id: str, start_wear: datetime, end_wear: datetime) -> Optional[Patient]: """ If data was created on a certain period then it belongs to an individual patient. NOTE: returns DevicePatient, not Patient """ start_wear = normalise_day(start_wear) end_wear = normalise_day(end_wear) devices = get_one_btf_dot(device_id) return determine_by_wear_period(devices, start_wear, end_wear)
def determine_by_wear_period( devices: Optional[List[DeviceWithPatients]], start_wear: datetime, end_wear: datetime, ) -> Optional[Patient]: """Reusable method to determine patient by wear period from a (list of) DeviceWithPatients""" if devices: for device in devices: for patient in device.patients: patient_start = normalise_day(patient.start_wear) # if end_wear is none, use today patient_end = normalise_day(patient.end_wear or datetime.today()) within_start_period = patient_start <= start_wear <= patient_end within_end_period = patient_start <= end_wear <= patient_end if within_start_period and within_end_period: return patient return None
def device_by_wear_period(devices: List[Device], start_wear: datetime, end_wear: datetime) -> Optional[Device]: """ If data was created on a certain period then it belongs to an individual patient. NOTE: returns PatientDevice, not Device """ start_wear = normalise_day(start_wear) end_wear = normalise_day(end_wear) for device in devices: device_start_wear = normalise_day(device.start_wear) # if end_wear is none, use today device_end_wear = normalise_day(device.end_wear or datetime.today()) within_start_period = device_start_wear <= start_wear <= device_end_wear within_end_period = device_start_wear <= end_wear <= device_end_wear if within_start_period and within_end_period: return device return None