diff --git a/genotype_api/dto/sample.py b/genotype_api/dto/sample.py index 0b2d2ea..3cade4d 100644 --- a/genotype_api/dto/sample.py +++ b/genotype_api/dto/sample.py @@ -1,7 +1,7 @@ """Module for the sample DTOs.""" from datetime import datetime -from pydantic import BaseModel, field_validator +from pydantic import BaseModel, computed_field from genotype_api.constants import Sexes, Status, Types from genotype_api.dto.genotype import GenotypeResponse @@ -25,29 +25,27 @@ class SampleResponse(BaseModel): sex: Sexes | None = None created_at: datetime | None = datetime.now() analyses: list[AnalysisOnSample] | None = None - detail: SampleDetail = None - @field_validator("detail") - def get_detail(cls, value, values) -> SampleDetail | None: - analyses = values.get("analyses") + @computed_field(alias="detail") + def get_detail(self) -> SampleDetail | None: + analyses = self.analyses if analyses: if len(analyses) != 2: return SampleDetail() - genotype_analysis: list[AnalysisOnSample] = [ + genotype_analysis: AnalysisOnSample = [ analysis for analysis in analyses if analysis.type == "genotype" ][0] - sequence_analysis: list[AnalysisOnSample] = [ + sequence_analysis: AnalysisOnSample = [ analysis for analysis in analyses if analysis.type == "sequence" ][0] status: dict = check_snps( genotype_analysis=genotype_analysis, sequence_analysis=sequence_analysis ) sex: str = check_sex( - sample_sex=values.get("sex"), + sample_sex=self.sex, genotype_analysis=genotype_analysis, sequence_analysis=sequence_analysis, ) - return SampleDetail(**status, sex=sex) return None