Production
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
"""ORM → response-schema mapping for reports."""
|
||||
|
||||
from app.reports.models import DailyCallReport
|
||||
from app.reports.schemas import (
|
||||
ChemistCallRead,
|
||||
DCRListItem,
|
||||
DCRRead,
|
||||
DoctorCallRead,
|
||||
)
|
||||
|
||||
|
||||
def to_read(dcr: DailyCallReport) -> DCRRead:
|
||||
return DCRRead(
|
||||
id=dcr.id,
|
||||
mr_user_id=dcr.mr_user_id,
|
||||
mr_name=dcr.mr.full_name,
|
||||
employee_code=dcr.mr.employee_code,
|
||||
headquarters_id=dcr.headquarters_id,
|
||||
headquarters_name=dcr.headquarters.name,
|
||||
report_date=dcr.report_date,
|
||||
status=dcr.status,
|
||||
is_locked=dcr.is_locked,
|
||||
mr_remarks=dcr.mr_remarks,
|
||||
stockist_visit=dcr.stockist_visit,
|
||||
order_value=dcr.order_value,
|
||||
return_reason=dcr.return_reason,
|
||||
returned_by_role=dcr.returned_by_role,
|
||||
submitted_at=dcr.submitted_at,
|
||||
approved_at=dcr.approved_at,
|
||||
doctor_calls=[
|
||||
DoctorCallRead(
|
||||
id=c.id,
|
||||
doctor_id=c.doctor_id,
|
||||
doctor_name=c.doctor.name,
|
||||
doctor_speciality=c.doctor.speciality,
|
||||
is_core_doctor=c.doctor.is_core_doctor,
|
||||
visit_time=c.visit_time,
|
||||
call_outcome=c.call_outcome,
|
||||
conversion_status=c.conversion_status,
|
||||
product_promote=c.product_promote,
|
||||
product_sample=c.product_sample,
|
||||
remarks=c.remarks,
|
||||
)
|
||||
for c in sorted(dcr.doctor_calls, key=lambda x: x.visit_time)
|
||||
],
|
||||
chemist_calls=[
|
||||
ChemistCallRead(
|
||||
id=c.id,
|
||||
chemist_id=c.chemist_id,
|
||||
chemist_name=c.chemist.name,
|
||||
visit_time=c.visit_time,
|
||||
pob=c.pob,
|
||||
remarks=c.remarks,
|
||||
)
|
||||
for c in sorted(dcr.chemist_calls, key=lambda x: x.visit_time)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
def to_list_item(dcr: DailyCallReport) -> DCRListItem:
|
||||
return DCRListItem(
|
||||
id=dcr.id,
|
||||
report_date=dcr.report_date,
|
||||
status=dcr.status,
|
||||
mr_user_id=dcr.mr_user_id,
|
||||
mr_name=dcr.mr.full_name,
|
||||
headquarters_id=dcr.headquarters_id,
|
||||
headquarters_name=dcr.headquarters.name,
|
||||
doctor_call_count=len(dcr.doctor_calls),
|
||||
chemist_call_count=len(dcr.chemist_calls),
|
||||
submitted_at=dcr.submitted_at,
|
||||
approved_at=dcr.approved_at,
|
||||
returned_by_role=dcr.returned_by_role,
|
||||
)
|
||||
Reference in New Issue
Block a user