3962 import csv to conceptmap needs status element (#3963)
* wip * test * refactor * doc change and changelog * add test cases * edit msg.code * fix msg code Co-authored-by: Justin_Dar <justin.dar@smilecdr.com>
This commit is contained in:
parent
9fd0addec6
commit
21cce44524
|
@ -138,7 +138,7 @@ public abstract class AbstractImportExportCsvConceptMapCommand extends BaseReque
|
|||
process();
|
||||
}
|
||||
|
||||
protected void parseAdditionalParameters(CommandLine theCommandLine) {}
|
||||
protected void parseAdditionalParameters(CommandLine theCommandLine) throws ParseException {}
|
||||
|
||||
protected abstract void process() throws ParseException, ExecutionException;
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome;
|
|||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.csv.CSVFormat;
|
||||
import org.apache.commons.csv.CSVParser;
|
||||
import org.apache.commons.csv.CSVRecord;
|
||||
|
@ -64,10 +65,15 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
|
|||
protected static final String TARGET_VALUE_SET_PARAM_LONGOPT = "output";
|
||||
protected static final String TARGET_VALUE_SET_PARAM_NAME = "output";
|
||||
protected static final String TARGET_VALUE_SET_PARAM_DESC = "The target value set of the ConceptMap to be imported (i.e. ConceptMap.targetUri).";
|
||||
protected static final String CONCEPTMAP_STATUS_PARAM = "s";
|
||||
protected static final String CONCEPTMAP_STATUS_PARAM_LONGOPT = "status";
|
||||
protected static final String CONCEPTMAP_STATUS_PARAM_NAME = "status";
|
||||
protected static final String CONCEPTMAP_STATUS_PARAM_DESC = "The status of the ConceptMap resource to be imported/exported (i.e. ConceptMap.status).";
|
||||
|
||||
protected String sourceValueSet;
|
||||
protected String targetValueSet;
|
||||
|
||||
private String status;
|
||||
private boolean hasElements;
|
||||
private boolean hasTargets;
|
||||
|
||||
|
@ -86,6 +92,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
|
|||
Options options = super.getOptions();
|
||||
|
||||
addRequiredOption(options, CONCEPTMAP_URL_PARAM, CONCEPTMAP_URL_PARAM_LONGOPT, CONCEPTMAP_URL_PARAM_NAME, CONCEPTMAP_URL_PARAM_DESC);
|
||||
addRequiredOption(options, CONCEPTMAP_STATUS_PARAM, CONCEPTMAP_STATUS_PARAM_LONGOPT, CONCEPTMAP_STATUS_PARAM_NAME, CONCEPTMAP_STATUS_PARAM_DESC);
|
||||
// </editor-fold desc="Additional parameters.">
|
||||
addOptionalOption(options, SOURCE_VALUE_SET_PARAM, SOURCE_VALUE_SET_PARAM_LONGOPT, SOURCE_VALUE_SET_PARAM_NAME, SOURCE_VALUE_SET_PARAM_DESC);
|
||||
addOptionalOption(options, TARGET_VALUE_SET_PARAM, TARGET_VALUE_SET_PARAM_LONGOPT, TARGET_VALUE_SET_PARAM_NAME, TARGET_VALUE_SET_PARAM_DESC);
|
||||
|
@ -96,7 +103,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void parseAdditionalParameters(CommandLine theCommandLine) {
|
||||
protected void parseAdditionalParameters(CommandLine theCommandLine) throws ParseException {
|
||||
sourceValueSet = theCommandLine.getOptionValue(SOURCE_VALUE_SET_PARAM);
|
||||
if (isBlank(sourceValueSet)) {
|
||||
ourLog.info("Source value set is not specified (i.e. ConceptMap.sourceUri).");
|
||||
|
@ -110,6 +117,11 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
|
|||
} else {
|
||||
ourLog.info("Specified target value set (i.e. ConceptMap.targetUri): {}", targetValueSet);
|
||||
}
|
||||
|
||||
status = theCommandLine.getOptionValue(CONCEPTMAP_STATUS_PARAM);
|
||||
if (isBlank(status)) {
|
||||
throw new ParseException(Msg.code(2132) + "No status (" + CONCEPTMAP_STATUS_PARAM + ") specified.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -178,6 +190,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
|
|||
.withTrim())
|
||||
) {
|
||||
retVal.setUrl(conceptMapUrl);
|
||||
retVal.setStatus(Enumerations.PublicationStatus.fromCode(status));
|
||||
|
||||
if (isNotBlank(sourceValueSet)) {
|
||||
retVal.setSource(new UriType(sourceValueSet));
|
||||
|
|
|
@ -2,8 +2,8 @@ package ca.uhn.fhir.cli;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.test.utilities.TlsAuthenticationTestHelper;
|
||||
import ca.uhn.fhir.test.utilities.RestServerR4Helper;
|
||||
import ca.uhn.fhir.test.utilities.TlsAuthenticationTestHelper;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import org.hl7.fhir.exceptions.FHIRException;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
|
@ -11,6 +11,7 @@ import org.hl7.fhir.r4.model.ConceptMap;
|
|||
import org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent;
|
||||
import org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent;
|
||||
import org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent;
|
||||
import org.hl7.fhir.r4.model.Enumerations;
|
||||
import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -24,6 +25,7 @@ import java.io.File;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class ImportCsvToConceptMapCommandR4Test {
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandR4Test.class);
|
||||
|
@ -34,6 +36,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
private static final String CS_URL_2 = "http://example.com/codesystem/2";
|
||||
private static final String CS_URL_3 = "http://example.com/codesystem/3";
|
||||
private static final String FILENAME = "import-csv-to-conceptmap-command-test-input.csv";
|
||||
private static final String STATUS = "Active";
|
||||
|
||||
static {
|
||||
System.setProperty("test", "true");
|
||||
|
@ -42,6 +45,8 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
private final FhirContext myFhirContext = FhirContext.forR4();
|
||||
private final String myVersion = "r4";
|
||||
private String myFilePath;
|
||||
private final String myStatus = Enumerations.PublicationStatus.ACTIVE.toCode();
|
||||
|
||||
|
||||
@RegisterExtension
|
||||
public final RestServerR4Helper myRestServerR4Helper = new RestServerR4Helper(true);
|
||||
|
@ -134,6 +139,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
"-i", VS_URL_1,
|
||||
"-o", VS_URL_2,
|
||||
"-f", myFilePath,
|
||||
"-s", myStatus,
|
||||
"-l"
|
||||
},
|
||||
"-t", theIncludeTls, myRestServerR4Helper
|
||||
|
@ -153,6 +159,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
assertEquals(myRestServerR4Helper.getBase() + "/ConceptMap/1/_history/1", conceptMap.getId());
|
||||
|
||||
assertEquals(CM_URL, conceptMap.getUrl());
|
||||
assertEquals(STATUS, conceptMap.getStatus().getDisplay());
|
||||
assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString());
|
||||
assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString());
|
||||
|
||||
|
@ -334,6 +341,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
"-i", VS_URL_1,
|
||||
"-o", VS_URL_2,
|
||||
"-f", myFilePath,
|
||||
"-s", myStatus,
|
||||
"-l"
|
||||
},
|
||||
"-t", theIncludeTls, myRestServerR4Helper
|
||||
|
@ -366,6 +374,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
"-i", "http://loinc.org",
|
||||
"-o", "http://phenxtoolkit.org",
|
||||
"-f", myFilePath,
|
||||
"-s", myStatus,
|
||||
"-l"
|
||||
},
|
||||
"-t", theIncludeTls, myRestServerR4Helper
|
||||
|
@ -385,6 +394,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
assertEquals(myRestServerR4Helper.getBase() + "/ConceptMap/1/_history/1", conceptMap.getId());
|
||||
|
||||
assertEquals("http://loinc.org/cm/loinc-to-phenx", conceptMap.getUrl());
|
||||
assertEquals(STATUS, conceptMap.getStatus().getDisplay());
|
||||
assertEquals("http://loinc.org", conceptMap.getSourceUriType().getValueAsString());
|
||||
assertEquals("http://phenxtoolkit.org", conceptMap.getTargetUriType().getValueAsString());
|
||||
|
||||
|
@ -418,6 +428,7 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
"-i", "http://loinc.org",
|
||||
"-o", "http://phenxtoolkit.org",
|
||||
"-f", myFilePath,
|
||||
"-s", myStatus,
|
||||
"-l"
|
||||
},
|
||||
"-t", theIncludeTls, myRestServerR4Helper
|
||||
|
@ -434,4 +445,29 @@ public class ImportCsvToConceptMapCommandR4Test {
|
|||
|
||||
assertEquals(myRestServerR4Helper.getBase() + "/ConceptMap/1/_history/2", conceptMap.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImportCsvToConceptMapCommand_withNoStatus_Fails() throws FHIRException {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
File fileToImport = new File(classLoader.getResource("loinc-to-phenx.csv").getFile());
|
||||
myFilePath = fileToImport.getAbsolutePath();
|
||||
|
||||
try {
|
||||
App.main(myTlsAuthenticationTestHelper.createBaseRequestGeneratingCommandArgs(
|
||||
new String[]{
|
||||
ImportCsvToConceptMapCommand.COMMAND,
|
||||
"-v", myVersion,
|
||||
"-u", "http://loinc.org/cm/loinc-to-phenx",
|
||||
"-i", "http://loinc.org",
|
||||
"-o", "http://phenxtoolkit.org",
|
||||
"-f", myFilePath,
|
||||
"-l"
|
||||
},
|
||||
"-t", true, myRestServerR4Helper
|
||||
));
|
||||
fail();
|
||||
} catch (Error e) {
|
||||
assertTrue(e.getMessage().contains("Missing required option: s"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 3962
|
||||
jira: SMILE-4516
|
||||
title: "Previously, using the `import-csv-to-conceptmap` command in the CLI successfully created ConceptMap resources
|
||||
without a `ConceptMap.status` element, which is against the FHIR specification. This has been fixed by adding a required
|
||||
option for status for the command."
|
Loading…
Reference in New Issue