Skip to content

Commit

Permalink
Merge pull request #76 from MeasureAuthoringTool/MAT-7013
Browse files Browse the repository at this point in the history
MAT-7013: Add cron job for midnight
  • Loading branch information
mcmcphillips authored Apr 25, 2024
2 parents 1d9b073 + fd86a27 commit c281b34
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
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}

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)
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);
}
}

0 comments on commit c281b34

Please sign in to comment.