-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIAD-3013: Throw exception on application startup if immunization cod…
…es are not loaded (#694) * Add sql command to ImmunizationSnomedCTDao to check if immunization codes have been loaded Add custom CommandLineRunner which will be executed after runtime initialization Add Unit tests to ensure that the CommandLineRunner throws an exception when required. * Update CHANGELOG.md * Update README.md for snomed-database-loader * Correct test name in ApplicationCommandLineRunnerTest * Add comment to load-release-postgressql.sh explaining the coupling between this script and the translator service Refactored the REFRESH MATERIALIZED VIEWS so both are completed in the same PSQL command * Address issues in PR comments
- Loading branch information
1 parent
f408434
commit e3fc3e6
Showing
7 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ces/uk/nhs/adaptors/connector/dao/ImmunizationSnomedCTDao/verify_immunizations_loaded.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- the conceptIds being checked for below represent the immunization root codes and those immunization codes outside | ||
-- of the root code hierarchy, as described in the snomed-database-loader README.md file | ||
|
||
SELECT COUNT(i.conceptid) = 16 -- total number of codes | ||
FROM "snomedct".immunization_codes i | ||
WHERE i.conceptid IN ( | ||
'787859002', '127785005', '304250009', '90351000119108','713404003','2997511000001102', | ||
'308101000000104','1036721000000101', '1373691000000102', '945831000000105', '542931000000103', | ||
'735981009', '90640007', '571631000119106', '764141000000106', '170399005' | ||
); | ||
|
26 changes: 26 additions & 0 deletions
26
...k/nhs/adaptors/pss/translator/application/VerifyImmunizationsLoadedCommandLineRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.nhs.adaptors.pss.translator.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.stereotype.Component; | ||
import uk.nhs.adaptors.connector.dao.ImmunizationSnomedCTDao; | ||
|
||
@Component | ||
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) | ||
public class VerifyImmunizationsLoadedCommandLineRunner implements CommandLineRunner { | ||
|
||
private final ImmunizationSnomedCTDao immunizationSnomedCTDao; | ||
|
||
@Override | ||
public void run(String... args) { | ||
if (!immunizationSnomedCTDao.areImmunizationCodesLoaded()) { | ||
throw new RuntimeException(""" | ||
FATAL: Expected Immunization codes not found in snomedct.immunization_codes view. | ||
SNOMED CT Database not set up correctly. | ||
Please update / reload the SNOMED DB. | ||
""" | ||
); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...s/adaptors/pss/translator/application/VerifyImmunizationsLoadedCommandLineRunnerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.nhs.adaptors.pss.translator.application; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import uk.nhs.adaptors.connector.dao.ImmunizationSnomedCTDao; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class VerifyImmunizationsLoadedCommandLineRunnerTest { | ||
|
||
@Mock | ||
private ImmunizationSnomedCTDao immunizationSnomedCTDao; | ||
|
||
@InjectMocks | ||
private VerifyImmunizationsLoadedCommandLineRunner verifyImmunizationsLoadedCommandLineRunner; | ||
|
||
@Test | ||
public void When_RunApplicationAndImmunizationsAreLoaded_Expect_ExceptionIsNotThrown() { | ||
when(immunizationSnomedCTDao.areImmunizationCodesLoaded()).thenReturn(true); | ||
|
||
assertDoesNotThrow(() -> verifyImmunizationsLoadedCommandLineRunner.run()); | ||
} | ||
|
||
@Test | ||
public void When_RunApplicationAndImmunizationsNotLoaded_Expect_RuntimeExceptionThrown() { | ||
when(immunizationSnomedCTDao.areImmunizationCodesLoaded()).thenReturn(false); | ||
|
||
assertThrows(RuntimeException.class, () -> verifyImmunizationsLoadedCommandLineRunner.run()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters