Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAT-7013: Add cron job for midnight #76

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootApplication
@EnableCaching
@EnableScheduling
public class TerminologyServiceApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ResponseEntity<List<QdmValueSet>> getValueSetsExpansions(
public ResponseEntity<List<CodeSystem>> retrieveAndUpdateCodeSystems(
Principal principal,
HttpServletRequest request,
@Value("${admin-api-key}") String apiKey,
@Value("${code-system-refresh-task.admin-api-key}") String apiKey,
@RequestHeader("Authorization") String accessToken) {
final String username = principal.getName();
UmlsUser umlsUser = vsacService.verifyUmlsAccess(username);
Expand Down
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);
}
}
5 changes: 4 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ okta:
issuer: ${OKTA_ISSUER:https://dev-18092578.okta.com/oauth2/default}
audience: ${OKTA_AUDIENCE:api://default}

admin-api-key: ${ADMIN_API_KEY:0a51991c}
code-system-refresh-task:
admin-api-key: ${ADMIN_API_KEY:0a51991c}
terminology-key: ${VSAC_API_KEY:defaultvaluetopreventillegalappstate}
code-system-cron-date-time: ${CS_REFRESH_TIME:@midnight}
mcmcphillips marked this conversation as resolved.
Show resolved Hide resolved

client:
vsac_base_url: https://vsac.nlm.nih.gov/vsac
Expand Down
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)
mcmcphillips marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading