コード例 #1
0
ファイル: __init__.py プロジェクト: renalreg/ukrdc-fastapi
from . import workitem_id

router = APIRouter(tags=["Work Items"])
router.include_router(workitem_id.router)


class UnlinkWorkItemRequestSchema(BaseModel):
    master_record: str = Field(..., title="Master record ID")
    person_id: str = Field(..., title="Person ID")
    comment: Optional[str]


@router.get(
    "/",
    response_model=Page[WorkItemSchema],
    dependencies=[Security(auth.permission(Permissions.READ_WORKITEMS))],
)
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),
):
コード例 #2
0
ファイル: workitem_id.py プロジェクト: renalreg/ukrdc-fastapi
router = APIRouter(prefix="/{workitem_id}")


class CloseWorkItemRequestSchema(JSONModel):
    comment: Optional[str] = Field(None, max_length=100)


class UpdateWorkItemRequestSchema(JSONModel):
    status: Optional[int] = None
    comment: Optional[str] = Field(None, max_length=100)


@router.get(
    "/",
    response_model=WorkItemExtendedSchema,
    dependencies=[Security(auth.permission(Permissions.READ_WORKITEMS))],
)
def workitem_detail(
        workitem_id: int,
        user: UKRDCUser = Security(auth.get_user()),
        jtrace: Session = Depends(get_jtrace),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a particular work item from the EMPI"""
    workitem = get_extended_workitem(jtrace, workitem_id, user)
    audit.add_workitem(workitem)
    return workitem


@router.put(
    "/",
コード例 #3
0
ファイル: empi.py プロジェクト: renalreg/ukrdc-fastapi
    person_id: int = Field(..., title="ID of the person-record to be unlinked")
    master_id: int = Field(..., title="ID of the master-record to unlink from")
    comment: Optional[str] = Field(None, max_length=100)


class UnlinkPatientRequestSchema(JSONModel):
    pid: str = Field(..., title="PID of the patient-record to be unlinked")
    master_id: int = Field(..., title="ID of the master-record to unlink from")


@router.post(
    "/merge/",
    response_model=MirthMessageResponseSchema,
    dependencies=[
        Security(
            auth.permission(
                [Permissions.READ_RECORDS, Permissions.WRITE_RECORDS]))
    ],
)
async def empi_merge(
        args: MergeRequestSchema,
        user: UKRDCUser = Security(auth.get_user()),
        jtrace: Session = Depends(get_jtrace),
        mirth: MirthAPI = Depends(get_mirth),
        redis: Redis = Depends(get_redis),
):
    """Merge a pair of MasterRecords"""

    return await merge_master_records(args.superseding, args.superseded, user,
                                      jtrace, mirth, redis)

コード例 #4
0
class MirthPage(OrmModel):
    """Like a pagination Page but without a total"""

    page: int
    size: int


class MessagePage(MirthPage):
    items: list[MirthChannelMessageModel]


@router.get(
    "/channels/",
    response_model=list[ChannelFullModel],
    dependencies=[Security(auth.permission(Permissions.READ_MIRTH))],
)
async def mirth_channels(redis: Redis = Depends(get_redis)):
    """Retrieve a list of Mirth channels"""
    return get_cached_channels_with_statistics(redis)


@router.get(
    "/groups/",
    response_model=list[ChannelGroupModel],
    dependencies=[Security(auth.permission(Permissions.READ_MIRTH))],
)
async def mirth_groups(
        redis: Redis = Depends(get_redis), ) -> list[ChannelGroupModel]:
    """Retrieve a list of Mirth channel groups"""
    return get_cached_all(redis)
コード例 #5
0
ファイル: persons.py プロジェクト: renalreg/ukrdc-fastapi
    AuditOperation,
    Resource,
    get_auditer,
)
from ukrdc_fastapi.dependencies.auth import Permissions, UKRDCUser, auth
from ukrdc_fastapi.query.masterrecords import get_masterrecords
from ukrdc_fastapi.query.persons import get_person
from ukrdc_fastapi.schemas.empi import MasterRecordSchema, PersonSchema

router = APIRouter(tags=["Persons"])


@router.get(
    "/{person_id}/",
    response_model=PersonSchema,
    dependencies=[Security(auth.permission(Permissions.READ_RECORDS))],
)
def person_detail(
        person_id: int,
        user: UKRDCUser = Security(auth.get_user()),
        jtrace: Session = Depends(get_jtrace),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a particular Person record from the EMPI"""
    person = get_person(jtrace, person_id, user)
    audit.add_event(Resource.PERSON, person.id, AuditOperation.READ)
    return person


@router.get(
    "/{person_id}/masterrecords/",
コード例 #6
0
)
from ukrdc_fastapi.schemas.code import CodeExclusionSchema, CodeMapSchema, CodeSchema
from ukrdc_fastapi.utils.paginate import Page, paginate


class CSVResponse(Response):
    media_type = "text/csv"


router = APIRouter(tags=["Codes"])


@router.get(
    "/list/",
    response_model=Page[CodeSchema],
    dependencies=[Security(auth.permission(Permissions.READ_CODES))],
)
def code_list(
        ukrdc3: Session = Depends(get_ukrdc3),
        coding_standard: Optional[list[str]] = Query(None),
        search: Optional[str] = Query(None),
):
    """Retreive a list of internal codes"""
    return paginate(get_codes(ukrdc3, coding_standard, search))


@router.get(
    "/list/{coding_standard}.{code}/",
    response_model=ExtendedCodeSchema,
    dependencies=[Security(auth.permission(Permissions.READ_CODES))],
)
コード例 #7
0
ファイル: export.py プロジェクト: renalreg/ukrdc-fastapi
    export_all_to_pkb,
    export_all_to_pv,
    export_all_to_radar,
    export_docs_to_pv,
    export_tests_to_pv,
)
from ukrdc_fastapi.tasks.background import TaskTracker, TrackableTaskSchema
from ukrdc_fastapi.utils.mirth import MirthMessageResponseSchema

router = APIRouter(tags=["Patient Records/Export"])


@router.post(
    "/pv/",
    response_model=MirthMessageResponseSchema,
    dependencies=[Security(auth.permission(Permissions.EXPORT_RECORDS))],
)
async def patient_export_pv(
        pid: str,
        user: UKRDCUser = Security(auth.get_user()),
        ukrdc3: Session = Depends(get_ukrdc3),
        mirth: MirthAPI = Depends(get_mirth),
        redis: Redis = Depends(get_redis),
        audit: Auditer = Depends(get_auditer),
):
    """Export a specific patient's data to PV"""
    response = await export_all_to_pv(pid, user, ukrdc3, mirth, redis)
    audit.add_event(Resource.PATIENT_RECORD, pid, RecordOperation.EXPORT_PV)
    return response

コード例 #8
0
ファイル: __init__.py プロジェクト: renalreg/ukrdc-fastapi
from ukrdc_fastapi.schemas.common import HistoryPoint

from . import datahealth

router = APIRouter(tags=["Admin"])
router.include_router(datahealth.router, prefix="/datahealth")


@router.get(
    "/workitems_history",
    response_model=list[HistoryPoint],
    dependencies=[
        Security(
            auth.permission(
                [
                    Permissions.READ_WORKITEMS,
                    Permissions.UNIT_PREFIX + Permissions.UNIT_WILDCARD,
                ]
            )
        )
    ],
)
def full_workitem_history(
    since: Optional[datetime.date] = None,
    until: Optional[datetime.date] = None,
    jtrace: Session = Depends(get_jtrace),
):
    """Retreive basic statistics about recent records"""
    return get_full_workitem_history(jtrace, since, until)


@router.get(
コード例 #9
0
from .dependencies import _get_patientrecord

router = APIRouter(tags=["Patient Records/Update"])


class DemographicUpdateSchema(JSONModel):
    name: Optional[NameSchema]
    birth_time: Optional[datetime.date]
    gender: Optional[GenderType]
    address: Optional[AddressSchema]


@router.post(
    "/demographics/",
    response_model=MirthMessageResponseSchema,
    dependencies=[Security(auth.permission(Permissions.WRITE_RECORDS))],
)
async def patient_update_demographics(
    demographics: DemographicUpdateSchema,
    patient_record: PatientRecord = Depends(_get_patientrecord),
    mirth: MirthAPI = Depends(get_mirth),
    redis: Redis = Depends(get_redis),
    audit: Auditer = Depends(get_auditer),
):
    """
    Update the demographic data of a given patient record

    Args:
        demographics (DemographicUpdateSchema): [description]
        patient_record (PatientRecord, optional): [description]. Defaults to Depends(_get_patientrecord).
        mirth (MirthAPI, optional): [description]. Defaults to Depends(get_mirth).
コード例 #10
0
from ukrdc_fastapi.utils.sort import SQLASorter, make_sqla_sorter


class MasterRecordStatisticsSchema(OrmModel):
    workitems: int
    errors: int
    ukrdcids: int


router = APIRouter(prefix="/{record_id}")


@router.get(
    "/",
    response_model=MasterRecordSchema,
    dependencies=[Security(auth.permission(Permissions.READ_RECORDS))],
)
def master_record_detail(
    record_id: int,
    user: UKRDCUser = Security(auth.get_user()),
    jtrace: Session = Depends(get_jtrace),
    audit: Auditer = Depends(get_auditer),
):
    """Retreive a particular master record from the EMPI"""
    record = get_masterrecord(jtrace, record_id, user)

    audit.add_event(Resource.MASTER_RECORD, record.id, AuditOperation.READ)

    return record

コード例 #11
0
ファイル: messages.py プロジェクト: renalreg/ukrdc-fastapi
from ukrdc_fastapi.schemas.message import MessageSchema
from ukrdc_fastapi.utils.paginate import Page, paginate
from ukrdc_fastapi.utils.sort import SQLASorter

router = APIRouter(tags=["Messages"])


class MessageSourceSchema(OrmModel):
    content: Optional[str]
    content_type: Optional[str]


@router.get(
    "/",
    response_model=Page[MessageSchema],
    dependencies=[Security(auth.permission(Permissions.READ_MESSAGES))],
)
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.
コード例 #12
0
from ukrdc_fastapi.utils.sort import SQLASorter, make_sqla_sorter

from . import export, update
from .dependencies import _get_patientrecord

router = APIRouter(prefix="/{pid}")
router.include_router(export.router, prefix="/export")
router.include_router(update.router, prefix="/update")

# Self-resources


@router.get(
    "/",
    response_model=PatientRecordSchema,
    dependencies=[Security(auth.permission(Permissions.READ_RECORDS))],
)
def patient_get(
        patient_record: PatientRecord = Depends(_get_patientrecord),
        jtrace: Session = Depends(get_jtrace),
        audit: Auditer = Depends(get_auditer),
):
    """Retreive a specific patient record"""
    # For some reason the fastAPI response_model doesn't call our master_record_compute
    # validator, meaning we don't get a populated master record unless we explicitly
    # call it here.
    record: PatientRecordSchema = PatientRecordSchema.from_orm_with_master_record(
        patient_record, jtrace)
    audit.add_event(Resource.PATIENT_RECORD, patient_record.pid,
                    RecordOperation.READ)
    return record
コード例 #13
0
ファイル: datahealth.py プロジェクト: renalreg/ukrdc-fastapi
from ukrdc_fastapi.dependencies import get_jtrace, get_statsdb
from ukrdc_fastapi.dependencies.auth import Permissions, auth
from ukrdc_fastapi.query.stats import get_multiple_ukrdcids
from ukrdc_fastapi.schemas.admin import LastRunTime, MultipleUKRDCIDGroup
from ukrdc_fastapi.utils.paginate import Page, paginate_sequence

router = APIRouter(tags=["Admin/Data Health"])


@router.get(
    "/multiple_ukrdcids",
    response_model=Page[MultipleUKRDCIDGroup],
    dependencies=[
        Security(
            auth.permission([
                Permissions.READ_RECORDS,
                Permissions.UNIT_PREFIX + Permissions.UNIT_WILDCARD,
            ]))
    ],
)
def datahealth_multiple_ukrdcids(
        jtrace: Session = Depends(get_jtrace),
        statsdb: Session = Depends(get_statsdb),
):
    """Retreive list of patients with multiple UKRDC IDs"""
    return paginate_sequence(get_multiple_ukrdcids(statsdb, jtrace))


@router.get("/multiple_ukrdcids/last_run", response_model=LastRunTime)
def datahealth_multiple_ukrdcids_last_run(
        statsdb: Session = Depends(get_statsdb), ):
    """Retreive the datetime the multiple_ukrdcid table was fully refreshed"""