Search in sources :

Example 1 with MaskEntity

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

the class MaskRepoTest method shouldDeleteRecord.

/**
 * Test delete record.
 */
@Test
void shouldDeleteRecord() {
    // Create an entity to save
    MaskEntity entity = new MaskEntity();
    String name = "Name";
    entity.setStationName(name);
    entity.addRectangle(new Rectangle());
    // Save the entity
    LOGGER.info("Saving entity with name [{}]", entity.getStationName());
    entity = repository.save(entity);
    // Retrieve the entity
    Optional<MaskEntity> foundByIdOpt = repository.findById(entity.getId());
    // Test Find by Id
    assertTrue(foundByIdOpt.isPresent());
    // Delete the entity
    entity = foundByIdOpt.get();
    Long id = entity.getId();
    LOGGER.info("Deleting entity with id [{}]", id);
    repository.delete(entity);
    // Test Delete
    foundByIdOpt = repository.findById(id);
    LOGGER.info("Is deleted entity with id [{}] present: [{}]", id, foundByIdOpt.isPresent());
    assertFalse(foundByIdOpt.isPresent());
}
Also used : MaskEntity(org.karnak.backend.data.entity.MaskEntity) Rectangle(java.awt.Rectangle) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 2 with MaskEntity

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

the class MaskRepoTest method shouldSaveAndFindARecord.

/**
 * Test save and find record.
 */
@Test
void shouldSaveAndFindARecord() {
    // Create an entity to save
    MaskEntity entity = new MaskEntity();
    entity.setStationName("Name");
    // Save the entity
    LOGGER.info("Saving entity with name [{}]", entity.getStationName());
    entity = repository.save(entity);
    // Test Save
    assertEquals("Name", entity.getStationName());
    assertNotNull(entity.getId());
    LOGGER.info("Entity with name [{}] and id [{}] saved", entity.getStationName(), entity.getId());
    // Find By Id
    Optional<MaskEntity> foundByIdOpt = repository.findById(entity.getId());
    // Test Find by Id
    assertTrue(foundByIdOpt.isPresent());
    LOGGER.info("Entity found with name [{}] and id [{}]", foundByIdOpt.get().getStationName(), foundByIdOpt.get().getId());
    assertEquals(entity.getId(), foundByIdOpt.get().getId());
}
Also used : MaskEntity(org.karnak.backend.data.entity.MaskEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 3 with MaskEntity

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

the class ProfileTest method should_apply.

@Test
void should_apply() {
    // Init data
    Attributes attributes = new Attributes();
    DestinationEntity destinationEntity = new DestinationEntity();
    destinationEntity.setDestinationType(DestinationType.dicom);
    ProjectEntity projectEntity = new ProjectEntity();
    ProfileEntity profileEntityProject = new ProfileEntity();
    projectEntity.setProfileEntity(profileEntityProject);
    byte[] tabByte = new byte[16];
    tabByte[0] = 1;
    projectEntity.addActiveSecretEntity(new SecretEntity(tabByte));
    destinationEntity.setProjectEntity(projectEntity);
    destinationEntity.setPseudonymType(PseudonymType.EXTID_IN_TAG);
    destinationEntity.setTag("0008,0080");
    destinationEntity.setSavePseudonym(false);
    ProfileEntity profileEntity = new ProfileEntity();
    Set<ProfileElementEntity> profileElementEntities = new HashSet<>();
    ProfileElementEntity profileElementEntityBasic = new ProfileElementEntity();
    profileElementEntityBasic.setCodename("basic.dicom.profile");
    profileElementEntityBasic.setName("nameBasic");
    ProfileElementEntity profileElementEntityCleanPixelData = new ProfileElementEntity();
    profileElementEntityCleanPixelData.setCodename("clean.pixel.data");
    profileElementEntityCleanPixelData.setName("nameCleanPixel");
    profileElementEntityBasic.setPosition(1);
    profileElementEntityCleanPixelData.setPosition(2);
    profileElementEntityBasic.setAction("ReplaceNull");
    profileElementEntityCleanPixelData.setAction("ReplaceNull");
    profileElementEntityCleanPixelData.setCondition("!tagValueContains(#Tag.StationName,'ICT256')");
    profileElementEntities.add(profileElementEntityBasic);
    profileElementEntities.add(profileElementEntityCleanPixelData);
    profileEntity.setProfileElementEntities(profileElementEntities);
    profileEntity.setDefaultIssuerOfPatientId("defaultIssuerOfPatientId");
    Set<MaskEntity> maskEntities = new HashSet<>();
    MaskEntity maskEntity = new MaskEntity();
    maskEntities.add(maskEntity);
    maskEntity.setColor("1234567897");
    maskEntity.setStationName("stationName");
    maskEntity.setRectangles(Arrays.asList(new Rectangle()));
    profileEntity.setMaskEntities(maskEntities);
    AttributeEditorContext context = new AttributeEditorContext("tsuid", null, null);
    attributes.setString(Tag.PatientID, VR.SH, "patientID");
    attributes.setString(Tag.SeriesInstanceUID, VR.SH, "seriesInstanceUID");
    attributes.setString(Tag.SOPInstanceUID, VR.SH, "sopInstanceUID");
    attributes.setString(Tag.IssuerOfPatientID, VR.SH, "issuerOfPatientID");
    attributes.setString(Tag.PixelData, VR.SH, "pixelData");
    attributes.setString(Tag.SOPClassUID, VR.SH, "1.2.840.10008.5.1.4.1.1.88.74");
    attributes.setString(Tag.BurnedInAnnotation, VR.SH, "YES");
    attributes.setString(Tag.StationName, VR.SH, "stationName");
    attributes.setString(524416, VR.SH, "pseudonym");
    // Call method
    Profile profile = new Profile(profileEntity);
    // profile.init(profileEntity);
    profile.apply(attributes, destinationEntity, profileEntity, context);
    // Test results
    assertEquals("NONE", context.getAbort().name());
    assertNull(context.getMaskArea());
}
Also used : MaskEntity(org.karnak.backend.data.entity.MaskEntity) Attributes(org.dcm4che3.data.Attributes) Rectangle(java.awt.Rectangle) SecretEntity(org.karnak.backend.data.entity.SecretEntity) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) DestinationEntity(org.karnak.backend.data.entity.DestinationEntity) AttributeEditorContext(org.weasis.dicom.param.AttributeEditorContext) ProjectEntity(org.karnak.backend.data.entity.ProjectEntity) ProfileElementEntity(org.karnak.backend.data.entity.ProfileElementEntity) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with MaskEntity

use of org.karnak.backend.data.entity.MaskEntity 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 5 with MaskEntity

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

the class MaskRepoTest method shouldFindAllRecords.

/**
 * Test find all.
 */
@Test
void shouldFindAllRecords() {
    // Create an entity to save
    // Profile
    ProfileEntity profileEntity = new ProfileEntity();
    profileEntity.setName("name");
    profileEntity = profileRepo.saveAndFlush(profileEntity);
    // Mask
    MaskEntity entity = new MaskEntity();
    entity.setStationName("Name");
    entity.addRectangle(new Rectangle());
    entity.setProfileEntity(profileEntity);
    // Save the entity
    LOGGER.info("Saving entity with name [{}]", entity.getStationName());
    repository.saveAndFlush(entity);
    // Find all
    List<MaskEntity> all = repository.findAll();
    // Test find all
    assertNotNull(all);
    assertTrue(all.size() > 0);
    assertEquals(1, all.size());
    LOGGER.info("Number of entities found [{}]", all.size());
}
Also used : MaskEntity(org.karnak.backend.data.entity.MaskEntity) Rectangle(java.awt.Rectangle) ProfileEntity(org.karnak.backend.data.entity.ProfileEntity) Test(org.junit.jupiter.api.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

MaskEntity (org.karnak.backend.data.entity.MaskEntity)6 Test (org.junit.jupiter.api.Test)5 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 Rectangle (java.awt.Rectangle)3 ProfileEntity (org.karnak.backend.data.entity.ProfileEntity)3 ProfileElementEntity (org.karnak.backend.data.entity.ProfileElementEntity)2 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Attributes (org.dcm4che3.data.Attributes)1 ArgumentEntity (org.karnak.backend.data.entity.ArgumentEntity)1 DestinationEntity (org.karnak.backend.data.entity.DestinationEntity)1 ExcludedTagEntity (org.karnak.backend.data.entity.ExcludedTagEntity)1 IncludedTagEntity (org.karnak.backend.data.entity.IncludedTagEntity)1 ProjectEntity (org.karnak.backend.data.entity.ProjectEntity)1 SecretEntity (org.karnak.backend.data.entity.SecretEntity)1 AttributeEditorContext (org.weasis.dicom.param.AttributeEditorContext)1