-
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.
Merge pull request #119 from MeasureAuthoringTool/feature/MAT-5404-re…
…move-HAPI-for-libraries replace HAPI FHIR with CQL Library Service for fetching CQL Libraries
- Loading branch information
Showing
11 changed files
with
203 additions
and
439 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/gov/cms/madie/madiefhirservice/exceptions/CqlLibraryNotFoundException.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,18 @@ | ||
package gov.cms.madie.madiefhirservice.exceptions; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.NOT_FOUND) | ||
@Slf4j | ||
public class CqlLibraryNotFoundException extends RuntimeException { | ||
|
||
private static final String NOT_FOUND_BY_FIND_DATA = | ||
"Cannot find a CQL Library with name: %s, version: %s"; | ||
|
||
public CqlLibraryNotFoundException(String name, String version) { | ||
super(String.format(NOT_FOUND_BY_FIND_DATA, name, version)); | ||
log.error(getMessage()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/gov/cms/madie/madiefhirservice/exceptions/MissingCqlException.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,17 @@ | ||
package gov.cms.madie.madiefhirservice.exceptions; | ||
|
||
import gov.cms.madie.models.library.CqlLibrary; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.NOT_FOUND) | ||
@Slf4j | ||
public class MissingCqlException extends RuntimeException { | ||
private static final String NONE_FOUND = "Cannot find CQL for library name: %s, version: %s"; | ||
|
||
public MissingCqlException(CqlLibrary library) { | ||
super(String.format(NONE_FOUND, library.getCqlLibraryName(), library.getVersion())); | ||
log.warn(getMessage()); | ||
} | ||
} |
60 changes: 0 additions & 60 deletions
60
src/main/java/gov/cms/madie/madiefhirservice/resources/HapiFhirLibraryController.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
src/main/java/gov/cms/madie/madiefhirservice/services/CqlLibraryService.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,69 @@ | ||
package gov.cms.madie.madiefhirservice.services; | ||
|
||
import gov.cms.madie.madiefhirservice.exceptions.CqlLibraryNotFoundException; | ||
import gov.cms.madie.models.library.CqlLibrary; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
|
||
import java.net.URI; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class CqlLibraryService { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Value("${madie.library.service.baseUrl}") | ||
private String madieLibraryService; | ||
|
||
@Value("${madie.library.service.versioned.uri}") | ||
private String librariesVersionedUri; | ||
|
||
public CqlLibrary getLibrary(String name, String version, String accessToken) { | ||
URI uri = buildMadieLibraryServiceUri(name, version); | ||
log.debug("Getting Madie library: {} ", uri); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("Authorization", accessToken); | ||
|
||
ResponseEntity<CqlLibrary> responseEntity = | ||
restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(headers), CqlLibrary.class); | ||
|
||
if (responseEntity.getStatusCode().is2xxSuccessful()) { | ||
if (responseEntity.hasBody()) { | ||
log.debug("Retrieved a valid cqlPayload"); | ||
return responseEntity.getBody(); | ||
} else { | ||
log.error("Cannot find Cql payload in the response"); | ||
return null; | ||
} | ||
} else if (responseEntity.getStatusCode().equals(HttpStatus.NOT_FOUND)) { | ||
throw new CqlLibraryNotFoundException(name, version); | ||
} else if (responseEntity.getStatusCode().equals(HttpStatus.CONFLICT)) { | ||
log.error( | ||
"Multiple libraries found with name: {}, version: {}, but only one was expected", | ||
name, | ||
version); | ||
} | ||
return null; | ||
} | ||
|
||
private URI buildMadieLibraryServiceUri(String name, String version) { | ||
return UriComponentsBuilder.fromHttpUrl(madieLibraryService + librariesVersionedUri) | ||
.queryParam("name", name) | ||
.queryParam("version", version) | ||
.build() | ||
.encode() | ||
.toUri(); | ||
} | ||
} |
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
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
Oops, something went wrong.