feat: Добавлен запрос истории линз по пациенту
Добавлен API endpoint и query для получения истории линз по ID пациента.
This commit is contained in:
parent
12eea23299
commit
1541aba89f
@ -1,11 +1,22 @@
|
||||
FROM python:3.10-slim
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
lsb-release \
|
||||
wget \
|
||||
gnupg \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN echo "deb http://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
|
||||
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
|
||||
|
||||
RUN apt-get update && apt-get install -y \
|
||||
libpq-dev \
|
||||
libmagic1 \
|
||||
postgresql-client \
|
||||
postgresql-client-17 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN mkdir -p /app/backups && chmod 777 /app/backups
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY req.txt .
|
||||
|
||||
@ -76,6 +76,15 @@ class LensIssuesRepository:
|
||||
|
||||
return issues, total_count
|
||||
|
||||
async def get_by_patient_id(self, patient_id: int) -> Sequence[LensIssue]:
|
||||
stmt = (
|
||||
select(LensIssue)
|
||||
.filter_by(patient_id=patient_id)
|
||||
.options(joinedload(LensIssue.lens))
|
||||
)
|
||||
result = await self.db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
|
||||
async def get_by_id(self, lens_issue_id: int) -> Optional[LensIssue]:
|
||||
stmt = select(LensIssue).filter_by(id=lens_issue_id)
|
||||
result = await self.db.execute(stmt)
|
||||
|
||||
@ -44,6 +44,22 @@ async def get_all_lens_issues(
|
||||
total_count=total_count
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
'/by-patient/{patient_id}/',
|
||||
response_model=list[LensIssueEntity],
|
||||
summary="Get lens issues by patients id",
|
||||
description="Returns a paginated list of lens issues by patients id",
|
||||
)
|
||||
async def get_lens_issues_by_patient(
|
||||
patient_id: int,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
user=Depends(get_current_user),
|
||||
):
|
||||
lens_issues_service = LensIssuesService(db)
|
||||
return await lens_issues_service.get_lens_issues_by_patient_id(patient_id)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/",
|
||||
response_model=LensIssueEntity,
|
||||
|
||||
@ -45,6 +45,24 @@ class LensIssuesService:
|
||||
total_count
|
||||
)
|
||||
|
||||
async def get_lens_issues_by_patient_id(self, patient_id: int) -> list[LensIssueEntity]:
|
||||
patient = await self.patient_repository.get_by_id(patient_id)
|
||||
|
||||
if not patient:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail='Пациент с таким ID не найден',
|
||||
)
|
||||
|
||||
lens_issues = await self.lens_issues_repository.get_by_patient_id(patient.id)
|
||||
|
||||
print(lens_issues)
|
||||
|
||||
return [
|
||||
self.model_to_entity(lens_issue)
|
||||
for lens_issue in lens_issues
|
||||
]
|
||||
|
||||
async def create_lens_issue(self, lens_issue: LensIssueEntity, user_id: int) -> Optional[LensIssueEntity]:
|
||||
patient = await self.patient_repository.get_by_id(lens_issue.patient_id)
|
||||
|
||||
|
||||
@ -46,10 +46,15 @@ export const lensIssuesApi = createApi({
|
||||
}),
|
||||
invalidatesTags: ['LensIssues'],
|
||||
}),
|
||||
getLensIssuesByPatient: builder.query({
|
||||
query: (patientId) => `/lens_issues/by-patient/${patientId}/`,
|
||||
providesTags: ['LensIssues'],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const {
|
||||
useGetLensIssuesQuery,
|
||||
useAddLensIssuesMutation,
|
||||
useGetLensIssuesByPatientQuery,
|
||||
} = lensIssuesApi;
|
||||
@ -0,0 +1,21 @@
|
||||
import { useGetLensIssuesByPatientQuery } from "../../../../../Api/lensIssuesApi.js";
|
||||
|
||||
const usePatientsViewModal = (patient, visible) => {
|
||||
const {
|
||||
data: lensIssues = [],
|
||||
isLoading: isLensIssuesLoading,
|
||||
isError: isLensIssuesError,
|
||||
} = useGetLensIssuesByPatientQuery(patient?.id, {
|
||||
skip: !visible || !patient?.id,
|
||||
pollingInterval: 60000,
|
||||
refetchOnMountOrArgChange: true,
|
||||
});
|
||||
|
||||
return {
|
||||
lensIssues,
|
||||
isLensIssuesLoading,
|
||||
isLensIssuesError,
|
||||
};
|
||||
};
|
||||
|
||||
export default usePatientsViewModal;
|
||||
Loading…
x
Reference in New Issue
Block a user