use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.
the class ShiftRangeDateTest method shift.
@Test
void shift() {
byte[] HMAC_KEY = { -116, -11, -20, 53, -37, -94, 64, 103, 63, -89, -108, -70, 84, 43, -74, -8 };
String Patient_ID = "Patient 1";
HashContext hashContext = new HashContext(HMAC_KEY, Patient_ID);
HMAC hmac = new HMAC(hashContext);
String Patient_ID_2 = "Patient 2";
byte[] HMAC_KEY_2 = { -57, -80, 125, -55, 54, 85, 52, 102, 20, -116, -78, -6, 108, 47, -37, -43 };
HashContext hashContext_2 = new HashContext(HMAC_KEY_2, Patient_ID_2);
HMAC hmac_2 = new HMAC(hashContext_2);
assertEquals("20171001", ShiftRangeDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac));
assertEquals("115745", ShiftRangeDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac));
assertEquals("043Y", ShiftRangeDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac));
assertEquals("20171001115756.354000", ShiftRangeDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac));
assertEquals("235036", ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
assertEquals("20171114", ShiftRangeDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac_2));
assertEquals("120126", ShiftRangeDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac_2));
assertEquals("043Y", ShiftRangeDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac_2));
assertEquals("20171114120137.354000", ShiftRangeDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac_2));
assertEquals("235417", ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac_2));
min_seconds.setKey("min_seconds");
min_seconds.setValue("500");
min_days.setKey("min_days");
min_days.setValue("100");
argumentEntities.add(min_seconds);
argumentEntities.add(min_days);
assertEquals("20170828", ShiftRangeDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac));
assertEquals("115454", ShiftRangeDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac));
assertEquals("043Y", ShiftRangeDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac));
assertEquals("20170828115505.354000", ShiftRangeDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac));
assertEquals("234745", ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
assertEquals("20170919", ShiftRangeDate.shift(dataset, Tag.StudyDate, argumentEntities, hmac_2));
assertEquals("115645", ShiftRangeDate.shift(dataset, Tag.StudyTime, argumentEntities, hmac_2));
assertEquals("043Y", ShiftRangeDate.shift(dataset, Tag.PatientAge, argumentEntities, hmac_2));
assertEquals("20170919115656.354000", ShiftRangeDate.shift(dataset, Tag.AcquisitionDateTime, argumentEntities, hmac_2));
assertEquals("234936", ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac_2));
max_seconds.setKey("test_max_seconds");
max_days.setKey("max_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
max_seconds.setKey("test_max_seconds");
max_days.setKey("max_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
max_seconds.setKey("max_seconds");
max_days.setKey("test_max_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
max_seconds.setKey("test_max_seconds");
max_days.setKey("test_max_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, argumentEntities, hmac));
List<ArgumentEntity> arguments_2 = new ArrayList<>();
ArgumentEntity arg_1 = new ArgumentEntity();
arg_1.setKey("max_seconds");
arg_1.setValue("12");
arguments_2.add(arg_1);
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, arguments_2, hmac));
arg_1.setKey("max_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, arguments_2, hmac));
arg_1.setKey("min_seconds");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, arguments_2, hmac));
arg_1.setKey("min_days");
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, arguments_2, hmac));
Assertions.assertThrows(IllegalArgumentException.class, () -> ShiftRangeDate.shift(dataset, Tag.AcquisitionTime, new ArrayList<>(), hmac));
}
use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.
the class Expression method profileValidation.
public void profileValidation() throws Exception {
if (!argumentEntities.stream().anyMatch(argument -> argument.getKey().equals("expr"))) {
List<String> args = argumentEntities.stream().map(ArgumentEntity::getKey).collect(Collectors.toList());
throw new IllegalArgumentException("Cannot build the expression: Missing argument, the class need [expr] as parameters. Parameters given " + args);
}
final String expr = argumentEntities.get(0).getValue();
final ExpressionError expressionError = ExpressionResult.isValid(expr, new ExprAction(1, VR.AE, new Attributes(), new Attributes()), ActionItem.class);
if (!expressionError.isValid()) {
throw new IllegalArgumentException(String.format("Expression is not valid: \n\r%s", expressionError.getMsg()));
}
}
use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.
the class ProfileElementView method setProfileArguments.
private VerticalLayout setProfileArguments(List<ArgumentEntity> argumentEntities) {
VerticalLayout verticalLayout = new VerticalLayout();
verticalLayout.getStyle().set("margin-top", "0px");
for (ArgumentEntity argumentEntity : argumentEntities) {
Div tagDiv = new Div();
tagDiv.add(new Text(argumentEntity.getKey() + " : " + argumentEntity.getValue()));
tagDiv.getStyle().set("color", "grey").set("padding-left", "15px").set("margin-top", "2px");
verticalLayout.add(tagDiv);
}
return verticalLayout;
}
Aggregations