978 cli tools for importing exporting terminology mappings need to be fixed (#988)

* Fixed export issue.

* Fixed import issue.

* Fixed tests.

* Fixed tests.
This commit is contained in:
Diederik Muylwyk 2018-06-07 10:22:41 -04:00 committed by GitHub
parent b61a3cc10b
commit 903df68d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 915 additions and 99 deletions

View File

@ -23,23 +23,23 @@ package ca.uhn.fhir.cli;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.convertors.VersionConvertor_30_40;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.ConceptMap;
import org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import static org.apache.commons.lang3.StringUtils.defaultString;
@ -72,11 +72,11 @@ public class ExportConceptMapToCsvCommand extends AbstractImportExportCsvConcept
}
@Override
protected void process() throws ParseException {
protected void process() throws ExecutionException {
searchForConceptMapByUrl();
}
private void searchForConceptMapByUrl() {
private void searchForConceptMapByUrl() throws ExecutionException {
ourLog.info("Searching for ConceptMap with specified URL (i.e. ConceptMap.url): {}", conceptMapUrl);
if (fhirVersion == FhirVersionEnum.DSTU3) {
org.hl7.fhir.dstu3.model.Bundle response = client
@ -111,61 +111,26 @@ public class ExportConceptMapToCsvCommand extends AbstractImportExportCsvConcept
}
}
private void convertConceptMapToCsv(org.hl7.fhir.dstu3.model.ConceptMap theConceptMap) {
ourLog.info("Exporting ConceptMap to CSV...");
BufferedWriter bufferedWriter = null;
CSVPrinter csvPrinter = null;
private void convertConceptMapToCsv(org.hl7.fhir.dstu3.model.ConceptMap theConceptMap) throws ExecutionException {
try {
bufferedWriter = Files.newBufferedWriter(Paths.get(file));
csvPrinter = new CSVPrinter(
bufferedWriter,
CSVFormat
.DEFAULT
.withRecordSeparator("\n")
.withHeader(Header.class));
for (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent group : theConceptMap.getGroup()) {
for (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent element : group.getElement()) {
for (org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent target : element.getTarget()) {
List<String> columns = new ArrayList<>();
columns.add(defaultString(group.getSource()));
columns.add(defaultString(group.getSourceVersion()));
columns.add(defaultString(group.getTarget()));
columns.add(defaultString(group.getTargetVersion()));
columns.add(defaultString(element.getCode()));
columns.add(defaultString(element.getDisplay()));
columns.add(defaultString(target.getCode()));
columns.add(defaultString(target.getDisplay()));
columns.add(defaultString(target.getEquivalence().toCode()));
columns.add(defaultString(target.getComment()));
csvPrinter.print(columns);
}
}
}
} catch (IOException ioe) {
throw new InternalErrorException(ioe);
} finally {
IOUtils.closeQuietly(csvPrinter);
IOUtils.closeQuietly(bufferedWriter);
convertConceptMapToCsv(VersionConvertor_30_40.convertConceptMap(theConceptMap));
} catch (FHIRException fe) {
throw new ExecutionException(fe);
}
ourLog.info("Finished exporting to {}", file);
}
private void convertConceptMapToCsv(ConceptMap theConceptMap) {
ourLog.info("Exporting ConceptMap to CSV...");
Writer writer = null;
CSVPrinter csvPrinter = null;
try {
writer = Files.newBufferedWriter(Paths.get(file));
csvPrinter = new CSVPrinter(
try (
Writer writer = Files.newBufferedWriter(Paths.get(file));
CSVPrinter csvPrinter = new CSVPrinter(
writer,
CSVFormat
.DEFAULT
.withRecordSeparator("\n")
.withHeader(Header.class).withQuoteMode(QuoteMode.ALL));
.withHeader(Header.class)
.withQuoteMode(QuoteMode.ALL));
) {
for (ConceptMapGroupComponent group : theConceptMap.getGroup()) {
for (SourceElementComponent element : group.getElement()) {
for (ConceptMap.TargetElementComponent target : element.getTarget()) {
@ -188,10 +153,8 @@ public class ExportConceptMapToCsvCommand extends AbstractImportExportCsvConcept
}
} catch (IOException ioe) {
throw new InternalErrorException(ioe);
} finally {
IOUtils.closeQuietly(csvPrinter);
IOUtils.closeQuietly(writer);
}
ourLog.info("Finished exporting to {}", file);
}
}

View File

@ -25,11 +25,9 @@ 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;
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.convertors.VersionConvertor_30_40;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.ConceptMap;
@ -43,7 +41,10 @@ import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import static org.apache.commons.lang3.StringUtils.*;
@ -96,7 +97,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
}
@Override
protected void parseAdditionalParameters(CommandLine theCommandLine) throws ParseException {
protected void parseAdditionalParameters(CommandLine theCommandLine) {
sourceValueSet = theCommandLine.getOptionValue(SOURCE_VALUE_SET_PARAM);
if (isBlank(sourceValueSet)) {
ourLog.info("Source value set is not specified (i.e. ConceptMap.sourceUri).");
@ -113,11 +114,11 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
}
@Override
protected void process() throws ParseException, ExecutionException {
protected void process() throws ExecutionException {
searchForConceptMapByUrl();
}
private void searchForConceptMapByUrl() throws ParseException, ExecutionException {
private void searchForConceptMapByUrl() throws ExecutionException {
if (fhirVersion == FhirVersionEnum.DSTU3) {
org.hl7.fhir.dstu3.model.ConceptMap conceptMap = convertCsvToConceptMapDstu3();
@ -153,7 +154,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
}
}
private org.hl7.fhir.dstu3.model.ConceptMap convertCsvToConceptMapDstu3() throws ParseException, ExecutionException {
private org.hl7.fhir.dstu3.model.ConceptMap convertCsvToConceptMapDstu3() throws ExecutionException {
try {
return VersionConvertor_30_40.convertConceptMap(convertCsvToConceptMapR4());
} catch (FHIRException fe) {
@ -161,14 +162,12 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
}
}
private ConceptMap convertCsvToConceptMapR4() throws ParseException, ExecutionException {
private ConceptMap convertCsvToConceptMapR4() throws ExecutionException {
ourLog.info("Converting CSV to ConceptMap...");
ConceptMap retVal = new ConceptMap();
Reader reader = null;
CSVParser csvParser = null;
try {
reader = Files.newBufferedReader(Paths.get(file));
csvParser = new CSVParser(
try (
Reader reader = Files.newBufferedReader(Paths.get(file));
CSVParser csvParser = new CSVParser(
reader,
CSVFormat
.DEFAULT
@ -178,7 +177,7 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
.withIgnoreHeaderCase()
.withIgnoreEmptyLines()
.withTrim());
) {
retVal.setUrl(conceptMapUrl);
if (isNotBlank(sourceValueSet)) {
@ -278,9 +277,6 @@ public class ImportCsvToConceptMapCommand extends AbstractImportExportCsvConcept
}
} catch (IOException e) {
throw new InternalErrorException(e);
} finally {
IOUtils.closeQuietly(csvParser);
IOUtils.closeQuietly(reader);
}
ourLog.info("Finished converting CSV to ConceptMap.");

View File

@ -0,0 +1,283 @@
package ca.uhn.fhir.cli;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence;
import org.hl7.fhir.dstu3.model.UriType;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class ExportConceptMapToCsvCommandDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExportConceptMapToCsvCommandDstu3Test.class);
private static final String CM_URL = "http://example.com/conceptmap";
private static final String VS_URL_1 = "http://example.com/valueset/1";
private static final String VS_URL_2 = "http://example.com/valueset/2";
private static final String CS_URL_1 = "http://example.com/codesystem/1";
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 FILE = "./target/output.csv";
private static String ourBase;
private static IGenericClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu3();
private static int ourPort;
private static Server ourServer;
private static String ourVersion = "dstu3";
static {
System.setProperty("test", "true");
}
@AfterClass
public static void afterClassClearContext() throws Exception {
ourServer.stop();
TestUtil.clearAllStaticFieldsForUnitTest();
}
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
ServletHandler servletHandler = new ServletHandler();
RestfulServer restfulServer = new RestfulServer(ourCtx);
restfulServer.registerInterceptor(new VerboseLoggingInterceptor());
restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapDstu3(ourCtx));
ServletHolder servletHolder = new ServletHolder(restfulServer);
servletHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(servletHandler);
ourServer.start();
ourBase = "http://localhost:" + ourPort;
ourClient = ourCtx.newRestfulGenericClient(ourBase);
ourClient.create().resource(createConceptMap()).execute();
}
@Test
public void testExportConceptMapToCsvCommand() throws IOException {
ourLog.info("ConceptMap:\n" + ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(createConceptMap()));
App.main(new String[] {"export-conceptmap-to-csv",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-f", FILE,
"-l"});
String expected = "\"SOURCE_CODE_SYSTEM\",\"SOURCE_CODE_SYSTEM_VERSION\",\"TARGET_CODE_SYSTEM\",\"TARGET_CODE_SYSTEM_VERSION\",\"SOURCE_CODE\",\"SOURCE_DISPLAY\",\"TARGET_CODE\",\"TARGET_DISPLAY\",\"EQUIVALENCE\",\"COMMENT\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/2\",\"Version 2t\",\"Code 1a\",\"Display 1a\",\"Code 2a\",\"Display 2a\",\"equal\",\"2a This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/2\",\"Version 2t\",\"Code 1b\",\"Display 1b\",\"Code 2b\",\"Display 2b\",\"equal\",\"2b This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/2\",\"Version 2t\",\"Code 1c\",\"Display 1c\",\"Code 2c\",\"Display 2c\",\"equal\",\"2c This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/2\",\"Version 2t\",\"Code 1d\",\"Display 1d\",\"Code 2d\",\"Display 2d\",\"equal\",\"2d This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 1a\",\"Display 1a\",\"Code 3a\",\"Display 3a\",\"equal\",\"3a This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 1b\",\"Display 1b\",\"Code 3b\",\"Display 3b\",\"equal\",\"3b This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 1c\",\"Display 1c\",\"Code 3c\",\"Display 3c\",\"equal\",\"3c This is a comment.\"\n" +
"\"http://example.com/codesystem/1\",\"Version 1s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 1d\",\"Display 1d\",\"Code 3d\",\"Display 3d\",\"equal\",\"3d This is a comment.\"\n" +
"\"http://example.com/codesystem/2\",\"Version 2s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 2a\",\"Display 2a\",\"Code 3a\",\"Display 3a\",\"equal\",\"3a This is a comment.\"\n" +
"\"http://example.com/codesystem/2\",\"Version 2s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 2b\",\"Display 2b\",\"Code 3b\",\"Display 3b\",\"equal\",\"3b This is a comment.\"\n" +
"\"http://example.com/codesystem/2\",\"Version 2s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 2c\",\"Display 2c\",\"Code 3c\",\"Display 3c\",\"equal\",\"3c This is a comment.\"\n" +
"\"http://example.com/codesystem/2\",\"Version 2s\",\"http://example.com/codesystem/3\",\"Version 3t\",\"Code 2d\",\"Display 2d\",\"Code 3d\",\"Display 3d\",\"equal\",\"3d This is a comment.\"\n";
String result = IOUtils.toString(new FileInputStream(FILE), Charsets.UTF_8);
assertEquals(expected, result);
FileUtils.deleteQuietly(new File(FILE));
}
static ConceptMap createConceptMap() {
ConceptMap conceptMap = new ConceptMap();
conceptMap
.setUrl(CM_URL)
.setSource(new UriType(VS_URL_1))
.setTarget(new UriType(VS_URL_2));
ConceptMap.ConceptMapGroupComponent group = conceptMap.addGroup();
group
.setSource(CS_URL_1)
.setSourceVersion("Version 1s")
.setTarget(CS_URL_2)
.setTargetVersion("Version 2t");
ConceptMap.SourceElementComponent element = group.addElement();
element
.setCode("Code 1a")
.setDisplay("Display 1a");
ConceptMap.TargetElementComponent target = element.addTarget();
target
.setCode("Code 2a")
.setDisplay("Display 2a")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("2a This is a comment.");
element = group.addElement();
element
.setCode("Code 1b")
.setDisplay("Display 1b");
target = element.addTarget();
target
.setCode("Code 2b")
.setDisplay("Display 2b")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("2b This is a comment.");
element = group.addElement();
element
.setCode("Code 1c")
.setDisplay("Display 1c");
target = element.addTarget();
target
.setCode("Code 2c")
.setDisplay("Display 2c")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("2c This is a comment.");
element = group.addElement();
element
.setCode("Code 1d")
.setDisplay("Display 1d");
target = element.addTarget();
target
.setCode("Code 2d")
.setDisplay("Display 2d")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("2d This is a comment.");
group = conceptMap.addGroup();
group
.setSource(CS_URL_1)
.setSourceVersion("Version 1s")
.setTarget(CS_URL_3)
.setTargetVersion("Version 3t");
element = group.addElement();
element
.setCode("Code 1a")
.setDisplay("Display 1a");
target = element.addTarget();
target
.setCode("Code 3a")
.setDisplay("Display 3a")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3a This is a comment.");
element = group.addElement();
element
.setCode("Code 1b")
.setDisplay("Display 1b");
target = element.addTarget();
target
.setCode("Code 3b")
.setDisplay("Display 3b")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3b This is a comment.");
element = group.addElement();
element
.setCode("Code 1c")
.setDisplay("Display 1c");
target = element.addTarget();
target
.setCode("Code 3c")
.setDisplay("Display 3c")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3c This is a comment.");
element = group.addElement();
element
.setCode("Code 1d")
.setDisplay("Display 1d");
target = element.addTarget();
target
.setCode("Code 3d")
.setDisplay("Display 3d")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3d This is a comment.");
group = conceptMap.addGroup();
group
.setSource(CS_URL_2)
.setSourceVersion("Version 2s")
.setTarget(CS_URL_3)
.setTargetVersion("Version 3t");
element = group.addElement();
element
.setCode("Code 2a")
.setDisplay("Display 2a");
target = element.addTarget();
target
.setCode("Code 3a")
.setDisplay("Display 3a")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3a This is a comment.");
element = group.addElement();
element
.setCode("Code 2b")
.setDisplay("Display 2b");
target = element.addTarget();
target
.setCode("Code 3b")
.setDisplay("Display 3b")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3b This is a comment.");
element = group.addElement();
element
.setCode("Code 2c")
.setDisplay("Display 2c");
target = element.addTarget();
target
.setCode("Code 3c")
.setDisplay("Display 3c")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3c This is a comment.");
element = group.addElement();
element
.setCode("Code 2d")
.setDisplay("Display 2d");
target = element.addTarget();
target
.setCode("Code 3d")
.setDisplay("Display 3d")
.setEquivalence(ConceptMapEquivalence.EQUAL)
.setComment("3d This is a comment.");
return conceptMap;
}
}

View File

@ -25,8 +25,8 @@ import java.io.IOException;
import static org.junit.Assert.assertEquals;
public class ExportConceptMapToCsvCommandTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExportConceptMapToCsvCommandTest.class);
public class ExportConceptMapToCsvCommandR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExportConceptMapToCsvCommandR4Test.class);
private static final String CM_URL = "http://example.com/conceptmap";
private static final String VS_URL_1 = "http://example.com/valueset/1";
private static final String VS_URL_2 = "http://example.com/valueset/2";
@ -40,6 +40,7 @@ public class ExportConceptMapToCsvCommandTest {
private static FhirContext ourCtx = FhirContext.forR4();
private static int ourPort;
private static Server ourServer;
private static String ourVersion = "r4";
static {
System.setProperty("test", "true");
@ -80,7 +81,7 @@ public class ExportConceptMapToCsvCommandTest {
ourLog.info("ConceptMap:\n" + ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(createConceptMap()));
App.main(new String[] {"export-conceptmap-to-csv",
"-v", "r4",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-f", FILE,

View File

@ -0,0 +1,127 @@
package ca.uhn.fhir.cli;
/*-
* #%L
* HAPI FHIR - Server Framework
* %%
* Copyright (C) 2014 - 2018 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.provider.AbstractHashMapResourceProvider;
import com.google.common.base.Charsets;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.IdType;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
/**
* This is a subclass to implement FHIR operations specific to DSTU3 ConceptMap
* resources. Its superclass, {@link AbstractHashMapResourceProvider}, is a simple
* implementation of the resource provider interface that uses a HashMap to
* store all resources in memory.
* <p>
* This subclass currently supports the following FHIR operations:
* </p>
* <ul>
* <li>Search for DSTU3 ConceptMap resources by ConceptMap.url</li>
* <li>Conditional update for DSTU3 ConceptMap resources by ConceptMap.url</li>
* </ul>
*/
public class HashMapResourceProviderConceptMapDstu3 extends AbstractHashMapResourceProvider<ConceptMap> {
@SuppressWarnings("unchecked")
public HashMapResourceProviderConceptMapDstu3(FhirContext theFhirContext) {
super(theFhirContext, ConceptMap.class);
FhirVersionEnum fhirVersion = theFhirContext.getVersion().getVersion();
if (fhirVersion != FhirVersionEnum.DSTU3) {
throw new IllegalStateException("Requires FHIR version DSTU3. Unsupported FHIR version provided: " + fhirVersion);
}
}
@Search
public List<ConceptMap> searchByUrl(
@RequiredParam(name=ConceptMap.SP_URL) String theConceptMapUrl) {
List<ConceptMap> retVal = new ArrayList<>();
for (TreeMap<Long, ConceptMap> next : myIdToVersionToResourceMap.values()) {
if (!next.isEmpty()) {
ConceptMap conceptMap = next.lastEntry().getValue();
if (theConceptMapUrl.equals(conceptMap.getUrl()))
retVal.add(conceptMap);
break;
}
}
return retVal;
}
@Update
public MethodOutcome updateConceptMapConditional(
@ResourceParam ConceptMap theConceptMap,
@IdParam IdType theId,
@ConditionalUrlParam String theConditional) {
MethodOutcome methodOutcome = new MethodOutcome();
if (theConditional != null) {
String url = null;
try {
List<NameValuePair> params = URLEncodedUtils.parse(new URI(theConditional), Charsets.UTF_8);
for (NameValuePair param : params) {
if (param.getName().equalsIgnoreCase("url")) {
url = param.getValue();
break;
}
}
} catch (URISyntaxException urise) {
throw new InvalidRequestException(urise);
}
if (isNotBlank(url)) {
List<ConceptMap> conceptMaps = searchByUrl(url);
if (!conceptMaps.isEmpty()) {
methodOutcome = update(conceptMaps.get(0));
} else {
methodOutcome = create(theConceptMap);
}
}
} else {
methodOutcome = update(theConceptMap);
}
return methodOutcome;
}
}

View File

@ -0,0 +1,367 @@
package ca.uhn.fhir.cli;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor;
import ca.uhn.fhir.util.PortUtil;
import ca.uhn.fhir.util.TestUtil;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.dstu3.model.Bundle;
import org.hl7.fhir.dstu3.model.ConceptMap;
import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent;
import org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent;
import org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent;
import org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
public class ImportCsvToConceptMapCommandDstu3Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandDstu3Test.class);
private static final String CM_URL = "http://example.com/conceptmap";
private static final String VS_URL_1 = "http://example.com/valueset/1";
private static final String VS_URL_2 = "http://example.com/valueset/2";
private static final String CS_URL_1 = "http://example.com/codesystem/1";
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 String file;
private static String ourBase;
private static IGenericClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu3();
private static int ourPort;
private static Server ourServer;
private static String ourVersion = "dstu3";
private static RestfulServer restfulServer;
private static HashMapResourceProviderConceptMapDstu3 hashMapResourceProviderConceptMapDstu3;
static {
System.setProperty("test", "true");
}
@After
public void afterClearResourceProvider() {
HashMapResourceProviderConceptMapDstu3 resourceProvider = (HashMapResourceProviderConceptMapDstu3) restfulServer.getResourceProviders().iterator().next();
resourceProvider.clear();
}
@AfterClass
public static void afterClassClearContext() throws Exception {
ourServer.stop();
TestUtil.clearAllStaticFieldsForUnitTest();
}
@BeforeClass
public static void beforeClass() throws Exception {
ourPort = PortUtil.findFreePort();
ourServer = new Server(ourPort);
ServletHandler servletHandler = new ServletHandler();
restfulServer = new RestfulServer(ourCtx);
restfulServer.registerInterceptor(new VerboseLoggingInterceptor());
restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapDstu3(ourCtx));
ServletHolder servletHolder = new ServletHolder(restfulServer);
servletHandler.addServletWithMapping(servletHolder, "/*");
ourServer.setHandler(servletHandler);
ourServer.start();
ourBase = "http://localhost:" + ourPort;
ourClient = ourCtx.newRestfulGenericClient(ourBase);
}
@Test
public void testConditionalUpdateResultsInCreate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandDstu3Test.createConceptMap();
String conceptMapUrl = conceptMap.getUrl();
ourLog.info("Searching for existing ConceptMap with specified URL (i.e. ConceptMap.url): {}", conceptMapUrl);
MethodOutcome methodOutcome = ourClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMapUrl))
.execute();
assertEquals(Boolean.TRUE, methodOutcome.getCreated());
}
@Test
public void testConditionalUpdateResultsInUpdate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandDstu3Test.createConceptMap();
ourClient.create().resource(conceptMap).execute();
String conceptMapUrl = conceptMap.getUrl();
ourLog.info("Searching for existing ConceptMap with specified URL (i.e. ConceptMap.url): {}", conceptMapUrl);
MethodOutcome methodOutcome = ourClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMapUrl))
.execute();
assertNull(methodOutcome.getCreated());
}
@Test
public void testNonConditionalUpdate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandDstu3Test.createConceptMap();
ourClient.create().resource(conceptMap).execute();
Bundle response = ourClient
.search()
.forResource(ConceptMap.class)
.where(ConceptMap.URL.matches().value(CM_URL))
.returnBundle(Bundle.class)
.execute();
ConceptMap resultConceptMap = (ConceptMap) response.getEntryFirstRep().getResource();
MethodOutcome methodOutcome = ourClient
.update()
.resource(resultConceptMap)
.withId(resultConceptMap.getIdElement())
.execute();
assertNull(methodOutcome.getCreated());
}
@Test
public void testImportCsvToConceptMapCommand() throws FHIRException {
ClassLoader classLoader = getClass().getClassLoader();
File fileToImport = new File(classLoader.getResource(FILENAME).getFile());
ImportCsvToConceptMapCommandDstu3Test.file = fileToImport.getAbsolutePath();
App.main(new String[] {"import-csv-to-conceptmap",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-i", VS_URL_1,
"-o", VS_URL_2,
"-f", file,
"-l"});
Bundle response = ourClient
.search()
.forResource(ConceptMap.class)
.where(ConceptMap.URL.matches().value(CM_URL))
.returnBundle(Bundle.class)
.execute();
ConceptMap conceptMap = (ConceptMap) response.getEntryFirstRep().getResource();
ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(conceptMap));
assertEquals("http://localhost:" + ourPort + "/ConceptMap/1/_history/1", conceptMap.getId());
assertEquals(CM_URL, conceptMap.getUrl());
assertEquals(VS_URL_1, conceptMap.getSourceUriType().getValueAsString());
assertEquals(VS_URL_2, conceptMap.getTargetUriType().getValueAsString());
assertEquals(3, conceptMap.getGroup().size());
ConceptMapGroupComponent group = conceptMap.getGroup().get(0);
assertEquals(CS_URL_1, group.getSource());
assertEquals("Version 1s", group.getSourceVersion());
assertEquals(CS_URL_2, group.getTarget());
assertEquals("Version 2t", group.getTargetVersion());
assertEquals(4, group.getElement().size());
SourceElementComponent source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size());
TargetElementComponent target = source.getTarget().get(0);
assertEquals("Code 2a", target.getCode());
assertEquals("Display 2a", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("2a This is a comment.", target.getComment());
source = group.getElement().get(1);
assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 2b", target.getCode());
assertEquals("Display 2b", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("2b This is a comment.", target.getComment());
source = group.getElement().get(2);
assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 2c", target.getCode());
assertEquals("Display 2c", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("2c This is a comment.", target.getComment());
source = group.getElement().get(3);
assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 2d", target.getCode());
assertEquals("Display 2d", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("2d This is a comment.", target.getComment());
group = conceptMap.getGroup().get(1);
assertEquals(CS_URL_1, group.getSource());
assertEquals("Version 1s", group.getSourceVersion());
assertEquals(CS_URL_3, group.getTarget());
assertEquals("Version 3t", group.getTargetVersion());
assertEquals(4, group.getElement().size());
source = group.getElement().get(0);
assertEquals("Code 1a", source.getCode());
assertEquals("Display 1a", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode());
assertEquals("Display 3a", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3a This is a comment.", target.getComment());
source = group.getElement().get(1);
assertEquals("Code 1b", source.getCode());
assertEquals("Display 1b", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode());
assertEquals("Display 3b", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3b This is a comment.", target.getComment());
source = group.getElement().get(2);
assertEquals("Code 1c", source.getCode());
assertEquals("Display 1c", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode());
assertEquals("Display 3c", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3c This is a comment.", target.getComment());
source = group.getElement().get(3);
assertEquals("Code 1d", source.getCode());
assertEquals("Display 1d", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode());
assertEquals("Display 3d", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3d This is a comment.", target.getComment());
group = conceptMap.getGroup().get(2);
assertEquals(CS_URL_2, group.getSource());
assertEquals("Version 2s", group.getSourceVersion());
assertEquals(CS_URL_3, group.getTarget());
assertEquals("Version 3t", group.getTargetVersion());
assertEquals(4, group.getElement().size());
source = group.getElement().get(0);
assertEquals("Code 2a", source.getCode());
assertEquals("Display 2a", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3a", target.getCode());
assertEquals("Display 3a", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3a This is a comment.", target.getComment());
source = group.getElement().get(1);
assertEquals("Code 2b", source.getCode());
assertEquals("Display 2b", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3b", target.getCode());
assertEquals("Display 3b", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3b This is a comment.", target.getComment());
source = group.getElement().get(2);
assertEquals("Code 2c", source.getCode());
assertEquals("Display 2c", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3c", target.getCode());
assertEquals("Display 3c", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3c This is a comment.", target.getComment());
source = group.getElement().get(3);
assertEquals("Code 2d", source.getCode());
assertEquals("Display 2d", source.getDisplay());
assertEquals(1, source.getTarget().size());
target = source.getTarget().get(0);
assertEquals("Code 3d", target.getCode());
assertEquals("Display 3d", target.getDisplay());
assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence());
assertEquals("3d This is a comment.", target.getComment());
App.main(new String[] {"import-csv-to-conceptmap",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-i", VS_URL_1,
"-o", VS_URL_2,
"-f", file,
"-l"});
response = ourClient
.search()
.forResource(ConceptMap.class)
.where(ConceptMap.URL.matches().value(CM_URL))
.returnBundle(Bundle.class)
.execute();
conceptMap = (ConceptMap) response.getEntryFirstRep().getResource();
assertEquals("http://localhost:" + ourPort + "/ConceptMap/1/_history/2", conceptMap.getId());
}
}

View File

@ -10,13 +10,13 @@ import ca.uhn.fhir.util.TestUtil;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Bundle;
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.ConceptMapEquivalence;
import org.hl7.fhir.exceptions.FHIRException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -26,8 +26,8 @@ import java.io.File;
import static org.junit.Assert.*;
public class ImportCsvToConceptMapCommandTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandTest.class);
public class ImportCsvToConceptMapCommandR4Test {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandR4Test.class);
private static final String CM_URL = "http://example.com/conceptmap";
private static final String VS_URL_1 = "http://example.com/valueset/1";
private static final String VS_URL_2 = "http://example.com/valueset/2";
@ -42,6 +42,7 @@ public class ImportCsvToConceptMapCommandTest {
private static FhirContext ourCtx = FhirContext.forR4();
private static int ourPort;
private static Server ourServer;
private static String ourVersion = "r4";
private static RestfulServer restfulServer;
@ -87,7 +88,7 @@ public class ImportCsvToConceptMapCommandTest {
@Test
public void testConditionalUpdateResultsInCreate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandTest.createConceptMap();
ConceptMap conceptMap = ExportConceptMapToCsvCommandR4Test.createConceptMap();
String conceptMapUrl = conceptMap.getUrl();
ourLog.info("Searching for existing ConceptMap with specified URL (i.e. ConceptMap.url): {}", conceptMapUrl);
@ -104,7 +105,7 @@ public class ImportCsvToConceptMapCommandTest {
@Test
public void testConditionalUpdateResultsInUpdate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandTest.createConceptMap();
ConceptMap conceptMap = ExportConceptMapToCsvCommandR4Test.createConceptMap();
ourClient.create().resource(conceptMap).execute();
String conceptMapUrl = conceptMap.getUrl();
@ -122,7 +123,7 @@ public class ImportCsvToConceptMapCommandTest {
@Test
public void testNonConditionalUpdate() {
ConceptMap conceptMap = ExportConceptMapToCsvCommandTest.createConceptMap();
ConceptMap conceptMap = ExportConceptMapToCsvCommandR4Test.createConceptMap();
ourClient.create().resource(conceptMap).execute();
Bundle response = ourClient
@ -150,10 +151,10 @@ public class ImportCsvToConceptMapCommandTest {
public void testImportCsvToConceptMapCommand() throws FHIRException {
ClassLoader classLoader = getClass().getClassLoader();
File fileToImport = new File(classLoader.getResource(FILENAME).getFile());
ImportCsvToConceptMapCommandTest.file = fileToImport.getAbsolutePath();
ImportCsvToConceptMapCommandR4Test.file = fileToImport.getAbsolutePath();
App.main(new String[] {"import-csv-to-conceptmap",
"-v", "r4",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-i", VS_URL_1,
@ -349,7 +350,7 @@ public class ImportCsvToConceptMapCommandTest {
assertEquals("3d This is a comment.", target.getComment());
App.main(new String[] {"import-csv-to-conceptmap",
"-v", "r4",
"-v", ourVersion,
"-t", ourBase,
"-u", CM_URL,
"-i", VS_URL_1,

View File

@ -27,7 +27,7 @@ import org.springframework.data.repository.query.Param;
*/
public interface ITermConceptMapGroupDao extends JpaRepository<TermConceptMapGroup, Long> {
@Query("DELETE FROM TermConceptMapGroup g WHERE g.myConceptMap.myId = :pid")
@Query("DELETE FROM TermConceptMapGroup g WHERE g.myId = :pid")
@Modifying
void deleteTermConceptMapGroupById(@Param("pid") Long theId);
}

View File

@ -27,7 +27,7 @@ import org.springframework.data.repository.query.Param;
*/
public interface ITermConceptMapGroupElementDao extends JpaRepository<TermConceptMapGroupElement, Long> {
@Query("DELETE FROM TermConceptMapGroupElement e WHERE e.myConceptMapGroup.myConceptMap.myId = :pid")
@Query("DELETE FROM TermConceptMapGroupElement e WHERE e.myId = :pid")
@Modifying
void deleteTermConceptMapGroupElementById(@Param("pid") Long theId);
}

View File

@ -27,7 +27,7 @@ import org.springframework.data.repository.query.Param;
*/
public interface ITermConceptMapGroupElementTargetDao extends JpaRepository<TermConceptMapGroupElementTarget, Long> {
@Query("DELETE FROM TermConceptMapGroupElementTarget t WHERE t.myConceptMapGroupElement.myConceptMapGroup.myConceptMap.myId = :pid")
@Query("DELETE FROM TermConceptMapGroupElementTarget t WHERE t.myId = :pid")
@Modifying
void deleteTermConceptMapGroupElementTargetById(@Param("pid") Long theId);
}

View File

@ -115,11 +115,12 @@ public class TermConceptMap implements Serializable {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("myId", myId)
.append("myResource", myResource.toString())
.append(myResource != null ? ("myResource=" + myResource.toString()) : ("myResource=(null)"))
.append("myResourcePid", myResourcePid)
.append("mySource", mySource)
.append("myTarget", myTarget)
.append("myUrl", myUrl)
.append("myConceptMapGroups - size", myConceptMapGroups.size())
.append(myConceptMapGroups != null ? ("myConceptMapGroups - size=" + myConceptMapGroups.size()) : ("myConceptMapGroups=(null)"))
.toString();
}
}

View File

@ -137,12 +137,12 @@ public class TermConceptMapGroup implements Serializable {
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("myId", myId)
.append("myConceptMap - id", myConceptMap.getId())
.append(myConceptMap != null ? ("myConceptMap - id=" + myConceptMap.getId()) : ("myConceptMap=(null)"))
.append("mySource", mySource)
.append("mySourceVersion", mySourceVersion)
.append("myTarget", myTarget)
.append("myTargetVersion", myTargetVersion)
.append("myConceptMapGroupElements - size", myConceptMapGroupElements.size())
.append(myConceptMapGroupElements != null ? ("myConceptMapGroupElements - size=" + myConceptMapGroupElements.size()) : ("myConceptMapGroupElements=(null)"))
.append("myConceptMapUrl", this.getConceptMapUrl())
.append("mySourceValueSet", this.getSourceValueSet())
.append("myTargetValueSet", this.getTargetValueSet())

View File

@ -151,10 +151,10 @@ public class TermConceptMapGroupElement implements Serializable {
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("myId", myId)
.append("myConceptMapGroup - id", myConceptMapGroup.getId())
.append(myConceptMapGroup != null ? ("myConceptMapGroup - id=" + myConceptMapGroup.getId()) : ("myConceptMapGroup=(null)"))
.append("myCode", myCode)
.append("myDisplay", myDisplay)
.append("myConceptMapGroupElementTargets - size", myConceptMapGroupElementTargets.size())
.append(myConceptMapGroupElementTargets != null ? ("myConceptMapGroupElementTargets - size=" + myConceptMapGroupElementTargets.size()) : ("myConceptMapGroupElementTargets=(null)"))
.append("myConceptMapUrl", this.getConceptMapUrl())
.append("mySystem", this.getSystem())
.append("mySystemVersion", this.getSystemVersion())

View File

@ -153,7 +153,7 @@ public class TermConceptMapGroupElementTarget implements Serializable {
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("myId", myId)
.append("myConceptMapGroupElement - id", myConceptMapGroupElement.getId())
.append(myConceptMapGroupElement != null ? ("myConceptMapGroupElement - id=" + myConceptMapGroupElement.getId()) : ("myConceptMapGroupElement=(null)"))
.append("myCode", myCode)
.append("myDisplay", myDisplay)
.append("myEquivalence", myEquivalence.toCode())

View File

@ -964,20 +964,33 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc,
termConceptMap.setUrl(theConceptMap.getUrl());
// Get existing entity so it can be deleted.
Optional<TermConceptMap> optionalExistingTermConceptMapById = myConceptMapDao.findTermConceptMapByResourcePid(termConceptMap.getResourcePid());
Optional<TermConceptMap> optionalExistingTermConceptMapById = myConceptMapDao.findTermConceptMapByResourcePid(theResourceTable.getId());
/*
* For now we always delete old versions. At some point, it would be nice to allow configuration to keep old versions.
*/
if (optionalExistingTermConceptMapById.isPresent()) {
Long id = optionalExistingTermConceptMapById.get().getId();
ourLog.info("Deleting existing TermConceptMap {} and its children...", id);
myConceptMapGroupElementTargetDao.deleteTermConceptMapGroupElementTargetById(id);
myConceptMapGroupElementDao.deleteTermConceptMapGroupElementById(id);
myConceptMapGroupDao.deleteTermConceptMapGroupById(id);
myConceptMapDao.deleteTermConceptMapById(id);
ourLog.info("Done deleting existing TermConceptMap {} and its children.", id);
TermConceptMap existingTermConceptMap = optionalExistingTermConceptMapById.get();
ourLog.info("Deleting existing TermConceptMap {} and its children...", existingTermConceptMap.getId());
for (TermConceptMapGroup group : existingTermConceptMap.getConceptMapGroups()) {
for (TermConceptMapGroupElement element : group.getConceptMapGroupElements()) {
for (TermConceptMapGroupElementTarget target : element.getConceptMapGroupElementTargets()) {
myConceptMapGroupElementTargetDao.deleteTermConceptMapGroupElementTargetById(target.getId());
}
myConceptMapGroupElementDao.deleteTermConceptMapGroupElementById(element.getId());
}
myConceptMapGroupDao.deleteTermConceptMapGroupById(group.getId());
}
myConceptMapDao.deleteTermConceptMapById(existingTermConceptMap.getId());
ourLog.info("Done deleting existing TermConceptMap {} and its children.", existingTermConceptMap.getId());
ourLog.info("Flushing...");
myConceptMapGroupElementTargetDao.flush();

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.provider.dstu3;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.dstu3.model.*;
import org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent;
@ -29,6 +30,37 @@ public class ResourceProviderDstu3ConceptMapTest extends BaseResourceProviderDst
myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless();
}
@Test
public void testStoreExistingTermConceptMapAndChildren() {
ConceptMap conceptMap = createConceptMap();
MethodOutcome methodOutcome = ourClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMap.getUrl()))
.execute();
assertNull(methodOutcome.getCreated());
assertEquals("1", methodOutcome.getId().getVersionIdPart());
}
@Test
public void testStoreUpdatedTermConceptMapAndChildren() {
ConceptMap conceptMap = createConceptMap();
conceptMap.getGroupFirstRep().getElementFirstRep().setCode("UPDATED_CODE");
MethodOutcome methodOutcome = ourClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMap.getUrl()))
.execute();
assertNull(methodOutcome.getCreated());
assertEquals("2", methodOutcome.getId().getVersionIdPart());
}
@Test
public void testTranslateByCodeSystemsAndSourceCodeOneToMany() {
ConceptMap conceptMap = myConceptMapDao.read(myConceptMapId);

View File

@ -1,5 +1,6 @@
package ca.uhn.fhir.jpa.provider.r4;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.*;
@ -29,6 +30,37 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test
myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless();
}
@Test
public void testStoreExistingTermConceptMapAndChildren() {
ConceptMap conceptMap = createConceptMap();
MethodOutcome methodOutcome = myClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMap.getUrl()))
.execute();
assertNull(methodOutcome.getCreated());
assertEquals("1", methodOutcome.getId().getVersionIdPart());
}
@Test
public void testStoreUpdatedTermConceptMapAndChildren() {
ConceptMap conceptMap = createConceptMap();
conceptMap.getGroupFirstRep().getElementFirstRep().setCode("UPDATED_CODE");
MethodOutcome methodOutcome = myClient
.update()
.resource(conceptMap)
.conditional()
.where(ConceptMap.URL.matches().value(conceptMap.getUrl()))
.execute();
assertNull(methodOutcome.getCreated());
assertEquals("2", methodOutcome.getId().getVersionIdPart());
}
@Test
public void testTranslateByCodeSystemsAndSourceCodeOneToMany() {
ConceptMap conceptMap = myConceptMapDao.read(myConceptMapId);