Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
type: fix
issue: 7401
jira: SMILE-11256
title: "Previously, `smileutil upload-terminology` failed to load and save multiple concept properties that
used the same property code for a single `CodeSystem.concept`. This is now fixed."


Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import ca.uhn.fhir.jpa.entity.TermConceptProperty;
import ca.uhn.fhir.jpa.entity.TermConceptPropertyTypeEnum;
import ca.uhn.fhir.jpa.term.IZipContentsHandlerCsv;
import ca.uhn.fhir.jpa.term.TermLoaderSvcImpl;
import ca.uhn.fhir.util.ValidateUtil;
import org.apache.commons.csv.CSVRecord;

import java.util.ArrayList;
Expand All @@ -50,18 +48,14 @@ public void accept(CSVRecord theRecord) {
String code = trim(theRecord.get(CODE));
String key = trim(theRecord.get(KEY));

if (isNotBlank(code) && isNotBlank(KEY)) {
if (isNotBlank(code) && isNotBlank(key)) {
String value = trim(theRecord.get(VALUE));
String type = trim(theRecord.get(TYPE));

List<TermConceptProperty> conceptProperties = myCode2Properties.get(code);
if (conceptProperties == null) conceptProperties = new ArrayList<>();

TermConceptProperty conceptProperty =
TermLoaderSvcImpl.getOrCreateConceptProperty(myCode2Properties, code, key);
ValidateUtil.isNotNullOrThrowUnprocessableEntity(
conceptProperty, "Concept property %s not found in file", conceptProperty);

TermConceptProperty conceptProperty = new TermConceptProperty();
conceptProperty.setKey(key);
conceptProperty.setValue(value);
// TODO: check this for different types, other types should be added once TermConceptPropertyTypeEnum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -318,6 +319,52 @@ public void testApplyDeltaAdd_UsingCsv_withPropertiesCsv() throws IOException {
});
}

@Test
public void testApplyDeltaAdd_duplicateConceptPropertyKeys_allPropertiesSaved() throws IOException {
String inputParamJson = loadResource("/custom_term/codeSystem-duplicatePropertyKeys.json");
Parameters inputParameters = myFhirContext.newJsonParser().parseResource(Parameters.class, inputParamJson);

LoggingInterceptor interceptor = new LoggingInterceptor(true);
myClient.registerInterceptor(interceptor);
Parameters outcome = myClient
.operation()
.onType(CodeSystem.class)
.named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD)
.withParameters(inputParameters)
.prettyPrint()
.execute();
myClient.unregisterInterceptor(interceptor);

String encoded = myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome);
ourLog.info(encoded);
assertThat(encoded).containsSubsequence(
"\"name\": \"conceptCount\"",
"\"valueInteger\": 1",
"\"name\": \"target\"",
"\"reference\": \"CodeSystem/"
);
runInTransaction(() -> {
TermCodeSystem cs = myTermCodeSystemDao.findByCodeSystemUri("http://www.nlm.nih.gov/research/umls/rxnorm_resource");
TermCodeSystemVersion version = cs.getCurrentVersion();
Optional<TermConcept> optional = myTermConceptDao.findByCodeSystemAndCode(version.getPid(), "748856");
assertThat(optional).isPresent();

TermConcept concept = optional.get();
Collection<TermConceptProperty> properties = concept.getProperties();

properties.forEach(prop -> ourLog.info("Property: {} = {}", prop.getKey(), prop.getValue()));
assertThat(properties).hasSize(3);

// Check that a property with key "STY" appears twice
List<String> valuesForSTY = properties.stream()
.filter(p -> "STY".equalsIgnoreCase(p.getKey()))
.map(TermConceptProperty::getValue)
.toList();
assertThat(valuesForSTY).hasSize(2);
assertThat(valuesForSTY).containsExactlyInAnyOrder("STN:A1.3.1.1", "STY:Drug Delivery Device");
});
}

@Test
public void testApplyDeltaAdd_UsingCodeSystem() {
CodeSystem codeSystem = new CodeSystem();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"resourceType": "Parameters",
"parameter": [
{
"name": "system",
"valueUri": "http://www.nlm.nih.gov/research/umls/rxnorm_resource"
},
{
"name": "codeSystem",
"resource": {
"resourceType": "CodeSystem",
"concept": [
{
"code": "748856",
"display": "{24 (drospirenone 3 MG / ethinyl estradiol 0.02 MG Oral Tablet) / 4 (inert ingredients 1 MG Oral Tablet) } Pack [Yaz 28 Day]",
"property": [
{
"code": "STY",
"valueString": "STN:A1.3.1.1"
},
{
"code": "STY",
"valueString": "STY:Drug Delivery Device"
},
{
"code": "TTY",
"valueString": "BPCK"
}
]
}
]
}
}
]
}
Loading