Aidbox/aidbox-python

Support Pydantic 2.0 & Pydantic [email] 2.0

Closed this issue · 5 comments

Currenly Pydantic version is 2.4 . There're conflicts in the virtual environment for some users

The patient.save() gives the following error with newer version of Pydantic
File "\venv\lib\site-packages\aidbox\base_init_.py", line 108, in save
json=self.model_dump(exclude_unset=True),
AttributeError: 'Patient' object has no attribute 'model_dump'

def save(self):  # create | persist | save
    resource_type = self.__class__.__name__
    response = requests.put(
        url=f"{base}/fhir/{resource_type}/{self.id or ''}",
        json=self.model_dump(exclude_unset=True),
        auth=basic,
    )
    response.raise_for_status()  # TODO: handle and type HTTP codes except 200+
    data = response.json()
    self.id = data["id"]
    self.meta = Meta(**data["meta"])

@st185229 I've downgraded version to 2.0 and include email validation but not sure yet that it is the problem that you faced.
There is the way I suggest to use validation - ContactPointEmail extends ContactPoint base class, but if you have better example of usage validator, please share! I'm curious how you use it in your projects

from aidbox.resource.patient import Patient
from aidbox.base import ContactPoint, ContactPointEmail

patient = Patient()

patient.telecom = [
    ContactPoint(system="phone", value="+1"),
    ContactPointEmail(value="gena@gmail.com"),
]

Hi @st185229 did you have a chance to try it out?

Thanks for doing this. I haven't tried this out so far, but I will do it next week and let you know. Thanks for fixing this

I have tested this and this can be closed now