File size: 1,348 Bytes
a671976
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Per-section note model produced by the schema-driven notes parser."""

from __future__ import annotations

from pydantic import BaseModel, Field, model_validator


class SectionNote(BaseModel):
    """Scrubbed notes routed to a single discovered section."""

    section_id: str = Field(description="Target section id, or 'UNASSIGNED'.")
    text: str = Field(
        default="", description="Joined verbatim note text for this section."
    )
    raw_observations: list[str] = Field(
        default_factory=list,
        description="Individual observations extracted from the notes.",
    )
    rating_value: str | None = Field(
        default=None,
        description="Detected rating token, only set when the schema has a rating system.",
    )
    shorthand_expanded: str | None = Field(
        default=None,
        description="Expanded shorthand text when notes_expansion_enabled is active.",
    )

    @model_validator(mode="after")
    def _sync_text_from_observations(self) -> SectionNote:
        if self.raw_observations and not self.text.strip():
            self.text = "\n".join(self.raw_observations).strip()
        elif self.text.strip() and not self.raw_observations:
            self.raw_observations = [
                line.strip() for line in self.text.split("\n") if line.strip()
            ]
        return self