Search in sources :

Example 6 with ArgumentEntity

use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.

the class ProfilePipeService method createNewProfile.

private ProfileEntity createNewProfile(ProfilePipeBody profilePipeYml, Boolean byDefault) {
    final ProfileEntity newProfileEntity = new ProfileEntity(profilePipeYml.getName(), profilePipeYml.getVersion(), profilePipeYml.getMinimumKarnakVersion(), null, byDefault);
    if (profilePipeYml.getMasks() != null) {
        profilePipeYml.getMasks().forEach(m -> {
            MaskEntity maskEntity = new MaskEntity(m.getStationName(), m.getColor(), newProfileEntity);
            m.getRectangles().forEach(maskEntity::addRectangle);
            newProfileEntity.addMask(maskEntity);
        });
    }
    AtomicInteger profilePosition = new AtomicInteger(0);
    profilePipeYml.getProfileElements().forEach(profileBody -> {
        ProfileElementEntity profileElementEntity = new ProfileElementEntity(profileBody.getName(), profileBody.getCodename(), profileBody.getCondition(), profileBody.getAction(), profileBody.getOption(), profilePosition.get(), newProfileEntity);
        if (profileBody.getArguments() != null) {
            profileBody.getArguments().forEach((key, value) -> {
                final ArgumentEntity argumentEntity = new ArgumentEntity(key, value, profileElementEntity);
                profileElementEntity.addArgument(argumentEntity);
            });
        }
        if (profileBody.getTags() != null) {
            profileBody.getTags().forEach(tag -> {
                final IncludedTagEntity includedTagEntityValue = new IncludedTagEntity(tag, profileElementEntity);
                profileElementEntity.addIncludedTag(includedTagEntityValue);
            });
        }
        if (profileBody.getExcludedTags() != null) {
            profileBody.getExcludedTags().forEach(excludedTag -> {
                final ExcludedTagEntity excludedTagEntityValue = new ExcludedTagEntity(excludedTag, profileElementEntity);
                profileElementEntity.addExceptedtags(excludedTagEntityValue);
            });
        }
        newProfileEntity.addProfilePipe(profileElementEntity);
        profilePosition.getAndIncrement();
    });
    return newProfileEntity;
}
Also used : ExcludedTagEntity(org.karnak.backend.data.entity.ExcludedTagEntity) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaskEntity(org.karnak.backend.data.entity.MaskEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity)

Example 7 with ArgumentEntity

use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.

the class ProfileTest method shiftRangeProfile.

@Test
void shiftRangeProfile() {
    // SHIFT range with hmackey: HmacKeyToTEST -> days: 57, seconds: 9
    final String projectSecret = "xN[LtKL!H5RUuQ}6";
    byte[] HMAC_KEY = { 85, 55, -40, -90, -102, 57, -5, -89, -77, -86, 22, -64, 89, -36, 2, 50 };
    final String PatientID = "TEST-SHIFT-RANGE";
    final HashContext hashContext = new HashContext(HMAC_KEY, PatientID);
    final HMAC hmac = new HMAC(hashContext);
    final Attributes dataset1 = new Attributes();
    final Attributes dataset2 = new Attributes();
    dataset1.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset1.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset1.setString(Tag.PatientAge, VR.AS, "069Y");
    dataset1.setString(Tag.PatientBirthDate, VR.DA, "20080822");
    dataset1.setString(Tag.AcquisitionDateTime, VR.DT, "20080729131503");
    dataset1.setString(Tag.InstanceCreationTime, VR.TM, "131735.000000");
    dataset2.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset2.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset2.setString(Tag.PatientAge, VR.AS, "069Y");
    dataset2.setString(Tag.PatientBirthDate, VR.DA, "20080626");
    dataset2.setString(Tag.AcquisitionDateTime, VR.DT, "20080602131454.000000");
    dataset2.setString(Tag.InstanceCreationTime, VR.TM, "131726");
    ProfileEntity profileEntity = new ProfileEntity("TEST", "0.9.1", "0.9.1", "DPA");
    ProfileElementEntity profileElementEntity = new ProfileElementEntity("Shift Date with argumentEntities", "action.on.dates", null, null, "shift_range", 0, profileEntity);
    profileElementEntity.addIncludedTag(new IncludedTagEntity("(xxxx,xxxx)", profileElementEntity));
    profileElementEntity.addArgument(new ArgumentEntity("max_seconds", "60", profileElementEntity));
    profileElementEntity.addArgument(new ArgumentEntity("min_days", "50", profileElementEntity));
    profileElementEntity.addArgument(new ArgumentEntity("max_days", "100", profileElementEntity));
    profileEntity.addProfilePipe(profileElementEntity);
    Profile profile = new Profile(profileEntity);
    profile.applyAction(dataset1, dataset1, hmac, null, null, null);
    assertTrue(DicomObjectTools.dicomObjectEquals(dataset2, dataset1));
}
Also used : IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) HMAC(org.karnak.backend.model.profilepipe.HMAC) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Attributes(org.dcm4che3.data.Attributes) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Profile(org.karnak.backend.service.profilepipe.Profile) HashContext(org.karnak.backend.model.profilepipe.HashContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ArgumentEntity

use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.

the class ProfileTest method shiftDateProfile.

@Test
void shiftDateProfile() {
    // SHIFT days: 365, seconds:60
    final Attributes dataset1 = new Attributes();
    final Attributes dataset2 = new Attributes();
    dataset1.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset1.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset1.setString(Tag.PatientAge, VR.AS, "069Y");
    dataset1.setString(Tag.PatientBirthDate, VR.DA, "20080822");
    dataset1.setString(Tag.AcquisitionDateTime, VR.DT, "20080729131503");
    dataset1.setString(Tag.InstanceCreationTime, VR.TM, "131735.000000");
    dataset2.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset2.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset2.setString(Tag.PatientAge, VR.AS, "070Y");
    dataset2.setString(Tag.PatientBirthDate, VR.DA, "20070823");
    dataset2.setString(Tag.AcquisitionDateTime, VR.DT, "20070730131403.000000");
    dataset2.setString(Tag.InstanceCreationTime, VR.TM, "131635");
    ProfileEntity profileEntity = new ProfileEntity("TEST", "0.9.1", "0.9.1", "DPA");
    ProfileElementEntity profileElementEntity = new ProfileElementEntity("Shift Date with argumentEntities", "action.on.dates", null, null, "shift", 0, profileEntity);
    profileElementEntity.addIncludedTag(new IncludedTagEntity("(xxxx,xxxx)", profileElementEntity));
    profileElementEntity.addArgument(new ArgumentEntity("seconds", "60", profileElementEntity));
    profileElementEntity.addArgument(new ArgumentEntity("days", "365", profileElementEntity));
    profileEntity.addProfilePipe(profileElementEntity);
    Profile profile = new Profile(profileEntity);
    profile.applyAction(dataset1, dataset1, defaultHMAC, null, null, null);
    assertTrue(DicomObjectTools.dicomObjectEquals(dataset2, dataset1));
}
Also used : IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Attributes(org.dcm4che3.data.Attributes) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Profile(org.karnak.backend.service.profilepipe.Profile) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ArgumentEntity

use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.

the class ProfileTest method expressionProfile.

@Test
void expressionProfile() {
    final Attributes dataset1 = new Attributes();
    final Attributes dataset2 = new Attributes();
    dataset1.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset1.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset1.setString(Tag.PatientAge, VR.AS, "075Y");
    dataset2.setString(Tag.PatientName, VR.PN, "TEST-Expr-AddAction");
    dataset2.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    ProfileEntity profileEntity = new ProfileEntity("TEST", "0.9.1", "0.9.1", "DPA");
    ProfileElementEntity profileElementEntity = new ProfileElementEntity("Expr", "expression.on.tags", null, null, null, 0, profileEntity);
    profileElementEntity.addArgument(new ArgumentEntity("expr", "stringValue == '075Y'? Remove() : Keep()", profileElementEntity));
    profileElementEntity.addIncludedTag(new IncludedTagEntity("(xxxx,xxxx)", profileElementEntity));
    profileEntity.addProfilePipe(profileElementEntity);
    Profile profile = new Profile(profileEntity);
    profile.applyAction(dataset1, dataset1, defaultHMAC, null, null, null);
    assertTrue(DicomObjectTools.dicomObjectEquals(dataset2, dataset1));
}
Also used : ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Attributes(org.dcm4che3.data.Attributes) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Profile(org.karnak.backend.service.profilepipe.Profile) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ArgumentEntity

use of org.karnak.backend.data.entity.ArgumentEntity in project karnak by OsiriX-Foundation.

the class ProfileTest method propagationInSequence3.

@Test
void propagationInSequence3() {
    final Attributes dataset1 = new Attributes();
    final Attributes dataset2 = new Attributes();
    dataset1.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset1.setString(Tag.PatientID, VR.LO, "10987654321");
    dataset1.setString(Tag.PatientName, VR.PN, "toto");
    dataset1.setString(Tag.PatientBirthDate, VR.DA, "20200101");
    dataset1.setString(Tag.PatientSex, VR.CS, "M");
    dataset1.setString(Tag.IssuerOfPatientID, VR.LO, "12345678910");
    dataset1.setString(Tag.PatientAge, VR.AS, "075Y");
    Sequence dicomElemSeq1 = dataset1.newSequence(Tag.CTExposureSequence, 1);
    final Attributes datasetSeq1 = new Attributes();
    datasetSeq1.setDouble(Tag.EstimatedDoseSaving, VR.FD, 0d);
    datasetSeq1.setDouble(Tag.ExposureTimeInms, VR.FD, 2.099d);
    datasetSeq1.setDouble(Tag.XRayTubeCurrentInmA, VR.FD, 381d);
    datasetSeq1.setDouble(Tag.ExposureInmAs, VR.FD, 800d);
    datasetSeq1.setDouble(Tag.CTDIvol, VR.FD, 47d);
    dicomElemSeq1.add(datasetSeq1);
    dataset2.setString(Tag.StudyInstanceUID, VR.UI, "12345");
    dataset2.setString(Tag.PatientID, VR.LO, "10987654321");
    dataset2.setString(Tag.PatientName, VR.PN, "toto");
    dataset2.setString(Tag.PatientBirthDate, VR.DA, "20190101");
    dataset2.setString(Tag.PatientSex, VR.CS, "M");
    dataset2.setString(Tag.IssuerOfPatientID, VR.LO, "12345678910");
    dataset2.setString(Tag.PatientAge, VR.AS, "076Y");
    Sequence dicomElemSeq2 = dataset2.newSequence(Tag.CTExposureSequence, 1);
    final Attributes datasetSeq2 = new Attributes();
    datasetSeq2.setDouble(Tag.EstimatedDoseSaving, VR.FD, 0d);
    datasetSeq2.remove(Tag.EstimatedDoseSaving);
    datasetSeq2.setDouble(Tag.ExposureTimeInms, VR.FD, 2.099d);
    datasetSeq2.setDouble(Tag.XRayTubeCurrentInmA, VR.FD, 381d);
    datasetSeq2.setDouble(Tag.ExposureInmAs, VR.FD, 800d);
    datasetSeq2.setDouble(Tag.CTDIvol, VR.FD, 47d);
    dicomElemSeq2.add(datasetSeq2);
    final ProfileEntity profileEntity = new ProfileEntity("TEST", "0.9.1", "0.9.1", "DPA");
    final ProfileElementEntity profileElementEntity1 = new ProfileElementEntity("Shift Date with argumentEntities", "action.on.dates", null, null, "shift", 0, profileEntity);
    profileElementEntity1.addIncludedTag(new IncludedTagEntity("(xxxx,xxxx)", profileElementEntity1));
    profileElementEntity1.addArgument(new ArgumentEntity("seconds", "60", profileElementEntity1));
    profileElementEntity1.addArgument(new ArgumentEntity("days", "365", profileElementEntity1));
    final ProfileElementEntity profileElementEntity2 = new ProfileElementEntity("Remove tag", "action.on.specific.tags", null, "X", null, 1, profileEntity);
    profileElementEntity2.addIncludedTag(new IncludedTagEntity("(0018,9324)", profileElementEntity2));
    final ProfileElementEntity profileElementEntity3 = new ProfileElementEntity("Keep tag", "action.on.specific.tags", null, "K", null, 2, profileEntity);
    profileElementEntity3.addIncludedTag(new IncludedTagEntity("(0018,9321)", profileElementEntity3));
    final ProfileElementEntity profileElementEntity4 = new ProfileElementEntity("Replace null", "action.on.specific.tags", null, "Z", null, 3, profileEntity);
    profileElementEntity4.addIncludedTag(new IncludedTagEntity("(0018,9330)", profileElementEntity2));
    profileEntity.addProfilePipe(profileElementEntity1);
    profileEntity.addProfilePipe(profileElementEntity2);
    profileEntity.addProfilePipe(profileElementEntity3);
    profileEntity.addProfilePipe(profileElementEntity4);
    Profile profile = new Profile(profileEntity);
    profile.applyAction(dataset1, dataset1, defaultHMAC, null, null, null);
    assertTrue(DicomObjectTools.dicomObjectEquals(dataset2, dataset1));
}
Also used : IncludedTagEntity(org.karnak.backend.data.entity.IncludedTagEntity) ArgumentEntity(org.karnak.backend.data.entity.ArgumentEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) Attributes(org.dcm4che3.data.Attributes) Sequence(org.dcm4che3.data.Sequence) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Profile(org.karnak.backend.service.profilepipe.Profile) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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