def test_is_implicit_vr(self): """Test DicomIO.is_implicit_VR""" fp = DicomIO() fp.is_implicit_VR = True assert fp.is_implicit_VR fp.is_implicit_VR = False assert not fp.is_implicit_VR
def _write_dataset(fp: DicomIO, dataset: Dataset, write_like_original: bool) -> None: """Write the Data Set to a file-like. Assumes the file meta information, if any, has been written. """ # if we want to write with the same endianness and VR handling as # the read dataset we want to preserve raw data elements for # performance reasons (which is done by get_item); # otherwise we use the default converting item getter if dataset.is_original_encoding: get_item = Dataset.get_item else: get_item = Dataset.__getitem__ # type: ignore[assignment] # WRITE DATASET # The transfer syntax used to encode the dataset can't be changed # within the dataset. # Write any Command Set elements now as elements must be in tag order # Mixing Command Set with other elements is non-conformant so we # require `write_like_original` to be True command_set = get_item(dataset, slice(0x00000000, 0x00010000)) if command_set and write_like_original: fp.is_implicit_VR = True fp.is_little_endian = True write_dataset(fp, command_set) # Set file VR and endianness. MUST BE AFTER writing META INFO (which # requires Explicit VR Little Endian) and COMMAND SET (which requires # Implicit VR Little Endian) fp.is_implicit_VR = cast(bool, dataset.is_implicit_VR) fp.is_little_endian = cast(bool, dataset.is_little_endian) # Write non-Command Set elements now write_dataset(fp, get_item(dataset, slice(0x00010000, None)))
def _harmonize_properties(ds: Dataset, fp: DicomIO) -> None: """Make sure the properties in the dataset and the file pointer are consistent, so the user can set both with the same effect. Properties set on the destination file object always have preference. """ # ensure preference of fp over dataset if hasattr(fp, 'is_little_endian'): ds.is_little_endian = fp.is_little_endian if hasattr(fp, 'is_implicit_VR'): ds.is_implicit_VR = fp.is_implicit_VR # write the properties back to have a consistent state fp.is_implicit_VR = cast(bool, ds.is_implicit_VR) fp.is_little_endian = cast(bool, ds.is_little_endian)