mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-06 11:29:30 +00:00
terminology utility improvements
This commit is contained in:
parent
bdb5a46621
commit
fe2b06031a
@ -53,10 +53,13 @@ import org.hl7.fhir.r5.model.CodeType;
|
|||||||
import org.hl7.fhir.r5.model.Coding;
|
import org.hl7.fhir.r5.model.Coding;
|
||||||
import org.hl7.fhir.r5.model.DataType;
|
import org.hl7.fhir.r5.model.DataType;
|
||||||
import org.hl7.fhir.r5.model.DateTimeType;
|
import org.hl7.fhir.r5.model.DateTimeType;
|
||||||
|
import org.hl7.fhir.r5.model.DecimalType;
|
||||||
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
|
import org.hl7.fhir.r5.model.Enumerations.PublicationStatus;
|
||||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptDefinitionComponentSorter;
|
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptDefinitionComponentSorter;
|
||||||
import org.hl7.fhir.r5.model.Identifier;
|
import org.hl7.fhir.r5.model.Identifier;
|
||||||
|
import org.hl7.fhir.r5.model.IntegerType;
|
||||||
import org.hl7.fhir.r5.model.Meta;
|
import org.hl7.fhir.r5.model.Meta;
|
||||||
|
import org.hl7.fhir.r5.model.StringType;
|
||||||
import org.hl7.fhir.r5.model.UriType;
|
import org.hl7.fhir.r5.model.UriType;
|
||||||
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
||||||
import org.hl7.fhir.utilities.StandardsStatus;
|
import org.hl7.fhir.utilities.StandardsStatus;
|
||||||
@ -68,7 +71,7 @@ public class CodeSystemUtilities {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(ConceptDefinitionComponent o1, ConceptDefinitionComponent o2) {
|
public int compare(ConceptDefinitionComponent o1, ConceptDefinitionComponent o2) {
|
||||||
return o1.getCode().compareTo(o2.getCode());
|
return o1.getCode().compareToIgnoreCase(o2.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -177,6 +180,58 @@ public class CodeSystemUtilities {
|
|||||||
concept.addProperty().setCode("notSelectable").setValue(new BooleanType(true));
|
concept.addProperty().setCode("notSelectable").setValue(new BooleanType(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setProperty(CodeSystem cs, ConceptDefinitionComponent concept, String code, DataType value) throws FHIRFormatError {
|
||||||
|
defineProperty(cs, code, propertyTypeForValue(value));
|
||||||
|
ConceptPropertyComponent p = getProperty(concept, code);
|
||||||
|
if (p != null)
|
||||||
|
p.setValue(value);
|
||||||
|
else
|
||||||
|
concept.addProperty().setCode(code).setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static PropertyType propertyTypeForValue(DataType value) {
|
||||||
|
if (value instanceof BooleanType) {
|
||||||
|
return PropertyType.BOOLEAN;
|
||||||
|
}
|
||||||
|
if (value instanceof CodeType) {
|
||||||
|
return PropertyType.CODE;
|
||||||
|
}
|
||||||
|
if (value instanceof Coding) {
|
||||||
|
return PropertyType.CODING;
|
||||||
|
}
|
||||||
|
if (value instanceof DateTimeType) {
|
||||||
|
return PropertyType.DATETIME;
|
||||||
|
}
|
||||||
|
if (value instanceof DecimalType) {
|
||||||
|
return PropertyType.DECIMAL;
|
||||||
|
}
|
||||||
|
if (value instanceof IntegerType) {
|
||||||
|
return PropertyType.INTEGER;
|
||||||
|
}
|
||||||
|
if (value instanceof StringType) {
|
||||||
|
return PropertyType.STRING;
|
||||||
|
}
|
||||||
|
throw new Error("Unknown property type "+value.getClass().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void defineProperty(CodeSystem cs, String code, PropertyType pt) {
|
||||||
|
String url = "http://hl7.org/fhir/concept-properties#"+code;
|
||||||
|
for (PropertyComponent p : cs.getProperty()) {
|
||||||
|
if (p.getCode().equals(code)) {
|
||||||
|
if (!p.getUri().equals(url)) {
|
||||||
|
throw new Error("URI mismatch for code "+code+" url = "+p.getUri()+" vs "+url);
|
||||||
|
}
|
||||||
|
if (!p.getType().equals(pt)) {
|
||||||
|
throw new Error("Type mismatch for code "+code+" type = "+p.getType()+" vs "+pt);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cs.addProperty().setCode(code).setUri(url).setType(pt).setUri(url);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void defineNotSelectableProperty(CodeSystem cs) {
|
public static void defineNotSelectableProperty(CodeSystem cs) {
|
||||||
defineCodeSystemProperty(cs, "notSelectable", "Indicates that the code is abstract - only intended to be used as a selector for other concepts", PropertyType.BOOLEAN);
|
defineCodeSystemProperty(cs, "notSelectable", "Indicates that the code is abstract - only intended to be used as a selector for other concepts", PropertyType.BOOLEAN);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.hl7.fhir.r5.terminologies;
|
package org.hl7.fhir.r5.terminologies;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -47,9 +49,11 @@ import org.hl7.fhir.r5.model.UriType;
|
|||||||
import org.hl7.fhir.r5.model.ValueSet;
|
import org.hl7.fhir.r5.model.ValueSet;
|
||||||
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent;
|
||||||
import org.hl7.fhir.r5.model.CodeType;
|
import org.hl7.fhir.r5.model.CodeType;
|
||||||
|
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
|
||||||
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
|
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
|
||||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
|
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
|
||||||
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionPropertyComponent;
|
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionPropertyComponent;
|
||||||
|
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptDefinitionComponentSorter;
|
||||||
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptStatus;
|
import org.hl7.fhir.r5.terminologies.CodeSystemUtilities.ConceptStatus;
|
||||||
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
import org.hl7.fhir.r5.utils.ToolingExtensions;
|
||||||
import org.hl7.fhir.utilities.StandardsStatus;
|
import org.hl7.fhir.utilities.StandardsStatus;
|
||||||
@ -255,4 +259,18 @@ public class ValueSetUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class ConceptReferenceComponentSorter implements Comparator<ConceptReferenceComponent> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(ConceptReferenceComponent o1, ConceptReferenceComponent o2) {
|
||||||
|
return o1.getCode().compareToIgnoreCase(o2.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void sortInclude(ConceptSetComponent inc) {
|
||||||
|
Collections.sort(inc.getConcept(), new ConceptReferenceComponentSorter());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user