Search in sources :

Example 6 with SnomedIdentifier

use of com.b2international.snowowl.snomed.cis.SnomedIdentifier in project snow-owl by b2ihealthcare.

the class ReservationImplTest method whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries.

@Test
public void whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries() throws Exception {
    final Index store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
    store.admin().create();
    final ISnomedIdentifierService identifierService = new DefaultSnomedIdentifierService(store, new ItemIdGenerationStrategy() {

        int counter = 200;

        @Override
        public Set<String> generateItemIds(String namespace, ComponentCategory category, int quantity, int attempt) {
            return IntStream.range(counter, counter + quantity).mapToObj(String::valueOf).collect(Collectors.toSet());
        }
    }, new SnomedIdentifierReservationServiceImpl(), new SnomedIdentifierConfiguration());
    final Set<ComponentCategory> components = Collections.singleton(ComponentCategory.CONCEPT);
    final Reservation range = Reservations.range(200, 300, "", components);
    final Set<String> componentIds = identifierService.generate(null, ComponentCategory.CONCEPT, 300 - 200 + 1);
    for (String id : componentIds) {
        final SnomedIdentifier identifier = SnomedIdentifiers.create(id);
        assertTrue(range.includes(identifier));
    }
    store.admin().delete();
}
Also used : ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) Set(java.util.Set) Index(com.b2international.index.Index) SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Mappings(com.b2international.index.mapping.Mappings) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) Test(org.junit.Test)

Example 7 with SnomedIdentifier

use of com.b2international.snowowl.snomed.cis.SnomedIdentifier in project snow-owl by b2ihealthcare.

the class SnomedIdSetReservationTest method testIdSetReservationReservedIds.

@Test
public void testIdSetReservationReservedIds() {
    final Reservation idSetReservation = Reservations.idSetReservation(Sets.newHashSet(Concepts.MODULE_ROOT, Concepts.MODULE_SCT_CORE));
    final SnomedIdentifier rootIdentifier = SnomedIdentifiers.create(Concepts.ROOT_CONCEPT);
    final SnomedIdentifier sctCoreIdentifier = SnomedIdentifiers.create(Concepts.MODULE_SCT_CORE);
    final Set<SnomedIdentifier> reservedIds = idSetReservation.intersection(Sets.newHashSet(rootIdentifier, sctCoreIdentifier));
    assertThat(reservedIds).containsOnly(sctCoreIdentifier);
}
Also used : Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) Test(org.junit.Test)

Example 8 with SnomedIdentifier

use of com.b2international.snowowl.snomed.cis.SnomedIdentifier in project snow-owl by b2ihealthcare.

the class SnomedIdentifierTest method whenCreatingRelationshipIdentifierInShortFormat_ThenItShouldBeCreated.

@Test
public void whenCreatingRelationshipIdentifierInShortFormat_ThenItShouldBeCreated() throws Exception {
    final SnomedIdentifier id = SnomedIdentifiers.create("9940000001029");
    assertEquals(9940000001L, id.getItemId());
    assertEquals("", id.getNamespace());
    assertEquals(0, id.getFormatIdentifier());
    assertEquals(2, id.getComponentIdentifier());
    assertEquals(9, id.getCheckDigit());
    assertEquals(ComponentCategory.RELATIONSHIP, id.getComponentCategory());
}
Also used : SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) Test(org.junit.Test)

Example 9 with SnomedIdentifier

use of com.b2international.snowowl.snomed.cis.SnomedIdentifier in project snow-owl by b2ihealthcare.

the class SnomedIdentifierTest method whenCreatingLongestConceptIdentifierInShortFormat_ThenItShouldBeCreated.

@Test
public void whenCreatingLongestConceptIdentifierInShortFormat_ThenItShouldBeCreated() throws Exception {
    final SnomedIdentifier id = SnomedIdentifiers.create(Concepts.DEFINITION_STATUS_ROOT);
    assertEquals(900000000000444L, id.getItemId());
    assertEquals("", id.getNamespace());
    assertEquals(0, id.getFormatIdentifier());
    assertEquals(0, id.getComponentIdentifier());
    assertEquals(6, id.getCheckDigit());
    assertEquals(ComponentCategory.CONCEPT, id.getComponentCategory());
}
Also used : SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) Test(org.junit.Test)

Example 10 with SnomedIdentifier

use of com.b2international.snowowl.snomed.cis.SnomedIdentifier in project snow-owl by b2ihealthcare.

the class SnomedIdentifierTest method whenCreatingDescriptionIdentifierInLongFormat_ThenItShouldBeCreated.

@Test
public void whenCreatingDescriptionIdentifierInLongFormat_ThenItShouldBeCreated() throws Exception {
    final SnomedIdentifier id = SnomedIdentifiers.create("1290000001117");
    assertEquals(129L, id.getItemId());
    assertEquals("0000001", id.getNamespace());
    assertEquals(1, id.getFormatIdentifier());
    assertEquals(1, id.getComponentIdentifier());
    assertEquals(7, id.getCheckDigit());
    assertEquals(ComponentCategory.DESCRIPTION, id.getComponentCategory());
}
Also used : SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) Test(org.junit.Test)

Aggregations

SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)11 Test (org.junit.Test)10 Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)3 Index (com.b2international.index.Index)1 Mappings (com.b2international.index.mapping.Mappings)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)1 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)1 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)1 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)1 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)1 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1