# 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
        })

    @classmethod
    def from_json(cls, json_data):
        """
        Create a :class:`ClinicalRecord` object from the given JSON dictionary

        :param json_data: the JSON corresponding to the :class:`ClinicalRecord` object
        :type json_data: dictionary
        :return: a :class:`ClinicalRecord` object
        :rtype: :class:`ClinicalRecord`
        """
        schema = cls._get_validation_schema()
        try:
            json_data = decode_dict(json_data)
            schema(json_data)
            json_data['ehr_data'] = ArchetypeInstance.from_json(json_data['ehr_data'])
            try:
                patient_id = json_data.pop('patient_id')
            except KeyError:
                patient_id = None
            crec = ClinicalRecord(**json_data)
            if patient_id:
                crec._set_patient_id(patient_id)
            return crec
        except MultipleInvalid:
            raise InvalidJsonStructureError('JSON record\'s structure is not compatible with ClinicalRecord object')

    def convert_to_revision(self):
        if not self.is_persistent:

# 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

        })

    @classmethod
    def from_json(cls, json_data):
        """
        Create a :class:`ClinicalRecord` object from the given JSON dictionary

        :param json_data: the JSON corresponding to the :class:`ClinicalRecord` object
        :type json_data: dictionary
        :return: a :class:`ClinicalRecord` object
        :rtype: :class:`ClinicalRecord`
        """
        schema = cls._get_validation_schema()
        try:
            json_data = decode_dict(json_data)
            schema(json_data)
            json_data['ehr_data'] = ArchetypeInstance.from_json(json_data['ehr_data'])
            try:
                patient_id = json_data.pop('patient_id')
            except KeyError:
                patient_id = None
            crec = ClinicalRecord(**json_data)
            if patient_id:
                crec._set_patient_id(patient_id)
            return crec
        except MultipleInvalid:
            raise InvalidJsonStructureError('JSON record\'s structure is not compatible with ClinicalRecord object')

    def convert_to_revision(self):
        if not self.is_persistent:

            raise OperationNotAllowedError('Non persistent record can\'t be converted to ClinicalRecordRevision')