|
37 | 37 | Version, |
38 | 38 | ) |
39 | 39 | from apps.answers.errors import AnswerNotFoundError |
40 | | -from apps.applets.db.schemas import AppletHistorySchema, AppletSchema |
| 40 | +from apps.applets.db.schemas import AppletHistorySchema |
41 | 41 | from apps.shared.filtering import Comparisons, FilterField, Filtering |
42 | 42 | from apps.shared.paging import paging |
43 | 43 | from infrastructure.database.crud import BaseCRUD |
@@ -342,64 +342,6 @@ async def get_by_applet_activity_created_at( |
342 | 342 | db_result = await self._execute(query) |
343 | 343 | return db_result.scalars().all() |
344 | 344 |
|
345 | | - async def get_activity_flow_by_answer_id( |
346 | | - self, answer_id: uuid.UUID |
347 | | - ) -> bool: |
348 | | - query: Query = select(AnswerItemSchema, ActivityFlowHistoriesSchema) |
349 | | - query = query.join( |
350 | | - AnswerSchema, AnswerSchema.id == AnswerItemSchema.answer_id |
351 | | - ) |
352 | | - query = query.join( |
353 | | - ActivityFlowHistoriesSchema, |
354 | | - ActivityFlowHistoriesSchema.id_version |
355 | | - == AnswerSchema.flow_history_id, |
356 | | - isouter=True, |
357 | | - ) |
358 | | - query = query.where(AnswerItemSchema.is_assessment == False) # noqa |
359 | | - query = query.where(AnswerSchema.id == answer_id) |
360 | | - |
361 | | - db_result = await self._execute(query) |
362 | | - ( |
363 | | - _, |
364 | | - flow_history_schema, |
365 | | - ) = ( |
366 | | - db_result.first() |
367 | | - ) # type: AnswerItemSchema, ActivityFlowHistoriesSchema |
368 | | - if not flow_history_schema: |
369 | | - return False |
370 | | - return flow_history_schema.is_single_report |
371 | | - |
372 | | - async def get_applet_info_by_answer_id( |
373 | | - self, answer: AnswerSchema |
374 | | - ) -> tuple[AppletHistorySchema, ActivityHistorySchema]: |
375 | | - query: Query = select( |
376 | | - AppletSchema, |
377 | | - ActivityHistorySchema, |
378 | | - ) |
379 | | - query = query.join( |
380 | | - AppletHistorySchema, |
381 | | - AppletHistorySchema.id == AppletSchema.id, |
382 | | - isouter=True, |
383 | | - ) |
384 | | - query = query.join( |
385 | | - ActivityHistorySchema, |
386 | | - and_( |
387 | | - ActivityHistorySchema.applet_id |
388 | | - == AppletHistorySchema.id_version, |
389 | | - ActivityHistorySchema.id_version == answer.activity_history_id, |
390 | | - ), |
391 | | - isouter=True, |
392 | | - ) |
393 | | - query = query.where( |
394 | | - and_( |
395 | | - AppletSchema.id == answer.applet_id, |
396 | | - AppletHistorySchema.version == answer.version, |
397 | | - ) |
398 | | - ) |
399 | | - db_result = await self._execute(query) |
400 | | - res = db_result.first() |
401 | | - return res |
402 | | - |
403 | 345 | async def get_activities_which_has_answer( |
404 | 346 | self, activity_hist_ids: list[str], respondent_id: uuid.UUID | None |
405 | 347 | ) -> list[str]: |
@@ -557,6 +499,20 @@ async def update_encrypted_fields( |
557 | 499 |
|
558 | 500 | await self._execute(query) |
559 | 501 |
|
| 502 | + async def is_single_report_flow(self, answer_flow_id: str | None) -> bool: |
| 503 | + query: Query = select(ActivityFlowHistoriesSchema) |
| 504 | + query = query.where( |
| 505 | + ActivityFlowHistoriesSchema.id_version == answer_flow_id |
| 506 | + ) |
| 507 | + db_result = await self._execute(query) |
| 508 | + db_result = db_result.first() |
| 509 | + flow_history_schema = ( |
| 510 | + db_result[0] if db_result else None |
| 511 | + ) # type: ActivityFlowHistoriesSchema | None |
| 512 | + if not flow_history_schema: |
| 513 | + return False |
| 514 | + return flow_history_schema.is_single_report |
| 515 | + |
560 | 516 | async def get_last_activity( |
561 | 517 | self, respondent_ids: list[uuid.UUID], applet_id: uuid.UUID | None |
562 | 518 | ) -> dict[uuid.UUID, datetime.datetime]: |
|
0 commit comments