Skip to content

Commit

Permalink
Merge pull request #195 from onc-healthit/develop
Browse files Browse the repository at this point in the history
merge develop into master for release
  • Loading branch information
drbgfc authored Aug 1, 2023
2 parents 0c6995a + 6f35d81 commit 0cbdff9
Show file tree
Hide file tree
Showing 29 changed files with 1,204 additions and 994 deletions.
40 changes: 32 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@
<version>2.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.2.17</version>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
Expand Down Expand Up @@ -115,7 +115,7 @@
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.3</version>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand Down Expand Up @@ -178,6 +178,30 @@
</dependency>
<!-- /testing -->

<!-- authorization/KeyCloak -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.1</version>
<scope>runtime</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.sitenv.service.ccda.smartscorecard.authorization;

import java.util.Objects;

import org.json.JSONObject;
import org.sitenv.service.ccda.smartscorecard.model.ScorecardProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

@Component
public class GenerateAccessToken {

private static final Logger logger = LoggerFactory.getLogger(GenerateAccessToken.class);

@Autowired
@Qualifier("scorecardProperties")
ScorecardProperties scorecardProperties;

public String getAccessToken() {
String accessToken = null;
try {
RestTemplate restTemplate = new RestTemplate();

String tokenEndpoint = scorecardProperties.getTokenEndpoint();
logger.info("tokenEndpoint: " + tokenEndpoint);
String clientId = scorecardProperties.getClientId();
logger.info("clientId: " + clientId);
String clientSecret = scorecardProperties.getClientSecret();

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("grant_type", "client_credentials");
map.add("client_secret", clientSecret);
map.add("client_id", clientId);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers);
ResponseEntity<KeyCloakResponse> response = restTemplate.postForEntity(tokenEndpoint, request,
KeyCloakResponse.class);

JSONObject jsonObj = new JSONObject(Objects.requireNonNull(response.getBody()));
accessToken = jsonObj.getString("access_token");
logger.info("getAccessToken accessToken status :::::::" + response.getStatusCode());
} catch (HttpClientErrorException clienterror) {
logger.error("HttpClientErrorException :::::::" + clienterror.getMessage());
clienterror.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return accessToken;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sitenv.service.ccda.smartscorecard.authorization;

public class KeyCloakResponse {

private String access_token;
private int expires_in;
private String user;

public String getAccess_token() {
return access_token;
}

public void setAccess_token(String access_token) {
this.access_token = access_token;
}

public int getExpires_in() {
return expires_in;
}

public void setExpires_in(int expires_in) {
this.expires_in = expires_in;
}

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,18 @@ public class ApplicationConfiguration {
* The following value is only looked at if OVERRIDE_SCORECARD_XML_CONFIG is true
* True allows for '2015 Edition Certification Feedback' results
*/
public static final boolean CERTIFICATION_RESULTS_CALL = true;
public static final boolean CERTIFICATION_RESULTS_CALL = true;

/**
* The following values are only looked at if OVERRIDE_SCORECARD_XML_CONFIG is true
* True allows defining the authorization detail programmatically vs in the XML config
* This should only be done for local testing purposes as it is dangerous to deploy a secret.
*/
public static final String TOKEN_ENDPOINT = "";
public static final String CLIENT_ID = "";
public static final String CLIENT_SECRET = "";

// TODO: Shouldn't this be updated to SVAP 2022 or later?
/**
* The cures update version of the Reference Validator is currently hosted on the C-CDA
* servers. True enables cures validation within the scorecard by switching
Expand Down Expand Up @@ -60,7 +70,8 @@ public class ApplicationConfiguration {
CODE_IN_VALUESET_SERVICE = "/referenceccdaservice/iscodeinvalueset",
CODE_IN_CODESYSTEM_SERVICE = "/referenceccdaservice/iscodeincodesystem",
REFERENCE_CCDA_SERVICE = "/referenceccdaservice/",
CCDA_SCORECARD_SERVICE = "/scorecard/ccdascorecardservice2",
CCDA_SCORECARD_SERVICE_APPLICATION_NAME = "ccdascorecardserviceinternal",
CCDA_SCORECARD_SERVICE = "/scorecard/" + CCDA_SCORECARD_SERVICE_APPLICATION_NAME,
SAVE_SCORECARD_SERVICE_BACKEND = "/scorecard/savescorecardservicebackend",
SAVE_SCORECARD_SERVICE_BACKEND_SUMMARY = "/scorecard/savescorecardservicebackendsummary";

Expand All @@ -72,7 +83,7 @@ public class ApplicationConfiguration {
CODE_VALUSET_VALIDATION_URL = server + CODE_IN_VALUESET_SERVICE,
CODE_CODESYSTEM_VALIDATION_URL = server + CODE_IN_CODESYSTEM_SERVICE,
REFERENCE_VALIDATOR_URL = server + REFERENCE_CCDA_SERVICE;
// -Scorecard endpoints
// -Scorecard endpoints (updating the same server variable to reuse programatically for next config)
static {
server = ENV.server(EndpointType.Scorecard);
}
Expand Down Expand Up @@ -153,4 +164,5 @@ public boolean isDevLocalOrCustom() {
public static final int CORE_POOL_SIZE = 200;
public static final int MAX_POOL_SIZE = 500;
public static final int QUEUE_CAPACITY = 10;

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherSe

@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {
MvcConfiguration.class,PersistanceConfiguration.class,PersistanceConfigurationPostGres.class};
return new Class<?>[] { MvcConfiguration.class, PersistanceConfiguration.class,
PersistanceConfigurationPostGres.class };
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public VocabularyLoaderFactory vocabularyLoaderFactory() {
@SuppressWarnings("unused")
public ScorecardProperties scorecardPropertiesLoader(final Environment environment){
ScorecardProperties scorecardProperties = new ScorecardProperties();

// Basic properties
scorecardProperties.setIgConformanceCall(
ApplicationConfiguration.OVERRIDE_SCORECARD_XML_CONFIG && ApplicationConfiguration.IG_CONFORMANCE_CALL ?
ApplicationConfiguration.IG_CONFORMANCE_CALL :
Expand All @@ -156,6 +158,19 @@ public ScorecardProperties scorecardPropertiesLoader(final Environment environme
scorecardProperties.setCertificatinResultsURL(
ApplicationConfiguration.OVERRIDE_SCORECARD_XML_CONFIG ? ApplicationConfiguration.REFERENCE_VALIDATOR_URL :
environment.getProperty("scorecard.certificationResultsUrl"));

// NOTE: scorecard.configFile is handled in the scorecardConfigurationLoader method in this file

// Authorization properties
scorecardProperties.setTokenEndpoint(
ApplicationConfiguration.OVERRIDE_SCORECARD_XML_CONFIG ? ApplicationConfiguration.TOKEN_ENDPOINT :
environment.getProperty("scorecard.tokenEndpoint"));
scorecardProperties.setClientId(
ApplicationConfiguration.OVERRIDE_SCORECARD_XML_CONFIG ? ApplicationConfiguration.CLIENT_ID :
environment.getProperty("scorecard.clientId"));
scorecardProperties.setClientSecret(
ApplicationConfiguration.OVERRIDE_SCORECARD_XML_CONFIG ? ApplicationConfiguration.CLIENT_SECRET :
environment.getProperty("scorecard.clientSecret"));
return scorecardProperties;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,7 @@ private static String convertFileToString(URI fileURI) {
return sb.toString();
}

// This is for local testing purposes
public static void main(String[] args) {
String[] filenames = {"highScoringSample", "lowScoringSample", "sampleWithErrors",
"sampleWithSchemaErrors", "sampleWithoutAnyContent", "sampleWithConfErrorAndNoCert"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.sitenv.service.ccda.smartscorecard.configuration.ApplicationConfiguration;
import org.sitenv.service.ccda.smartscorecard.model.ResponseTO;
import org.sitenv.service.ccda.smartscorecard.processor.ScorecardProcessor;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -18,44 +19,41 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
public class ScorecardController {

@Autowired
ScorecardProcessor scorecardProcessor;

@RequestMapping(value = "/ccdascorecardservice2", method = RequestMethod.POST)
public @ResponseBody ResponseTO ccdascorecardservice(@RequestParam("ccdaFile") MultipartFile ccdaFile){

@RequestMapping(value = "/"
+ ApplicationConfiguration.CCDA_SCORECARD_SERVICE_APPLICATION_NAME, method = RequestMethod.POST)
public @ResponseBody ResponseTO ccdascorecardservice(@RequestParam("ccdaFile") MultipartFile ccdaFile) {
return scorecardProcessor.processCCDAFile(ccdaFile);
}

@RequestMapping(value = "/exportscorecarddatatoexcel", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> genrateScorecardData(@RequestParam(value="fromDate", required=false) String fromDate,
@RequestParam(value="toDate", required=false) String toDate)throws Exception {

File file=null;
public ResponseEntity<InputStreamResource> genrateScorecardData(
@RequestParam(value = "fromDate", required = false) String fromDate,
@RequestParam(value = "toDate", required = false) String toDate) throws Exception {

File file = null;
HSSFWorkbook workBook = null;
String fileName = "scorecardData.xls";
try {

workBook = scorecardProcessor.generateScorecardData(fromDate, toDate);
file = new File(fileName);
workBook.write(file);

} catch (IOException ioe) {
ioe.printStackTrace();
throw ioe;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return ResponseEntity.ok()
.contentLength(file.length())
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.header("Content-Disposition","attachment; filename=" + fileName )
.body(new InputStreamResource(new FileInputStream(file)));

return ResponseEntity.ok().contentLength(file.length())
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.header("Content-Disposition", "attachment; filename=" + fileName)
.body(new InputStreamResource(new FileInputStream(file)));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sitenv.service.ccda.smartscorecard.loader;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

Expand All @@ -13,7 +14,7 @@

public class VocabularyLoadRunner implements InitializingBean, DisposableBean {
private VocabularyLoaderFactory vocabularyLoaderFactory;
private static Logger logger = Logger.getLogger(VocabularyLoadRunner.class);
private static Logger logger = LogManager.getLogger(VocabularyLoadRunner.class);
private String codeDirectory = null;
private boolean recursive = true;
private DataSource dataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrBuilder;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sitenv.service.ccda.smartscorecard.loader.BaseVocabularyLoader;
import org.sitenv.service.ccda.smartscorecard.loader.VocabularyLoader;
import org.springframework.stereotype.Component;
Expand All @@ -18,7 +19,7 @@

@Component(value = "LOINC")
public class LoincLoader extends BaseVocabularyLoader implements VocabularyLoader {
private static Logger logger = Logger.getLogger(LoincLoader.class);
private static Logger logger = LogManager.getLogger(LoincLoader.class);

@Override
public void load(List<File> filesToLoad, Connection connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrBuilder;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sitenv.service.ccda.smartscorecard.loader.BaseVocabularyLoader;
import org.sitenv.service.ccda.smartscorecard.loader.VocabularyLoader;
import org.springframework.stereotype.Component;

@Component(value = "TEMPLATEIDSR1.1")
public class TemplateIdLoaderR11 extends BaseVocabularyLoader implements VocabularyLoader {

private static Logger logger = Logger.getLogger(TemplateIdLoaderR21.class);
private static Logger logger = LogManager.getLogger(TemplateIdLoaderR21.class);

@Override
public void load(List<File> filesToLoad, Connection connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrBuilder;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sitenv.service.ccda.smartscorecard.loader.BaseVocabularyLoader;
import org.sitenv.service.ccda.smartscorecard.loader.VocabularyLoader;
import org.springframework.stereotype.Component;

@Component(value = "TEMPLATEIDSR2.1")
public class TemplateIdLoaderR21 extends BaseVocabularyLoader implements VocabularyLoader {

private static Logger logger = Logger.getLogger(TemplateIdLoaderR21.class);
private static Logger logger = LogManager.getLogger(TemplateIdLoaderR21.class);

@Override
public void load(List<File> filesToLoad, Connection connection) {
Expand Down
Loading

0 comments on commit 0cbdff9

Please sign in to comment.