Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def master_record_audit(
    record_id: int,
    user: UKRDCUser = Security(auth.get_user()),
    jtrace: Session = Depends(get_jtrace),
    ukrdc3: Session = Depends(get_ukrdc3),
    auditdb: Session = Depends(get_auditdb),
    since: Optional[datetime.datetime] = None,
    until: Optional[datetime.datetime] = None,
    sorter: SQLASorter = Depends(
        make_sqla_sorter(
            [AuditEvent.id, AccessEvent.time],
            default_sort_by=AuditEvent.id,
        )
    ),
):
    """
    Retreive a page of audit events related to a particular master record.
    """
    page = paginate(
        sorter.sort(
            get_auditevents_related_to_masterrecord(
                auditdb, ukrdc3, jtrace, record_id, user, since=since, until=until
            )
        )
    )

    for item in page.items:  # type: ignore
        item.populate_identifiers(jtrace, ukrdc3)

    return page
Ejemplo n.º 3
0
def master_record_messages(
    record_id: int,
    facility: Optional[str] = None,
    since: Optional[datetime.datetime] = None,
    until: Optional[datetime.datetime] = None,
    status: Optional[list[str]] = QueryParam(None),
    user: UKRDCUser = Security(auth.get_user()),
    jtrace: Session = Depends(get_jtrace),
    errorsdb: Session = Depends(get_errorsdb),
    sorter: SQLASorter = Depends(ERROR_SORTER),
    audit: Auditer = Depends(get_auditer),
):
    """
    Retreive a list of errors related to a particular master record.
    By default returns message created within the last 365 days.
    """
    audit.add_event(
        Resource.MESSAGES,
        None,
        AuditOperation.READ,
        parent=audit.add_event(Resource.MASTER_RECORD, record_id, AuditOperation.READ),
    )
    return paginate(
        sorter.sort(
            get_messages_related_to_masterrecord(
                errorsdb, jtrace, record_id, user, status, facility, since, until
            )
        )
    )
Ejemplo n.º 4
0
def error_messages(
        facility: Optional[str] = None,
        since: Optional[datetime.datetime] = None,
        until: Optional[datetime.datetime] = None,
        status: Optional[list[str]] = QueryParam(None),
        ni: Optional[list[str]] = QueryParam([]),
        user: UKRDCUser = Security(auth.get_user()),
        errorsdb: Session = Depends(get_errorsdb),
        sorter: SQLASorter = Depends(ERROR_SORTER),
        audit: Auditer = Depends(get_auditer),
):
    """
    Retreive a list of error messages, optionally filtered by NI, facility, or date.
    By default returns message created within the last 365 days.
    """
    audit.add_event(Resource.MESSAGES, None, MessageOperation.READ)
    return paginate(
        sorter.sort(
            get_messages(
                errorsdb,
                user,
                statuses=status,
                nis=ni,
                facility=facility,
                since=since,
                until=until,
            )))
Ejemplo n.º 5
0
def patient_resultitems(
        patient_record: PatientRecord = Depends(_get_patientrecord),
        service_id: Optional[list[str]] = QueryParam([]),
        order_id: Optional[list[str]] = QueryParam([]),
        since: Optional[datetime.datetime] = None,
        until: Optional[datetime.datetime] = None,
        sorter: SQLASorter = Depends(
            make_sqla_sorter(
                [ResultItem.observation_time, ResultItem.entered_on],
                default_sort_by=ResultItem.observation_time,
            )),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a specific patient's lab orders"""

    query = patient_record.result_items

    if service_id:
        query = query.filter(ResultItem.service_id.in_(service_id))
    if order_id:
        query = query.filter(ResultItem.order_id.in_(order_id))
    if since:
        query = query.filter(ResultItem.observation_time >= since)
    if until:
        query = query.filter(ResultItem.observation_time <= until)

    audit.add_event(
        Resource.RESULTITEMS,
        None,
        RecordOperation.READ,
        parent=audit.add_event(Resource.PATIENT_RECORD, patient_record.pid,
                               RecordOperation.READ),
    )

    return paginate(sorter.sort(query))
Ejemplo n.º 6
0
def patient_observations(
        patient_record: PatientRecord = Depends(_get_patientrecord),
        code: Optional[list[str]] = QueryParam([]),
        sorter: SQLASorter = Depends(
            make_sqla_sorter(
                [Observation.observation_time, Observation.updated_on],
                default_sort_by=Observation.observation_time,
            )),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a specific patient's lab orders"""
    observations = patient_record.observations
    if code:
        observations = observations.filter(
            Observation.observation_code.in_(code))

    audit.add_event(
        Resource.OBSERVATIONS,
        None,
        RecordOperation.READ,
        parent=audit.add_event(Resource.PATIENT_RECORD, patient_record.pid,
                               RecordOperation.READ),
    )

    return paginate(sorter.sort(observations))
Ejemplo n.º 7
0
def facility_patients_latest_errors(
        code: str,
        ukrdc3: Session = Depends(get_ukrdc3),
        errorsdb: Session = Depends(get_errorsdb),
        statsdb: Session = Depends(get_statsdb),
        user: UKRDCUser = Security(auth.get_user()),
        sorter: SQLASorter = Depends(ERROR_SORTER),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive time-series new error counts for the last year for a particular facility"""
    query = get_patients_latest_errors(ukrdc3, errorsdb, statsdb, code, user)

    audit.add_event(
        Resource.MESSAGES,
        None,
        AuditOperation.READ,
        parent=audit.add_event(Resource.FACILITY, code, AuditOperation.READ),
    )

    return paginate(sorter.sort(query))
Ejemplo n.º 8
0
def patient_documents(
        patient_record: PatientRecord = Depends(_get_patientrecord),
        sorter: SQLASorter = Depends(
            make_sqla_sorter(
                [Document.documenttime, Document.updatedon],
                default_sort_by=Document.documenttime,
            )),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a specific patient's documents"""
    audit.add_event(
        Resource.DOCUMENTS,
        None,
        RecordOperation.READ,
        parent=audit.add_event(Resource.PATIENT_RECORD, patient_record.pid,
                               RecordOperation.READ),
    )
    # NOTE: We defer the 'stream' column to avoid sending the full PDF file content
    # when we're just querying the list of documents.
    return paginate(
        sorter.sort(patient_record.documents.options(defer("stream"))))