Class: DICOM::AuditTrail
- Inherits:
-
Object
- Object
- DICOM::AuditTrail
- Defined in:
- lib/dicom/audit_trail.rb
Overview
The AuditTrail class handles key/value storage for the Anonymizer. When using the advanced Anonymization options such as enumeration and UID replacement, the AuditTrail class keeps track of key/value pairs and dumps this information to a text file using the json format. This enables us to ensure a unique relationship between the anonymized values and the original values, as well as preserving this relationship for later restoration of original values.
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
readonly
The hash used for storing the key/value pairs of this instace.
Class Method Summary collapse
-
.read(file_name) ⇒ AuditTrail
Creates a new AuditTrail instance by loading the information stored in the specified file.
Instance Method Summary collapse
-
#add_record(tag, original, replacement) ⇒ Object
Adds a tag record to the log.
-
#initialize ⇒ AuditTrail
constructor
Creates a new AuditTrail instance.
-
#load(file_name) ⇒ Object
Loads the key/value dictionary hash from a specified file.
-
#original(tag, replacement) ⇒ String, ...
Retrieves the original value used for the given combination of tag & replacement value.
-
#records(tag) ⇒ Hash
Gives the key/value pairs for a specific tag.
-
#replacement(tag, original) ⇒ String, ...
Retrieves the replacement value used for the given combination of tag & original value.
-
#write(file_name) ⇒ Object
Dumps the key/value pairs to a json string which is written to the specified file.
Constructor Details
#initialize ⇒ AuditTrail
Creates a new AuditTrail instance.
30 31 32 33 34 35 |
# File 'lib/dicom/audit_trail.rb', line 30 def initialize # The AuditTrail requires JSON for serialization: require 'json' # Define the key/value hash used for tag records: @dictionary = Hash.new end |
Instance Attribute Details
#dictionary ⇒ Object (readonly)
The hash used for storing the key/value pairs of this instace.
14 15 16 |
# File 'lib/dicom/audit_trail.rb', line 14 def dictionary @dictionary end |
Class Method Details
.read(file_name) ⇒ AuditTrail
Creates a new AuditTrail instance by loading the information stored in the specified file.
22 23 24 25 26 |
# File 'lib/dicom/audit_trail.rb', line 22 def self.read(file_name) audit_trail = AuditTrail.new audit_trail.load(file_name) return audit_trail end |
Instance Method Details
#add_record(tag, original, replacement) ⇒ Object
Adds a tag record to the log.
43 44 45 46 |
# File 'lib/dicom/audit_trail.rb', line 43 def add_record(tag, original, replacement) @dictionary[tag] = Hash.new unless @dictionary.key?(tag) @dictionary[tag][original] = replacement end |
#load(file_name) ⇒ Object
Loads the key/value dictionary hash from a specified file.
52 53 54 |
# File 'lib/dicom/audit_trail.rb', line 52 def load(file_name) @dictionary = JSON.load(File.new(file_name, "r:UTF-8")) end |
#original(tag, replacement) ⇒ String, ...
Retrieves the original value used for the given combination of tag & replacement value.
62 63 64 65 66 67 68 |
# File 'lib/dicom/audit_trail.rb', line 62 def original(tag, replacement) original = nil if @dictionary.key?(tag) original = @dictionary[tag].key(replacement) end return original end |
#records(tag) ⇒ Hash
Gives the key/value pairs for a specific tag.
75 76 77 78 79 80 81 |
# File 'lib/dicom/audit_trail.rb', line 75 def records(tag) if @dictionary.key?(tag) return @dictionary[tag] else return Hash.new end end |
#replacement(tag, original) ⇒ String, ...
Retrieves the replacement value used for the given combination of tag & original value.
89 90 91 92 93 |
# File 'lib/dicom/audit_trail.rb', line 89 def replacement(tag, original) replacement = nil replacement = @dictionary[tag][original] if @dictionary.key?(tag) return replacement end |
#write(file_name) ⇒ Object
Dumps the key/value pairs to a json string which is written to the specified file.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/dicom/audit_trail.rb', line 99 def write(file_name) # Encode json string: str = JSON.pretty_generate(@dictionary) # Create directory if needed: unless File.directory?(File.dirname(file_name)) require 'fileutils' FileUtils.mkdir_p(File.dirname(file_name)) end # Write to file: File.open(file_name, 'w') {|f| f.write(str) } end |