Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkiefer committed Jul 30, 2020
1 parent e12d3ba commit 45002ca
Show file tree
Hide file tree
Showing 34 changed files with 667 additions and 244 deletions.
338 changes: 338 additions & 0 deletions phema-elm-to-ohdsi.iml

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions src/main/java/edu/phema/elm_to_omop/ElmToOmopConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void run(String[] args) {

logger.info("Config: " + config.configString());

String domain = config.getOmopBaseUrl();
String domain = config.getOmopBaseURL();
String source = config.getSource();
OmopRepositoryService omopService = new OmopRepositoryService(domain, source);
OmopWriter omopWriter = new OmopWriter(logger);
Expand Down Expand Up @@ -112,18 +112,17 @@ public void run(String[] args) {
// Write the resulting cohort definitions to out to the filesystem
omopWriter.writeOmopJson(cohortDefinitions, config.getOutFileName());
} catch (PhenotypeException pe) {
System.out.println(pe.getMessage());
pe.printStackTrace();
logger.severe(pe.getLocalizedMessage());
} catch (IOException ioe) {
ioe.printStackTrace();
logger.severe(ioe.getLocalizedMessage());
} catch (InvalidFormatException ife) {
ife.printStackTrace();
logger.severe(ife.getLocalizedMessage());
} catch (JAXBException jaxb) {
jaxb.printStackTrace();
} catch (ParseException pe) {
pe.printStackTrace();
logger.severe(jaxb.getLocalizedMessage());
} catch (ParseException parse) {
logger.severe(parse.getLocalizedMessage());
} catch (Exception exc) {
exc.printStackTrace();
logger.severe(exc.getLocalizedMessage());
}
System.out.println("done");
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/edu/phema/elm_to_omop/api/CohortService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class CohortService {
private IValuesetService valuesetService;
private IOmopRepositoryService omopService;

private String errorMsg = "Error initializing concept sets";

/**
* Constructor using just a config object.
*
Expand All @@ -56,7 +58,7 @@ public CohortService(Config config) throws CohortServiceException {
try {
conceptSets = valuesetService.getConceptSets();
} catch (Exception e) {
throw new CohortServiceException("Error initializing concept sets", e);
throw new CohortServiceException(errorMsg, e);
}
}

Expand All @@ -77,7 +79,7 @@ public CohortService(Config config, IValuesetService valuesetService) throws Coh
try {
conceptSets = valuesetService.getConceptSets();
} catch (Exception e) {
throw new CohortServiceException("Error initializing concept sets", e);
throw new CohortServiceException(errorMsg, e);
}
}

Expand All @@ -98,7 +100,7 @@ public CohortService(IValuesetService valuesetService, IOmopRepositoryService om
try {
conceptSets = valuesetService.getConceptSets();
} catch (Exception e) {
throw new CohortServiceException("Error initializing concept sets", e);
throw new CohortServiceException(errorMsg, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
public class CqlToElmTranslator {

public CqlToElmTranslator() {
super();
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/edu/phema/elm_to_omop/api/ElmToOmopTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class ElmToOmopTranslator {
private Logger logger;
private List<PhemaConceptSet> conceptSets;

private String expString = "expression";

/**
* Specify configuration to use for the translation
*
Expand Down Expand Up @@ -111,13 +113,13 @@ public JsonObject cqlToOmopJsonObject(String cqlString, String statementName) th
JsonParser parser = new JsonParser();
JsonObject root = parser.parse(jsonish).getAsJsonObject();

String expressionJson = root.get("expression").toString()
String expressionJson = root.get(expString).toString()
.replace("\\\"", "\"").replaceAll("^\"|\"$", "");

JsonObject expression = parser.parse(expressionJson).getAsJsonObject();

root.remove("expression");
root.add("expression", expression);
root.remove(expString);
root.add(expString, expression);

return root;
}
Expand All @@ -140,7 +142,7 @@ public CohortDefinitionDTO buildCohortDefinition(String name, String description
cohortDefinition.name = name;
cohortDefinition.description = description;

// This manual serialization isn't required in later versions of the WebAPI, see:
// TODO: This manual serialization isn't required in later versions of the WebAPI, see:
// https://github.com/OHDSI/WebAPI/blob/v2.7.4/src/main/java/org/ohdsi/webapi/cohortdefinition/dto/CohortDTO.java#L10
cohortDefinition.expression = mapper.writeValueAsString(cohortExpression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum CriteriaGroupType {
this.typeString = typeString;
}

@Override
public String toString() {
return typeString;
}
Expand All @@ -36,6 +37,7 @@ public enum NumericRangeOperator {
this.opString = opString;
}

@Override
public String toString() {
return opString;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/phema/elm_to_omop/helper/CirceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* generate invalid objects using the empty default constructors.
*/
public class CirceUtil {
private CirceUtil() {
super();
}

/**
* Extends a primitive array of CriteriaGroups by adding a new CriteriaGroup.
* This is necessary because Circe uses primitive arrays instead of Java collections.
Expand Down
39 changes: 15 additions & 24 deletions src/main/java/edu/phema/elm_to_omop/helper/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public final class Config {
/**
* Logs messages to file.
*/
private final Logger LOGGER = Logger.getLogger(Config.class.getName());
private final Logger logger = Logger.getLogger(Config.class.getName());

private static final String PHENOTYPE_NAME_DELIMITER = "\\|";

/**
* Configuration file name.
Expand All @@ -33,9 +35,6 @@ public final class Config {
*/
private Properties configProps;

private final String PHENOTYPE_NAME_DELIMITER = "\\|";


private String omopBaseURL;

private String inputFileName;
Expand All @@ -50,6 +49,7 @@ public final class Config {

private List<String> phenotypeExpressions;


/**
* Empty constructor removes dependency
* on `config.properties` file, which is
Expand All @@ -69,7 +69,7 @@ public Config(String configFilePath) {
configProps.load(is);
setConfig();
} catch (Exception eta) {
eta.printStackTrace();
logger.severe(eta.getLocalizedMessage());
}
}

Expand All @@ -84,7 +84,7 @@ public Config(final String[] inArgs) {

// Override any arguments specified
for (int i = 0; i < inArgs.length; i++) {
LOGGER.info("Found argument:" + inArgs[i]);
logger.info(String.format("Found argument: %1$s", inArgs[i]));
setArg(inArgs[i]);
}
runPropertyCheck();
Expand All @@ -107,8 +107,7 @@ public static String getDefaultConfigPath() {
* @return property value
*/
public String getProperty(final String key) {
String value = this.configProps.getProperty(key);
return value;
return this.configProps.getProperty(key);
}

/**
Expand All @@ -126,10 +125,6 @@ public void setConfig() {
runPropertyCheck();
}

public String getOmopBaseUrl() {
return omopBaseURL;
}

public String getInputFileName() {
return inputFileName;
}
Expand Down Expand Up @@ -164,7 +159,7 @@ private void setArg(final String inArg) {
if (args.startsWith("-")) {
args = args.substring(1);
}
int pos = args.indexOf("=");
int pos = args.indexOf('=');
String prop = args.substring(0, pos);
String val = args.substring(pos + 1);

Expand Down Expand Up @@ -193,7 +188,7 @@ private void setArg(final String inArg) {
}

private List<String> parsePhenotypeExpressions(String phenotypes) {
List<String> expressions = new ArrayList<String>();
List<String> expressions = new ArrayList<>();
if (phenotypes != null) {
expressions = Arrays.asList(phenotypes.split(PHENOTYPE_NAME_DELIMITER));
}
Expand All @@ -206,22 +201,22 @@ private List<String> parsePhenotypeExpressions(String phenotypes) {
*/
private void runPropertyCheck() {
if (omopBaseURL == null) {
LOGGER.severe("ERROR - missing parameter OMOP_BASE_URL");
logger.severe("ERROR - missing parameter OMOP_BASE_URL");
}
if (inputFileName == null) {
LOGGER.severe("ERROR - missing parameter INPUT_FILE_NAME");
logger.severe("ERROR - missing parameter INPUT_FILE_NAME");
}
if (vsFileName == null) {
LOGGER.severe("ERROR - missing parameter VS_FILE_NAME");
logger.severe("ERROR - missing parameter VS_FILE_NAME");
}
if (outFileName == null) {
LOGGER.severe("ERROR - missing parameter OUT_FILE_NAME");
logger.severe("ERROR - missing parameter OUT_FILE_NAME");
}
if (source == null) {
LOGGER.severe("ERROR - missing parameter SOURCE");
logger.severe("ERROR - missing parameter SOURCE");
}
if (tab == null) {
LOGGER.severe("INFO - missing optional parameter VS_TAB");
logger.severe("INFO - missing optional parameter VS_TAB");
}
}

Expand All @@ -233,10 +228,6 @@ public String getConfigFileName() {
return configFileName;
}

public void setConfigFileName(String configFileName) {
this.configFileName = configFileName;
}

public String getConfigFullPath() {
return configFullPath;
}
Expand Down
59 changes: 31 additions & 28 deletions src/main/java/edu/phema/elm_to_omop/helper/Terms.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,40 @@
* or have the possibility of changing.
*/
public class Terms {
private Terms() {
super();
}

public static int COL_VS_OID = 0;
public static int COL_VS_NAME = 1;
public static int COL_CODE = 2;
public static int COL_DESC = 3;
public static int COL_CS = 4;
public static int COL_CS_VER = 5;
public static int COL_CS_OID = 6;
public static int COL_TTY = 7;
public static int COL_OMOP_CONCEPT_ID = 8;
public static final int COL_VS_OID = 0;
public static final int COL_VS_NAME = 1;
public static final int COL_CODE = 2;
public static final int COL_DESC = 3;
public static final int COL_CS = 4;
public static final int COL_CS_VER = 5;
public static final int COL_CS_OID = 6;
public static final int COL_TTY = 7;
public static final int COL_OMOP_CONCEPT_ID = 8;

public static String COL_VS_OID_NAME = "value_set_oid";
public static String COL_VS_NAME_NAME = "value_set_name";
public static String COL_CODE_NAME = "code";
public static String COL_DESC_NAME = "description";
public static String COL_CS_NAME = "code_system";
public static String COL_CS_VER_NAME = "code_system_version";
public static String COL_CS_OID_NAME = "code_system_oid";
public static String COL_TTY_NAME = "tty";
public static String COL_OMOP_CONCEPT_ID_NAME = "omop_concept_id";
public static final String COL_VS_OID_NAME = "value_set_oid";
public static final String COL_VS_NAME_NAME = "value_set_name";
public static final String COL_CODE_NAME = "code";
public static final String COL_DESC_NAME = "description";
public static final String COL_CS_NAME = "code_system";
public static final String COL_CS_VER_NAME = "code_system_version";
public static final String COL_CS_OID_NAME = "code_system_oid";
public static final String COL_TTY_NAME = "tty";
public static final String COL_OMOP_CONCEPT_ID_NAME = "omop_concept_id";

public static String CONCEPT_ID = "CONCEPT_ID";
public static String CONCEPT_NAME = "CONCEPT_NAME";
public static String STANDARD_CONCEPT = "STANDARD_CONCEPT";
public static String STANDARD_CONCEPT_CAPTION = "STANDARD_CONCEPT_CAPTION";
public static String INVALID_REASON = "INVALID_REASON";
public static String INVALID_REASON_CAPTION = "INVALID_REASON_CAPTION";
public static String CONCEPT_CODE = "CONCEPT_CODE";
public static String DOMAIN_ID = "DOMAIN_ID";
public static String VOCABULARY_ID = "VOCABULARY_ID";
public static String CONCEPT_CLASS_ID = "CONCEPT_CLASS_ID";
public static final String CONCEPT_ID = "CONCEPT_ID";
public static final String CONCEPT_NAME = "CONCEPT_NAME";
public static final String STANDARD_CONCEPT = "STANDARD_CONCEPT";
public static final String STANDARD_CONCEPT_CAPTION = "STANDARD_CONCEPT_CAPTION";
public static final String INVALID_REASON = "INVALID_REASON";
public static final String INVALID_REASON_CAPTION = "INVALID_REASON_CAPTION";
public static final String CONCEPT_CODE = "CONCEPT_CODE";
public static final String DOMAIN_ID = "DOMAIN_ID";
public static final String VOCABULARY_ID = "VOCABULARY_ID";
public static final String CONCEPT_CLASS_ID = "CONCEPT_CLASS_ID";


public static final String VS_CACHE_FILE_SUFFIX = ".cache";
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/phema/elm_to_omop/io/ElmReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ElmReader {

public static final String CQL_EXTENSION = ".cql";

public ElmReader() {
private ElmReader() {
super();
}

Expand Down
Loading

0 comments on commit 45002ca

Please sign in to comment.