-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from MeasureAuthoringTool/MAT-7013
MAT-7013: Add cron job for midnight
- Loading branch information
Showing
5 changed files
with
66 additions
and
2 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
32 changes: 32 additions & 0 deletions
32
src/main/java/gov/cms/madie/terminology/task/UpdateCodeSystemTask.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,32 @@ | ||
package gov.cms.madie.terminology.task; | ||
|
||
import gov.cms.madie.terminology.models.CodeSystem; | ||
import gov.cms.madie.terminology.models.UmlsUser; | ||
import gov.cms.madie.terminology.service.FhirTerminologyService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class UpdateCodeSystemTask { | ||
private final FhirTerminologyService fhirTerminologyService; | ||
|
||
@Value("${code-system-refresh-task.terminology-key}") | ||
private String apiKey; | ||
|
||
@Scheduled(cron = "${code-system-refresh-task.code-system-cron-date-time}") // every midnight | ||
public void updateCodeSystems() { | ||
log.info("Starting scheduled task to update code systems."); | ||
|
||
UmlsUser user = new UmlsUser(); | ||
user.setApiKey(apiKey); | ||
List<CodeSystem> response = fhirTerminologyService.retrieveAllCodeSystems(user); | ||
log.info("Successfully retrieved and updated code systems for user: {}", response); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/test/java/gov/cms/madie/terminology/task/UpdateCodeSystemTaskTest.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,27 @@ | ||
package gov.cms.madie.terminology.task; | ||
|
||
import gov.cms.madie.terminology.models.CodeSystem; | ||
import gov.cms.madie.terminology.models.UmlsUser; | ||
import gov.cms.madie.terminology.service.FhirTerminologyService; | ||
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 java.util.*; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class UpdateCodeSystemTaskTest { | ||
@Mock private FhirTerminologyService fhirTerminologyService; | ||
@InjectMocks UpdateCodeSystemTask updateCodeSystemTask; | ||
@Test | ||
void updateCodeSystemTaskTest() { | ||
UmlsUser umlsUser = new UmlsUser(); | ||
List<CodeSystem> codeSystems = Arrays.asList(new CodeSystem(), new CodeSystem()); | ||
updateCodeSystemTask.updateCodeSystems(); | ||
verify(fhirTerminologyService).retrieveAllCodeSystems(umlsUser); | ||
} | ||
} |