Return codesystem ID in upload terminology response
This commit is contained in:
parent
9be96c4130
commit
994f2992d1
|
@ -27,10 +27,7 @@ import ca.uhn.fhir.rest.param.StringParam;
|
|||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
|
||||
import org.hl7.fhir.r4.model.Attachment;
|
||||
import org.hl7.fhir.r4.model.IntegerType;
|
||||
import org.hl7.fhir.r4.model.Parameters;
|
||||
import org.hl7.fhir.r4.model.StringType;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -44,6 +41,8 @@ public abstract class BaseTerminologyUploaderProvider extends BaseJpaProvider {
|
|||
public static final String UPLOAD_EXTERNAL_CODE_SYSTEM = "$upload-external-code-system";
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseTerminologyUploaderProvider.class);
|
||||
public static final String CONCEPT_COUNT = "conceptCount";
|
||||
public static final String TARGET = "target";
|
||||
|
||||
@Autowired
|
||||
private IHapiTerminologyLoaderSvc myTerminologyLoaderSvc;
|
||||
|
@ -125,7 +124,8 @@ public abstract class BaseTerminologyUploaderProvider extends BaseJpaProvider {
|
|||
}
|
||||
|
||||
Parameters retVal = new Parameters();
|
||||
retVal.addParameter().setName("conceptCount").setValue(new IntegerType(stats.getConceptCount()));
|
||||
retVal.addParameter().setName(CONCEPT_COUNT).setValue(new IntegerType(stats.getConceptCount()));
|
||||
retVal.addParameter().setName(TARGET).setValue(new Reference(stats.getTarget().getValue()));
|
||||
return retVal;
|
||||
} finally {
|
||||
endRequest(theServletRequest);
|
||||
|
|
|
@ -850,7 +850,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc
|
|||
|
||||
@Override
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void storeNewCodeSystemVersion(CodeSystem theCodeSystemResource, TermCodeSystemVersion theCodeSystemVersion, RequestDetails theRequestDetails, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) {
|
||||
public IIdType storeNewCodeSystemVersion(CodeSystem theCodeSystemResource, TermCodeSystemVersion theCodeSystemVersion, RequestDetails theRequestDetails, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) {
|
||||
Validate.notBlank(theCodeSystemResource.getUrl(), "theCodeSystemResource must have a URL");
|
||||
|
||||
IIdType csId = createOrUpdateCodeSystem(theCodeSystemResource);
|
||||
|
@ -865,6 +865,8 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc
|
|||
|
||||
myDeferredConceptMaps.addAll(theConceptMaps);
|
||||
myDeferredValueSets.addAll(theValueSets);
|
||||
|
||||
return csId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -874,7 +876,7 @@ public abstract class BaseHapiTerminologySvcImpl implements IHapiTerminologySvc
|
|||
}
|
||||
|
||||
private ArrayList<VersionIndependentConcept> toVersionIndependentConcepts(String theSystem, Set<TermConcept> codes) {
|
||||
ArrayList<VersionIndependentConcept> retVal = new ArrayList<VersionIndependentConcept>(codes.size());
|
||||
ArrayList<VersionIndependentConcept> retVal = new ArrayList<>(codes.size());
|
||||
for (TermConcept next : codes) {
|
||||
retVal.add(new VersionIndependentConcept(theSystem, next.getCode()));
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ package ca.uhn.fhir.jpa.term;
|
|||
* 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.
|
||||
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.term;
|
|||
*/
|
||||
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
@ -45,15 +46,21 @@ public interface IHapiTerminologyLoaderSvc {
|
|||
|
||||
class UploadStatistics {
|
||||
private final int myConceptCount;
|
||||
private final IIdType myTarget;
|
||||
|
||||
public UploadStatistics(int theConceptCount) {
|
||||
public UploadStatistics(int theConceptCount, IIdType theTarget) {
|
||||
myConceptCount = theConceptCount;
|
||||
myTarget = theTarget;
|
||||
}
|
||||
|
||||
public int getConceptCount() {
|
||||
return myConceptCount;
|
||||
}
|
||||
|
||||
public IIdType getTarget() {
|
||||
return myTarget;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystem;
|
|||
import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
|
||||
import ca.uhn.fhir.jpa.entity.TermConcept;
|
||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -18,9 +19,9 @@ import java.util.Set;
|
|||
* 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.
|
||||
|
@ -45,10 +46,14 @@ public interface IHapiTerminologySvc {
|
|||
|
||||
List<VersionIndependentConcept> findCodesAbove(String theSystem, String theCode);
|
||||
|
||||
List<VersionIndependentConcept> findCodesAboveUsingBuiltInSystems(String theSystem, String theCode);
|
||||
|
||||
Set<TermConcept> findCodesBelow(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersionPid, String theCode);
|
||||
|
||||
List<VersionIndependentConcept> findCodesBelow(String theSystem, String theCode);
|
||||
|
||||
List<VersionIndependentConcept> findCodesBelowUsingBuiltInSystems(String theSystem, String theCode);
|
||||
|
||||
void saveDeferred();
|
||||
|
||||
/**
|
||||
|
@ -59,12 +64,11 @@ public interface IHapiTerminologySvc {
|
|||
|
||||
void storeNewCodeSystemVersion(Long theCodeSystemResourcePid, String theSystemUri, String theSystemName, TermCodeSystemVersion theCodeSytemVersion);
|
||||
|
||||
/**
|
||||
* @return Returns the ID of the created/updated code system
|
||||
*/
|
||||
IIdType storeNewCodeSystemVersion(org.hl7.fhir.r4.model.CodeSystem theCodeSystemResource, TermCodeSystemVersion theCodeSystemVersion, RequestDetails theRequestDetails, List<org.hl7.fhir.r4.model.ValueSet> theValueSets, List<org.hl7.fhir.r4.model.ConceptMap> theConceptMaps);
|
||||
|
||||
boolean supportsSystem(String theCodeSystem);
|
||||
|
||||
List<VersionIndependentConcept> findCodesAboveUsingBuiltInSystems(String theSystem, String theCode);
|
||||
|
||||
List<VersionIndependentConcept> findCodesBelowUsingBuiltInSystems(String theSystem, String theCode);
|
||||
|
||||
void storeNewCodeSystemVersion(org.hl7.fhir.r4.model.CodeSystem theCodeSystemResource, TermCodeSystemVersion theCodeSystemVersion, RequestDetails theRequestDetails, List<org.hl7.fhir.r4.model.ValueSet> theValueSets, List<org.hl7.fhir.r4.model.ConceptMap> theConceptMaps);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.commons.io.input.BOMInputStream;
|
|||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.CodeSystem;
|
||||
import org.hl7.fhir.r4.model.ConceptMap;
|
||||
import org.hl7.fhir.r4.model.ValueSet;
|
||||
|
@ -319,9 +320,9 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc {
|
|||
int conceptCount = code2concept.size();
|
||||
ourLog.info("Have {} total concepts, {} root concepts, {} ValueSets", conceptCount, rootConceptCount, valueSetCount);
|
||||
|
||||
storeCodeSystem(theRequestDetails, codeSystemVersion, loincCs, valueSets, conceptMaps);
|
||||
IIdType target = storeCodeSystem(theRequestDetails, codeSystemVersion, loincCs, valueSets, conceptMaps);
|
||||
|
||||
return new UploadStatistics(conceptCount);
|
||||
return new UploadStatistics(conceptCount, target);
|
||||
}
|
||||
|
||||
private UploadStatistics processSnomedCtFiles(LoadedFileDescriptors theDescriptors, RequestDetails theRequestDetails) {
|
||||
|
@ -367,9 +368,9 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc {
|
|||
cs.setUrl(SCT_URI);
|
||||
cs.setName("SNOMED CT");
|
||||
cs.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT);
|
||||
storeCodeSystem(theRequestDetails, codeSystemVersion, cs, null, null);
|
||||
IIdType target = storeCodeSystem(theRequestDetails, codeSystemVersion, cs, null, null);
|
||||
|
||||
return new UploadStatistics(code2concept.size());
|
||||
return new UploadStatistics(code2concept.size(), target);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -382,19 +383,22 @@ public class TerminologyLoaderSvcImpl implements IHapiTerminologyLoaderSvc {
|
|||
myTermSvc = theTermSvc;
|
||||
}
|
||||
|
||||
private void storeCodeSystem(RequestDetails theRequestDetails, final TermCodeSystemVersion theCodeSystemVersion, CodeSystem theCodeSystem, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) {
|
||||
private IIdType storeCodeSystem(RequestDetails theRequestDetails, final TermCodeSystemVersion theCodeSystemVersion, CodeSystem theCodeSystem, List<ValueSet> theValueSets, List<ConceptMap> theConceptMaps) {
|
||||
Validate.isTrue(theCodeSystem.getContent() == CodeSystem.CodeSystemContentMode.NOTPRESENT);
|
||||
|
||||
List<ValueSet> valueSets = ObjectUtils.defaultIfNull(theValueSets, Collections.emptyList());
|
||||
List<ConceptMap> conceptMaps = ObjectUtils.defaultIfNull(theConceptMaps, Collections.emptyList());
|
||||
|
||||
IIdType retVal;
|
||||
myTermSvc.setProcessDeferred(false);
|
||||
if (myTermSvcDstu3 != null) {
|
||||
myTermSvcDstu3.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps);
|
||||
retVal = myTermSvcDstu3.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps);
|
||||
} else {
|
||||
myTermSvcR4.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps);
|
||||
retVal = myTermSvcR4.storeNewCodeSystemVersion(theCodeSystem, theCodeSystemVersion, theRequestDetails, valueSets, conceptMaps);
|
||||
}
|
||||
myTermSvc.setProcessDeferred(true);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.util.zip.ZipEntry;
|
|||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.matchesPattern;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Test {
|
||||
|
@ -90,6 +91,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes
|
|||
ourLog.info(resp);
|
||||
|
||||
assertThat(((IntegerType) respParam.getParameter().get(0).getValue()).getValue(), greaterThan(1));
|
||||
assertThat(((Reference) respParam.getParameter().get(1).getValue()).getReference(), matchesPattern("CodeSystem\\/[a-zA-Z0-9]+"));
|
||||
|
||||
/*
|
||||
* Try uploading a second time
|
||||
|
|
Loading…
Reference in New Issue