コード例 #1
0
ファイル: __init__.py プロジェクト: renalreg/ukrdc-fastapi
def workitems_list(
        since: Optional[datetime.datetime] = None,
        until: Optional[datetime.datetime] = None,
        status: Optional[list[int]] = Query([1]),
        facility: Optional[str] = None,
        user: UKRDCUser = Security(auth.get_user()),
        jtrace: Session = Depends(get_jtrace),
        sorter: SQLASorter = Depends(
            make_sqla_sorter(
                [WorkItem.id, WorkItem.last_updated],
                default_sort_by=WorkItem.last_updated,
            )),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a list of open work items from the EMPI"""
    query = get_workitems(jtrace,
                          user,
                          statuses=status,
                          facility=facility,
                          since=since,
                          until=until)
    page = paginate(sorter.sort(query))

    for item in page.items:  # type: ignore
        audit.add_workitem(item)

    return page
コード例 #2
0
def master_record_statistics(
    record_id: int,
    user: UKRDCUser = Security(auth.get_user()),
    jtrace: Session = Depends(get_jtrace),
    errorsdb: Session = Depends(get_errorsdb),
    audit: Auditer = Depends(get_auditer),
):
    """Retreive a particular master record from the EMPI"""
    record: MasterRecord = get_masterrecord(jtrace, record_id, user)

    errors = get_messages_related_to_masterrecord(
        errorsdb, jtrace, record.id, user, statuses=["ERROR"]
    )

    related_records = get_masterrecords_related_to_masterrecord(jtrace, record.id, user)

    related_ukrdc_records = related_records.filter(
        MasterRecord.nationalid_type == "UKRDC"
    )

    workitems = get_workitems(
        jtrace, user, master_id=[record.id for record in related_records.all()]
    )

    audit.add_event(
        Resource.STATISTICS,
        None,
        AuditOperation.READ,
        parent=audit.add_event(Resource.MASTER_RECORD, record.id, AuditOperation.READ),
    )

    return MasterRecordStatisticsSchema(
        workitems=workitems.count(),
        errors=errors.count(),
        # Workaround for https://jira.ukrdc.org/browse/UI-56
        # For some reason, if you log in as a non-admin user,
        # related_ukrdc_records.count() returns the wrong value
        # sometimes, despite the query returning the right data.
        # I truly, deeply do not understand why this would happen,
        # so I've had to implement this slightly slower workaround.
        # Assuming the patient doesn't somehow have hundreds of
        # UKRDC records, the speed decrease should be negligable.
        ukrdcids=len(related_ukrdc_records.all()),
    )
コード例 #3
0
ファイル: __init__.py プロジェクト: renalreg/ukrdc-fastapi
def admin_counts(
    jtrace: Session = Depends(get_jtrace),
    statsdb: Session = Depends(get_statsdb),
    user: UKRDCUser = Security(auth.get_user()),
):
    """Retreive basic counts across the UKRDC"""
    open_workitems_count = get_workitems(jtrace, user, [1]).count()
    ukrdc_records_count = (
        jtrace.query(MasterRecord)
        .filter(MasterRecord.nationalid_type == "UKRDC")
        .count()
    )
    patients_receiving_errors_count = (
        statsdb.query(PatientsLatestErrors.ni).distinct().count()
    )

    return AdminCountsSchema(
        open_workitems=open_workitems_count,
        UKRDC_records=ukrdc_records_count,
        patients_receiving_errors=patients_receiving_errors_count,
    )
コード例 #4
0
def master_record_workitems(
    record_id: int,
    user: UKRDCUser = Security(auth.get_user()),
    jtrace: Session = Depends(get_jtrace),
    audit: Auditer = Depends(get_auditer),
):
    """Retreive a list of work items related to a particular master record."""
    related: list[MasterRecord] = get_masterrecords_related_to_masterrecord(
        jtrace, record_id, user
    ).all()

    workitems = get_workitems(
        jtrace, user, master_id=[record.id for record in related]
    ).all()

    record_audit = audit.add_event(
        Resource.MASTER_RECORD, record_id, AuditOperation.READ
    )
    for item in workitems:
        audit.add_workitem(item, parent=record_audit)

    return workitems
コード例 #5
0
def test_get_workitems_masterid(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, master_id=[4])
    assert {item.id for item in all_items} == {1, 2}
コード例 #6
0
def test_get_workitems_until(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, until=days_ago(2))
    assert {item.id for item in all_items} == {1}
コード例 #7
0
def test_get_workitems_since(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, since=days_ago(1))
    assert {item.id for item in all_items} == {2, 3}
コード例 #8
0
def test_get_workitems_statuses(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, statuses=[1, 3])
    assert {item.id for item in all_items} == {1, 2, 3, 4}
コード例 #9
0
def test_get_workitems_facility(jtrace_session, superuser):
    all_items = workitems.get_workitems(jtrace_session, superuser, statuses=[3])
    assert {item.id for item in all_items} == {4}
コード例 #10
0
def test_get_workitems_user(jtrace_session, test_user):
    all_items = workitems.get_workitems(jtrace_session, test_user)
    assert {item.id for item in all_items} == {1, 3}