def from_json( cls: Type["DataElement"], dataset_class: Type["Dataset"], tag: str, vr: str, value: Any, value_key: Optional[str], bulk_data_uri_handler: Optional[Union[Callable[[str, str, str], BulkDataType], Callable[[str], BulkDataType]]] = None ) -> "DataElement": """Return a :class:`DataElement` from a DICOM JSON Model attribute object. .. versionadded:: 1.3 Parameters ---------- dataset_class : dataset.Dataset derived class The class object to use for **SQ** element items. tag : str The data element's tag as uppercase hex. vr : str The data element's value representation (VR). value : str or List[Union[None, str, int, float, bytes, dict]] The data element's value(s). value_key : str or None The attribute name for `value`, should be one of: ``{"Value", "InlineBinary", "BulkDataURI"}``. If the element's VM is ``0`` and none of the keys are used then will be ``None``. bulk_data_uri_handler: callable or None Callable function that accepts either the `tag`, `vr` and "BulkDataURI" `value` or just the "BulkDataURI" `value` of the JSON representation of a data element and returns the actual value of that data element (retrieved via DICOMweb WADO-RS). If no `bulk_data_uri_handler` is specified (default) then the corresponding element will have an "empty" value such as ``""``, ``b""`` or ``None`` depending on the `vr` (i.e. the Value Multiplicity will be 0). Returns ------- DataElement """ # TODO: test wado-rs retrieve wrapper converter = JsonDataElementConverter(dataset_class, tag, vr, value, value_key, bulk_data_uri_handler) elem_value = converter.get_element_values() try: return cls(tag=tag, value=elem_value, VR=vr) except Exception as exc: raise ValueError( f"Data element '{tag}' could not be loaded from JSON: " f"{elem_value}") from exc
def from_json( cls: Type[_DataElement], dataset_class: Type[_Dataset], tag: Union[BaseTag, int], vr: str, value: object, value_key: Union[str, None], bulk_data_uri_handler: Optional[ Union[ Callable[[BaseTag, str, str], object], Callable[[str], object] ] ] = None ) -> _DataElement: """Return a :class:`DataElement` from JSON. .. versionadded:: 1.3 Parameters ---------- dataset_class : dataset.Dataset derived class Class used to create sequence items. tag : pydicom.tag.BaseTag or int The data element tag. vr : str The data element value representation. value : list The data element's value(s). value_key : str or None Key of the data element that contains the value (options: ``{"Value", "InlineBinary", "BulkDataURI"}``) bulk_data_uri_handler: callable or None Callable function that accepts either the tag, vr and "BulkDataURI" or just the "BulkDataURI" of the JSON representation of a data element and returns the actual value of that data element (retrieved via DICOMweb WADO-RS) Returns ------- DataElement """ # TODO: test wado-rs retrieve wrapper converter = JsonDataElementConverter( dataset_class, tag, vr, value, value_key, bulk_data_uri_handler ) elem_value = converter.get_element_values() try: return cls(tag=tag, value=elem_value, VR=vr) except Exception as exc: raise ValueError( f"Data element '{tag}' could not be loaded from JSON: " f"{elem_value}" ) from exc
def from_json(cls, dataset_class, tag, vr, value, value_key, bulk_data_uri_handler=None): """Return a :class:`DataElement` from JSON. .. versionadded:: 1.3 Parameters ---------- dataset_class : dataset.Dataset derived class Class used to create sequence items. tag : BaseTag or int The data element tag. vr : str The data element value representation. value : list The data element's value(s). value_key : str or None Key of the data element that contains the value (options: ``{"Value", "InlineBinary", "BulkDataURI"}``) bulk_data_uri_handler: callable or None Callable function that accepts the "BulkDataURI" of the JSON representation of a data element and returns the actual value of that data element (retrieved via DICOMweb WADO-RS) Returns ------- DataElement """ # TODO: test wado-rs retrieve wrapper converter = JsonDataElementConverter(dataset_class, tag, vr, value, value_key, bulk_data_uri_handler) elem_value = converter.get_element_values() try: return DataElement(tag=tag, value=elem_value, VR=vr) except Exception: raise ValueError( 'Data element "{}" could not be loaded from JSON: {}'.format( tag, elem_value))