Repository: blairconrad/dicognito

Issue:
Fails to anonymize object with Issue Date of Imaging Service Request
… because we look for "Date" at the beginning or end of the element name:

```
UnboundLocalError: With tag (200b, 102b) got exception: local variable 'time_name' referenced before assignment
Traceback (most recent call last):
  File "c:\program files\python37\lib\site-packages\pydicom\tag.py", line 30, in tag_in_exception
    yield
  File "c:\program files\python37\lib\site-packages\pydicom\dataset.py", line 1773, in walk
    callback(self, data_element)  # self = this Dataset
  File "c:\program files\python37\lib\site-packages\dicognito\anonymizer.py", line 120, in _anonymize_element
    if handler(dataset, data_element):
  File "c:\program files\python37\lib\site-packages\dicognito\datetimeanonymizer.py", line 43, in __call__
    self._anonymize_date_and_time(dataset, data_element)
  File "c:\program files\python37\lib\site-packages\dicognito\datetimeanonymizer.py", line 61, in _anonymize_date_and_time
    if time_name in dataset:
UnboundLocalError: local variable 'time_name' referenced before assignment
```

Comments:

Patch:
diff --git a/src/dicognito/datetimeanonymizer.py b/src/dicognito/datetimeanonymizer.py
index 14ccade..90c6818 100644
--- a/src/dicognito/datetimeanonymizer.py
+++ b/src/dicognito/datetimeanonymizer.py
@@ -53,10 +53,7 @@ class DateTimeAnonymizer:
             dates = [data_element.value]
 
         times = []
-        if data_element.keyword.endswith("Date"):
-            time_name = data_element.keyword[:-4] + "Time"
-        elif data_element.keyword.startswith("Date"):
-            time_name = "Time" + data_element.keyword[4:]
+        time_name = data_element.keyword.replace("Date", "Time")
 
         if time_name in dataset:
             time_value = dataset.data_element(time_name).value
diff --git a/src/dicognito/release_notes.md b/src/dicognito/release_notes.md
index 61c64a5..d3285cd 100644
--- a/src/dicognito/release_notes.md
+++ b/src/dicognito/release_notes.md
@@ -1,8 +1,12 @@
-## 0.9.0
-
+### Fixed
+
+- Fails to anonymize object with Issue Date of Imaging Service Request ([#72](https://github.com/blairconrad/dicognito/issues/72))
+
+## 0.9.0
+
 ### New
 
-- Add option to write anonymized files to another directory([#69](https://github.com/blairconrad/dicognito/issues/69))
+- Add option to write anonymized files to another directory ([#69](https://github.com/blairconrad/dicognito/issues/69))
 
 ## 0.8.1
 


Test patch:
diff --git a/tests/test_anonymize_single_instance.py b/tests/test_anonymize_single_instance.py
index 567e996..23a05bc 100644
--- a/tests/test_anonymize_single_instance.py
+++ b/tests/test_anonymize_single_instance.py
@@ -452,6 +452,23 @@ def test_multivalued_date_and_time_pair_gets_anonymized():
     assert len(new_time) == len(original_time)
 
 
+def test_issue_date_of_imaging_service_request_gets_anonymized():
+    original_datetime = datetime.datetime(1974, 11, 3, 12, 15, 58)
+    original_date_string = original_datetime.strftime("%Y%m%d")
+    original_time_string = original_datetime.strftime("%H%M%S")
+
+    with load_test_instance() as dataset:
+        dataset.IssueDateOfImagingServiceRequest = original_date_string
+        dataset.IssueTimeOfImagingServiceRequest = original_time_string
+
+        anonymizer = Anonymizer()
+        anonymizer.anonymize(dataset)
+
+        new_date_string = dataset.IssueDateOfImagingServiceRequest
+        new_time_string = dataset.IssueTimeOfImagingServiceRequest
+    assert (new_date_string, new_time_string) != (original_date_string, original_time_string)
+
+
 @pytest.mark.parametrize(
     "datetime_name",
     [