-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from ADIS-SA/feat/shift_by_date
Feat/shift by date
- Loading branch information
Showing
5 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright (c) 2020-2021 Karnak Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.karnak.backend.util; | ||
|
||
import org.dcm4che3.data.Attributes; | ||
import org.karnak.backend.data.entity.ArgumentEntity; | ||
import org.karnak.backend.model.expression.ExprCondition; | ||
import org.karnak.backend.model.profilepipe.HMAC; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.List; | ||
|
||
public class ShiftByTagDate { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(ShiftByTagDate.class); | ||
|
||
private ShiftByTagDate() { | ||
} | ||
|
||
public static void verifyShiftArguments(List<ArgumentEntity> argumentEntities) { | ||
// All arguments are optional | ||
} | ||
|
||
public static String shift(Attributes dcm, int tag, List<ArgumentEntity> argumentEntities, HMAC hmac) { | ||
try { | ||
verifyShiftArguments(argumentEntities); | ||
} catch (IllegalArgumentException e) { | ||
throw e; | ||
} | ||
|
||
String dcmElValue = dcm.getString(tag); | ||
String shiftDaysTag = ""; | ||
String shiftSecondsTag = ""; | ||
|
||
for (ArgumentEntity argumentEntity : argumentEntities) { | ||
final String key = argumentEntity.getKey(); | ||
final String value = argumentEntity.getValue(); | ||
|
||
try { | ||
if (key.equals("days_tag")) { | ||
shiftDaysTag = value; | ||
} | ||
if (key.equals("seconds_tag")) { | ||
shiftSecondsTag = value; | ||
} | ||
} catch (Exception e) { | ||
LOGGER.error("args {} is not correct", value, e); | ||
} | ||
} | ||
|
||
final String shiftDaysValue = dcm.getString(ExprCondition.intFromHexString(shiftDaysTag)); | ||
final String shiftSecondsValue = dcm.getString(ExprCondition.intFromHexString(shiftSecondsTag)); | ||
|
||
int shiftDays = 0; | ||
int shiftSeconds = 0; | ||
try { | ||
if (shiftDaysValue != null) { | ||
shiftDays = Integer.parseInt(shiftDaysValue); | ||
} | ||
} catch (Exception e) { | ||
LOGGER.error("args {} is not correct", shiftDaysValue, e); | ||
} | ||
try { | ||
if (shiftSecondsValue != null) { | ||
shiftSeconds = Integer.parseInt(shiftSecondsValue); | ||
} | ||
} catch (Exception e) { | ||
LOGGER.error("args {} is not correct", shiftSecondsValue, e); | ||
} | ||
|
||
return ShiftDate.shiftValue(dcm, tag, dcmElValue, shiftDays, shiftSeconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/test/java/org/karnak/profilepipe/option/datemanager/ShiftByTagDateTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2020-2021 Karnak Team and other contributors. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0, or the Apache | ||
* License, Version 2.0 which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package org.karnak.profilepipe.option.datemanager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.dcm4che3.data.Attributes; | ||
import org.dcm4che3.data.Tag; | ||
import org.dcm4che3.data.VR; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.karnak.backend.data.entity.ArgumentEntity; | ||
import org.karnak.backend.model.profilepipe.HMAC; | ||
import org.karnak.backend.util.ShiftByTagDate; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ShiftByTagDateTest { | ||
|
||
private static final Attributes dataset = new Attributes(); | ||
private static final List<ArgumentEntity> argumentEntities = new ArrayList<>(); | ||
private static final ArgumentEntity seconds_tag = new ArgumentEntity(); | ||
private static final ArgumentEntity days_tag = new ArgumentEntity(); | ||
private static final HMAC hmac = new HMAC(HMAC.generateRandomKey()); | ||
|
||
@BeforeEach | ||
protected void setUpBeforeTest() throws Exception { | ||
argumentEntities.clear(); | ||
|
||
dataset.clear(); | ||
|
||
dataset.setString(Tag.StudyDate, VR.DA, "20180209"); | ||
dataset.setString(Tag.StudyTime, VR.TM, "120843"); | ||
dataset.setString(Tag.PatientAge, VR.AS, "043Y"); | ||
dataset.setString(Tag.AcquisitionDateTime, VR.DT, "20180209120854.354"); | ||
dataset.setString(Tag.AcquisitionTime, VR.TM, "010134"); | ||
dataset.setString(0x00150010, VR.LT, "ADIS"); | ||
dataset.setString(0x00151010, VR.LT, "10"); | ||
dataset.setString(0x00151011, VR.LT, "500"); | ||
dataset.setString(0x00151012, VR.LT, "AAA"); | ||
dataset.setString(0x00151013, VR.LT, "BBB"); | ||
} | ||
|
||
@Test | ||
void shiftNoop() { | ||
assertEquals("20180209", ShiftByTagDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac)); | ||
assertEquals("120843", ShiftByTagDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac)); | ||
assertEquals("043Y", ShiftByTagDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac)); | ||
assertEquals( | ||
"20180209120854.354000", | ||
ShiftByTagDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac)); | ||
assertEquals("010134", ShiftByTagDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac)); | ||
} | ||
|
||
@Test | ||
void shiftByTag() { | ||
days_tag.setKey("days_tag"); | ||
days_tag.setValue("(0015,1010)"); | ||
seconds_tag.setKey("seconds_tag"); | ||
seconds_tag.setValue("(0015,1011)"); | ||
argumentEntities.add(seconds_tag); | ||
argumentEntities.add(days_tag); | ||
|
||
assertEquals("20180130", ShiftByTagDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac)); | ||
assertEquals("120023", ShiftByTagDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac)); | ||
assertEquals("043Y", ShiftByTagDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac)); | ||
assertEquals( | ||
"20180130120034.354000", | ||
ShiftByTagDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac)); | ||
assertEquals("005314", ShiftByTagDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac)); | ||
} | ||
|
||
@Test | ||
void shiftByBadTag() { | ||
days_tag.setKey("days_tag"); | ||
days_tag.setValue("(0017,1010)"); | ||
seconds_tag.setKey("seconds_tag"); | ||
seconds_tag.setValue("(0017,1011)"); | ||
argumentEntities.add(seconds_tag); | ||
argumentEntities.add(days_tag); | ||
|
||
assertEquals("20180209", ShiftByTagDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac)); | ||
assertEquals("120843", ShiftByTagDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac)); | ||
assertEquals("043Y", ShiftByTagDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac)); | ||
assertEquals( | ||
"20180209120854.354000", | ||
ShiftByTagDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac)); | ||
assertEquals("010134", ShiftByTagDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac)); | ||
} | ||
|
||
@Test | ||
void shiftByBadTag2() { | ||
days_tag.setKey("days_tag"); | ||
days_tag.setValue("(0015,1012)"); | ||
seconds_tag.setKey("seconds_tag"); | ||
seconds_tag.setValue("(0015,1013)"); | ||
argumentEntities.add(seconds_tag); | ||
argumentEntities.add(days_tag); | ||
|
||
assertEquals("20180209", ShiftByTagDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac)); | ||
assertEquals("120843", ShiftByTagDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac)); | ||
assertEquals("043Y", ShiftByTagDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac)); | ||
assertEquals( | ||
"20180209120854.354000", | ||
ShiftByTagDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac)); | ||
assertEquals("010134", ShiftByTagDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac)); | ||
} | ||
} |