Skip to content

Commit

Permalink
first working export: fr.CarteVitaleV1
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianMindee committed Oct 6, 2023
1 parent c981cda commit 7ddb74a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/extras/code_samples/carte_vitale_v1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from mindee import Client, PredictResponse, product

# Init a new client
mindee_client = Client(api_key="my-api-key")

# Load a file from disk
input_doc = mindee_client.source_from_path("/path/to/the/file.ext")

# Load a file from disk and parse it.
# The endpoint name must be specified since it cannot be determined from the class.
result: PredictResponse = mindee_client.parse(product.fr.CarteVitaleV1, input_doc)

# Print a brief summary of the parsed data
print(result.document)

# # Iterate over all the fields in the document
# for field_name, field_values in result.document.inference.prediction.fields.items():
# print(field_name, "=", field_values)
1 change: 1 addition & 0 deletions mindee/product/fr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from mindee.product.fr.carte_vitale.carte_vitale_v1 import CarteVitaleV1
Empty file.
32 changes: 32 additions & 0 deletions mindee/product/fr/carte_vitale/carte_vitale_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import List

from mindee.parsing.common import Inference, Page, StringDict
from mindee.product.fr.carte_vitale.carte_vitale_v1_document import (
CarteVitaleV1Document,
)


class CarteVitaleV1(Inference):
"""Inference prediction for Carte Vitale, API version 1."""

prediction: CarteVitaleV1Document
"""Document-level prediction."""
pages: List[Page[CarteVitaleV1Document]]
"""Page-level prediction(s)."""
endpoint_name = "carte_vitale"
"""Name of the endpoint."""
endpoint_version = "1"
"""Version of the endpoint."""

def __init__(self, raw_prediction: StringDict):
"""
Carte Vitale v1 inference.
:param raw_prediction: Raw prediction from the HTTP response.
"""
super().__init__(raw_prediction)

self.prediction = CarteVitaleV1Document(raw_prediction["prediction"])
self.pages = []
for page in raw_prediction["pages"]:
self.pages.append(Page(CarteVitaleV1Document, page))
57 changes: 57 additions & 0 deletions mindee/product/fr/carte_vitale/carte_vitale_v1_document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import List, Optional

from mindee.parsing.common import Prediction, StringDict, clean_out_string
from mindee.parsing.standard import DateField, StringField


class CarteVitaleV1Document(Prediction):
"""Document data for Carte Vitale, API version 1."""

given_names: List[StringField]
"""The given name(s) of the card holder."""
issuance_date: DateField
"""The date the card was issued."""
social_security: StringField
"""The Social Security Number (Numéro de Sécurité Sociale) of the card holder"""
surname: StringField
"""The surname of the card holder."""

def __init__(
self,
raw_prediction: StringDict,
page_id: Optional[int] = None,
):
"""
Carte Vitale document.
:param raw_prediction: Raw prediction from HTTP response
"""

self.given_names = [
StringField(prediction, page_id=page_id)
for prediction in raw_prediction["given_names"]
]
self.issuance_date = DateField(
raw_prediction["issuance_date"],
page_id=page_id,
)
self.social_security = StringField(
raw_prediction["social_security"],
page_id=page_id,
)
self.surname = StringField(
raw_prediction["surname"],
page_id=page_id,
)

def __str__(self) -> str:
given_names = f"\n { ' ' * 15 }".join(
[str(item) for item in self.given_names],
)

return clean_out_string(
f":Given Name(s): {given_names}\n"
f":Surname: {self.surname}\n"
f":Social Security Number: {self.social_security}\n"
f":Issuance Date: {self.issuance_date}\n"
)
Empty file added tests/product/eu/__init__.py
Empty file.

0 comments on commit 7ddb74a

Please sign in to comment.