# Path: pyehr/ehr/services/dbmanager/errors.py
# class InvalidJsonStructureError(Exception):
#     pass
# 
# class OperationNotAllowedError(Exception):
#     pass


from abc import ABCMeta, abstractmethod
from voluptuous import Schema, Required, MultipleInvalid, Coerce
from uuid import uuid4
from pyehr.ehr.services.dbmanager.errors import InvalidJsonStructureError,\
    OperationNotAllowedError
from pyehr.utils import cleanup_json, decode_dict
import time
        json['ehr_records'] = []
        for e in self.ehr_records:
            json['ehr_records'].append(e.to_json())
        return json

    @classmethod
    def from_json(cls, json_data):
        """
        Create a :class:`PatientRecord` object from the given JSON dictionary, if one or more :class:`ClinicalRecord`
        objects in JSON format are encoded in ehr_records field, create these objects as well

        :param json_data: the JSON corresponding to the :class:`PatientRecord` object
        :type json_data: dictionary
        :return: a :class:`PatientRecord` object
        :rtype: :class:`PatientRecord`
        """
        schema = Schema({
            'creation_time': float,
            'last_update': float,
            'record_id': str,
            'active': bool,
            Required('ehr_records'): list
        })
        try:
            json_data = decode_dict(json_data)
            schema(json_data)
            ehr_records = [ClinicalRecord.from_json(ehr) for ehr in json_data['ehr_records']]
            json_data['ehr_records'] = ehr_records
            return PatientRecord(**json_data)
        except MultipleInvalid:

# Path: pyehr/ehr/services/dbmanager/errors.py
# class InvalidJsonStructureError(Exception):
#     pass
# 
# class OperationNotAllowedError(Exception):
#     pass


# Path: pyehr/ehr/services/dbmanager/dbservices/wrappers.py
from abc import ABCMeta, abstractmethod
from voluptuous import Schema, Required, MultipleInvalid, Coerce
from uuid import uuid4
from pyehr.ehr.services.dbmanager.errors import InvalidJsonStructureError,\
    OperationNotAllowedError
from pyehr.utils import cleanup_json, decode_dict
import time

        json['ehr_records'] = []
        for e in self.ehr_records:
            json['ehr_records'].append(e.to_json())
        return json

    @classmethod
    def from_json(cls, json_data):
        """
        Create a :class:`PatientRecord` object from the given JSON dictionary, if one or more :class:`ClinicalRecord`
        objects in JSON format are encoded in ehr_records field, create these objects as well

        :param json_data: the JSON corresponding to the :class:`PatientRecord` object
        :type json_data: dictionary
        :return: a :class:`PatientRecord` object
        :rtype: :class:`PatientRecord`
        """
        schema = Schema({
            'creation_time': float,
            'last_update': float,
            'record_id': str,
            'active': bool,
            Required('ehr_records'): list
        })
        try:
            json_data = decode_dict(json_data)
            schema(json_data)
            ehr_records = [ClinicalRecord.from_json(ehr) for ehr in json_data['ehr_records']]
            json_data['ehr_records'] = ehr_records
            return PatientRecord(**json_data)
        except MultipleInvalid:

            raise InvalidJsonStructureError('JSON record\'s structure is not compatible with PatientRecord object')