ConceptCodeServiceImpl implements ConceptCodeService { @Override public ConceptCodeVSCSDto create() throws ValueSetNotFoundException, CodeSystemVersionNotFoundException, CodeSystemNotFoundException { ConceptCodeVSCSDto conceptCodeVSCSDto = new ConceptCodeVSCSDto(); conceptCodeVSCSDto.setValueSetsMap(getAllValueSetsInMap()); List<CodeSystem> codeSystems = codeSystemRepository.findAll(); if (codeSystems == null || codeSystems.size() == 0) { logger.debug("No codeSystems found in the system"); throw new CodeSystemNotFoundException(); } conceptCodeVSCSDto.setCsVersions(valueSetMgmtHelper .createCSVersionsDTOFormEntity(codeSystems)); return conceptCodeVSCSDto; } ConceptCodeServiceImpl(int conceptCodePageSize,
			ConceptCodeRepository conceptCodeRepository,
			ValueSetRepository valueSetRepository,
			CodeSystemRepository codeSystemRepository,
			CodeSystemVersionRepository codeSystemVersionRepository,
			ConceptCodeValueSetRepository conceptCodeValueSetRepository,
			ValueSetMgmtHelper valueSetMgmtHelper); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto delete(Long conceptCodeId); @Override ConceptCodeDto findById(Long id); @Override @Transactional(rollbackFor = ConceptCodeNotFoundException.class) ConceptCodeDto update(ConceptCodeDto updated); @Override List<ConceptCodeDto> findAll(); @Override Map<String, Object> findAll(int pageNumber); @Override Map<String, Object> findAllByCode(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override Map<String, Object> findAllByName(String searchTerm,
			String codeSystem, String codeSystemVersion, String valueSetName,
			int pageNumber); @Override ConceptCodeVSCSDto create(); @Override @Transactional ConceptCodeDto create(ConceptCodeDto created); @Override @Transactional(rollbackFor = DataIntegrityViolationException.class) ConceptCodeDto conceptCodeBatchUpload(ConceptCodeDto conceptCodeDto,
			MultipartFile file, String codeSystemId, Long codeSystemVersionId,
			List<Long> valueSetIds); @Override List<ValueSet> findValueSetsByCodeSystem(String codeSystem,
			String codeSystemVersion); final int CONCEPT_CODE_PAGE_SIZE; }
@Test(expected = CodeSystemNotFoundException.class) public void testCreateCodeSystemFromDto_throw_CodeSystemNotFoundException() throws ValueSetNotFoundException, CodeSystemNotFoundException, DuplicateConceptCodeException { ConceptCodeDto created = mock(ConceptCodeDto.class); when(created.getDescription()).thenReturn("description"); when(created.getCodeSystemVersionId()).thenReturn((long) 1); when(codeSystemVersionRepository.findOne(anyLong())).thenReturn(null); conceptCodeServiceImpl.create(created); }
@Test(expected = ValueSetNotFoundException.class) public void testCreateCodeSystemFromDto_throw_ValueSetNotFoundException() throws ValueSetNotFoundException, CodeSystemNotFoundException, DuplicateConceptCodeException { ConceptCodeDto created = mock(ConceptCodeDto.class); when(created.getDescription()).thenReturn("description"); when(created.getCodeSystemVersionId()).thenReturn((long) 1); CodeSystemVersion selectedCsv = mock(CodeSystemVersion.class); when(codeSystemVersionRepository.findOne(anyLong())).thenReturn( selectedCsv); List<Long> selVsIds = Arrays.asList((long) 1, (long) 2, (long) 3); when(created.getValueSetIds()).thenReturn(null); conceptCodeServiceImpl.create(created); }
@Test(expected = ValueSetNotFoundException.class) public void testCreateCodeSystemFromDto_throw_ValueSetNotFoundException_2() throws ValueSetNotFoundException, CodeSystemNotFoundException, DuplicateConceptCodeException { ConceptCodeDto created = mock(ConceptCodeDto.class); when(created.getDescription()).thenReturn("description"); when(created.getCodeSystemVersionId()).thenReturn((long) 1); CodeSystemVersion selectedCsv = mock(CodeSystemVersion.class); when(codeSystemVersionRepository.findOne(anyLong())).thenReturn( selectedCsv); List<Long> selVsIds = Arrays.asList((long) 1, (long) 2, (long) 3); when(created.getValueSetIds()).thenReturn(selVsIds); when(valueSetRepository.findOne(anyLong())).thenReturn(null); conceptCodeServiceImpl.create(created); }
@Test public void testCreateCodeSystemFromDto_throw_ValueSetNotFoundException_3() throws ValueSetNotFoundException, CodeSystemNotFoundException, DuplicateConceptCodeException { ConceptCodeDto created = mock(ConceptCodeDto.class); when(created.getDescription()).thenReturn("description"); when(created.getCodeSystemVersionId()).thenReturn((long) 1); CodeSystemVersion selectedCsv = mock(CodeSystemVersion.class); when(codeSystemVersionRepository.findOne(anyLong())).thenReturn( selectedCsv); List<Long> selVsIds = Arrays.asList((long) 1, (long) 2, (long) 3); when(created.getValueSetIds()).thenReturn(selVsIds); ValueSet selectedVs = mock(ValueSet.class); when(valueSetRepository.findOne(anyLong())).thenReturn(selectedVs); when(created.getCode()).thenReturn("code"); when(selectedCsv.getId()).thenReturn((long) 1); ConceptCode conceptCode = mock(ConceptCode.class); when( conceptCodeRepository.findByCodeAndCodeSystemVersionId( anyString(), anyLong())).thenReturn(conceptCode); ConceptCodeDto conceptCodeDto = mock(ConceptCodeDto.class); when( valueSetMgmtHelper .createConceptCodeDtoFromEntity(any(ConceptCode.class))) .thenReturn(conceptCodeDto); assertEquals(conceptCodeServiceImpl.create(created), conceptCodeDto); }
@Test public void testCreateCodeSystemFromDto_3() throws ValueSetNotFoundException, CodeSystemNotFoundException, DuplicateConceptCodeException { ConceptCodeDto created = mock(ConceptCodeDto.class); when(created.getDescription()).thenReturn("description"); when(created.getCodeSystemVersionId()).thenReturn((long) 1); CodeSystemVersion selectedCsv = mock(CodeSystemVersion.class); when(codeSystemVersionRepository.findOne(anyLong())).thenReturn( selectedCsv); List<Long> selVsIds = Arrays.asList((long) 1, (long) 2, (long) 3); when(created.getValueSetIds()).thenReturn(selVsIds); ValueSet selectedVs = mock(ValueSet.class); when(valueSetRepository.findOne(anyLong())).thenReturn(selectedVs); when(created.getCode()).thenReturn("code"); when(selectedCsv.getId()).thenReturn((long) 1); ConceptCode conceptCode = mock(ConceptCode.class); when( conceptCodeRepository.findByCodeAndCodeSystemVersionId( anyString(), anyLong())).thenReturn(null); ConceptCodeDto conceptCodeDto = mock(ConceptCodeDto.class); when( valueSetMgmtHelper .createConceptCodeDtoFromEntity(any(ConceptCode.class))) .thenReturn(conceptCodeDto); assertEquals(conceptCodeServiceImpl.create(created), conceptCodeDto); }