|
| 1 | +from typing import List, Optional, TypeVar |
| 2 | + |
| 3 | +from mindee.documents.base import Document, TypeApiPrediction, clean_out_string |
| 4 | +from mindee.fields.date import DateField |
| 5 | +from mindee.fields.text import TextField |
| 6 | + |
| 7 | + |
| 8 | +class CarteVitaleV1(Document): |
| 9 | + """A Carte Vitale prediction.""" |
| 10 | + |
| 11 | + given_names: List[TextField] |
| 12 | + """The given name(s) of the card holder.""" |
| 13 | + surname: TextField |
| 14 | + """The surname of the card holder.""" |
| 15 | + social_security: TextField |
| 16 | + """The Social Security Number (Numéro de Sécurité Sociale) of the card holder""" |
| 17 | + issuance_date: DateField |
| 18 | + """The date the card was issued.""" |
| 19 | + |
| 20 | + def __init__( |
| 21 | + self, |
| 22 | + api_prediction=None, |
| 23 | + input_source=None, |
| 24 | + page_n: Optional[int] = None, |
| 25 | + document_type="carte_vitale", |
| 26 | + ): |
| 27 | + """ |
| 28 | + document. |
| 29 | +
|
| 30 | + :param api_prediction: Raw prediction from HTTP response |
| 31 | + :param input_source: Input object |
| 32 | + :param page_n: Page number for multi pages pdf input |
| 33 | + """ |
| 34 | + super().__init__( |
| 35 | + input_source=input_source, |
| 36 | + document_type=document_type, |
| 37 | + api_prediction=api_prediction, |
| 38 | + page_n=page_n, |
| 39 | + ) |
| 40 | + self._build_from_api_prediction(api_prediction["prediction"], page_n=page_n) |
| 41 | + |
| 42 | + def _build_from_api_prediction( |
| 43 | + self, api_prediction: TypeApiPrediction, page_n: Optional[int] = None |
| 44 | + ) -> None: |
| 45 | + """ |
| 46 | + Build the object from the prediction API JSON. |
| 47 | +
|
| 48 | + :param api_prediction: Raw prediction from HTTP response |
| 49 | + :param page_n: Page number |
| 50 | + """ |
| 51 | + self.given_names = [ |
| 52 | + TextField(prediction, page_n=page_n) |
| 53 | + for prediction in api_prediction["given_names"] |
| 54 | + ] |
| 55 | + self.surname = TextField( |
| 56 | + api_prediction["surname"], |
| 57 | + page_n=page_n, |
| 58 | + ) |
| 59 | + self.social_security = TextField( |
| 60 | + api_prediction["social_security"], |
| 61 | + page_n=page_n, |
| 62 | + ) |
| 63 | + self.issuance_date = DateField( |
| 64 | + api_prediction["issuance_date"], |
| 65 | + page_n=page_n, |
| 66 | + ) |
| 67 | + |
| 68 | + def __str__(self) -> str: |
| 69 | + return clean_out_string( |
| 70 | + "----- Carte Vitale V1 -----\n" |
| 71 | + f"Given Name(s): {self.given_names}" |
| 72 | + f"Surname: {self.surname}" |
| 73 | + f"Social Security Number: {self.social_security}" |
| 74 | + f"Issuance Date: {self.issuance_date}" |
| 75 | + "----------------------" |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +TypeCarteVitaleV1 = TypeVar("TypeCarteVitaleV1", bound=CarteVitaleV1) |
0 commit comments