Search in sources :

Example 11 with ArgumentEntity

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));
}
Also used : ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) HMAC(org.karnak.backend.model.profilepipe.HMAC) ArrayList(java.util.ArrayList) HashContext(org.karnak.backend.model.profilepipe.HashContext) Test(org.junit.jupiter.api.Test)

Example 12 with ArgumentEntity

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()));
    }
}
Also used : VR(org.dcm4che3.data.VR) HMAC(org.karnak.backend.model.profilepipe.HMAC) Attributes(org.dcm4che3.data.Attributes) AbstractAction(org.karnak.backend.model.action.AbstractAction) ExcludedTagEntity(org.karnak.backend.data.entity.ExcludedTagEntity) Collectors(java.util.stream.Collectors) IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ExprAction(org.karnak.backend.model.expression.ExprAction) List(java.util.List) ExpressionError(org.karnak.backend.model.expression.ExpressionError) TagActionMap(org.karnak.backend.model.profilepipe.TagActionMap) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) ActionItem(org.karnak.backend.model.action.ActionItem) ExpressionResult(org.karnak.backend.model.expression.ExpressionResult) ExpressionError(org.karnak.backend.model.expression.ExpressionError) ExprAction(org.karnak.backend.model.expression.ExprAction) Attributes(org.dcm4che3.data.Attributes)

Example 13 with ArgumentEntity

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;
}
Also used : Div(com.vaadin.flow.component.html.Div) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) Text(com.vaadin.flow.component.Text)

Aggregations

ArgumentEntity (org.karnak.backend.data.entity.ArgumentEntity)13 Test (org.junit.jupiter.api.Test)10 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)7 IncludedTagEntity (org.karnak.backend.data.entity.IncludedTagEntity)6 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)6 Attributes (org.dcm4che3.data.Attributes)5 Profile (org.karnak.backend.service.profilepipe.Profile)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 HMAC (org.karnak.backend.model.profilepipe.HMAC)3 ArrayList (java.util.ArrayList)2 ExcludedTagEntity (org.karnak.backend.data.entity.ExcludedTagEntity)2 HashContext (org.karnak.backend.model.profilepipe.HashContext)2 Text (com.vaadin.flow.component.Text)1 Div (com.vaadin.flow.component.html.Div)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Sequence (org.dcm4che3.data.Sequence)1