コード例 #1
0
ファイル: messages.py プロジェクト: renalreg/ukrdc-fastapi
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,
            )))
コード例 #2
0
ファイル: root_paths.py プロジェクト: youwol/py-youwol
async def get_children(
    request: Request,
    document_id: str,
    from_position: float = QueryParam(0, alias="from-position"),
    count: int = QueryParam(1000),
    configuration: Configuration = Depends(get_configuration)):

    headers = generate_headers_downstream(request.headers)
    doc_db_docs = configuration.doc_db_documents
    from_position = position_format(from_position)
    query = Query(where_clause=[
        WhereClause(
            column="parent_document_id", relation="eq", term=document_id),
        WhereClause(column="position", relation="geq", term=from_position),
    ])
    documents_resp = await doc_db_docs.query(query_body=QueryBody(
        max_results=count, query=query),
                                             owner=Configuration.default_owner,
                                             headers=headers)
    documents = [d for d in documents_resp['documents']]

    return GetChildrenResp(documents=[
        GetDocumentResp(storyId=d['story_id'],
                        documentId=d['document_id'],
                        parentDocumentId=d['parent_document_id'],
                        title=d['title'],
                        position=float(d['position']),
                        contentId=d["content_id"]) for d in documents
    ])
コード例 #3
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))
コード例 #4
0
ファイル: root_paths.py プロジェクト: youwol/py-youwol
async def get_entity(
    request: Request,
    entity_id: str,
    include_drives: bool = QueryParam(True, alias="include-drives"),
    include_folders: bool = QueryParam(True, alias="include-folders"),
    include_items: bool = QueryParam(True, alias="include-items"),
    configuration: Configuration = Depends(get_configuration)):

    items_db, folders_db, drives_db = configuration.doc_dbs.items_db,  configuration.doc_dbs.folders_db, \
                                      configuration.doc_dbs.drives_db

    drive = ensure_query_permission(
        request=request,
        docdb=drives_db,
        key="drive_id",
        value=entity_id,
        max_count=1,
        configuration=configuration) if include_drives else None
    folder = ensure_query_permission(
        request=request,
        docdb=folders_db,
        key="folder_id",
        value=entity_id,
        max_count=1,
        configuration=configuration) if include_folders else None
    item = ensure_query_permission(
        request=request,
        docdb=items_db,
        key="item_id",
        value=entity_id,
        max_count=1,
        configuration=configuration) if include_items else None

    futures = [d for d in [item, folder, drive] if d]
    entities = list(flatten(await asyncio.gather(*futures)))
    if not entities:
        raise HTTPException(status_code=404,
                            detail="No entities found with corresponding id")
    entity = entities[0]
    if 'item_id' in entity:
        return EntityResponse(entityType='item',
                              entity=ItemResponse(**convert_out(entity)))

    if 'parent_folder_id' in entity:
        return EntityResponse(entityType='folder',
                              entity=FolderResponse(**convert_out(entity)))

    return EntityResponse(entityType='drive',
                          entity=DriveResponse(**convert_out(entity)))
コード例 #5
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
            )
        )
    )
コード例 #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))
コード例 #7
0
def search_masterrecords(
        pid: list[str] = QueryParam([]),
        mrn_number: list[str] = QueryParam([]),
        ukrdc_number: list[str] = QueryParam([]),
        full_name: list[str] = QueryParam([]),
        dob: list[str] = QueryParam([]),
        facility: list[str] = QueryParam([]),
        search: list[str] = QueryParam([]),
        number_type: list[str] = QueryParam([]),
        include_ukrdc: bool = False,
        user: UKRDCUser = Security(auth.get_user()),
        jtrace: Session = Depends(get_jtrace),
        ukrdc3: Session = Depends(get_ukrdc3),
        audit: Auditer = Depends(get_auditer),
):
    """Search the EMPI for a particular master record"""
    matched_ukrdc_ids = search_masterrecord_ids(mrn_number, ukrdc_number,
                                                full_name, pid, dob, facility,
                                                search, ukrdc3)

    # Matched UKRDC IDs will only give us UKRDC-type Master Records,
    # but we also want the associated NHS/CHI/HSC master records.
    # So, we do a single pass of the link records to expand our selection.
    person_ids = (jtrace.query(LinkRecord.person_id).join(MasterRecord).filter(
        MasterRecord.nationalid.in_(matched_ukrdc_ids)))

    master_ids = (jtrace.query(MasterRecord.id).join(LinkRecord).filter(
        LinkRecord.person_id.in_(person_ids)))

    matched_records = get_masterrecords(jtrace, user).filter(
        MasterRecord.id.in_(master_ids))

    if number_type:
        matched_records = matched_records.filter(
            MasterRecord.nationalid_type.in_(number_type))

    if not include_ukrdc:
        matched_records = matched_records.filter(
            MasterRecord.nationalid_type != "UKRDC")

    page: Page = paginate(matched_records)  # type: ignore

    for record in page.items:
        audit.add_event(Resource.MASTER_RECORD, record.id, AuditOperation.READ)

    return page
コード例 #8
0
ファイル: workitem_id.py プロジェクト: renalreg/ukrdc-fastapi
def workitem_messages(
        workitem_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),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a list of other work items related to a particular work item"""
    workitem = get_extended_workitem(jtrace, workitem_id, user)

    workitem_nis: list[str] = [
        record.nationalid for record in workitem.incoming.master_records
    ]

    if workitem.master_record:
        workitem_nis.append(workitem.master_record.nationalid)

    audit.add_event(
        Resource.MESSAGES,
        None,
        AuditOperation.READ,
        parent=audit.add_event(Resource.WORKITEM, workitem_id,
                               AuditOperation.READ),
    )

    return paginate(
        get_messages(
            errorsdb,
            user,
            statuses=status,
            nis=workitem_nis,
            facility=facility,
            since=since,
            until=until,
        ))
コード例 #9
0
ファイル: search.py プロジェクト: mAAdhaTTah/memezer
 def __init__(self,
              term: Optional[str] = QueryParam(None,
                                               description="Search term")):
     self.term = term