Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modifications for "parameters" and "languages" #15

Open
wants to merge 7 commits into
base: fhir-tests
Choose a base branch
from
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
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.Extension;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand All @@ -16,6 +17,7 @@
import org.springframework.data.elasticsearch.annotations.*;

import java.util.Date;
import java.util.List;

import static org.snomed.snowstorm.fhir.config.FHIRConstants.*;

Expand All @@ -31,6 +33,9 @@ public class FHIRCodeSystemVersion {
@Field(type = FieldType.Keyword)
private String version;

@Field(type = FieldType.Keyword)
private String language;

@Field(type = FieldType.Date, format = DateFormat.date_time)
private Date date;

Expand All @@ -55,6 +60,9 @@ public class FHIRCodeSystemVersion {
@Field(type = FieldType.Keyword)
private String content;

@Field(type = FieldType.Nested)
private List<Extension> extensions;

@Transient
private String snomedBranch;

Expand Down Expand Up @@ -84,6 +92,7 @@ public FHIRCodeSystemVersion(CodeSystem codeSystem) {
version = codeSystem.getVersion();
date = codeSystem.getDate();
title = codeSystem.getTitle();
language = codeSystem.getLanguage();
if (title != null) {
title = title.replace(" Code System", "");
}
Expand All @@ -96,6 +105,7 @@ public FHIRCodeSystemVersion(CodeSystem codeSystem) {
compositional = codeSystem.getCompositional();
CodeSystem.CodeSystemContentMode codeSystemContent = codeSystem.getContent();
content = codeSystemContent != null ? codeSystemContent.toCode() : null;
extensions = codeSystem.getExtension();
}

public FHIRCodeSystemVersion(CodeSystemVersion snomedVersion) {
Expand Down Expand Up @@ -144,9 +154,13 @@ public FHIRCodeSystemVersion(org.snomed.snowstorm.core.data.domain.CodeSystem sn

public CodeSystem toHapiCodeSystem() {
CodeSystem codeSystem = new CodeSystem();
codeSystem.setExtension(extensions);
codeSystem.setId(id);
codeSystem.setUrl(url);
codeSystem.setVersion(version);
if(!"0".equals(version)) {
codeSystem.setVersion(version);
}
codeSystem.setLanguage(language);
codeSystem.setDate(date);
codeSystem.setName(name);
codeSystem.setTitle(title);
Expand Down Expand Up @@ -181,7 +195,11 @@ public boolean isVersionMatch(String requestedVersion) {
}

public String getCanonical() {
return url + "|" + version;
if ("0".equals(version)){
return url;
} else {
return url + "|" + version;
}
}

public String getId() {
Expand Down Expand Up @@ -248,6 +266,14 @@ public void setPublisher(String publisher) {
this.publisher = publisher;
}

public List<Extension> getExtensions() {
return extensions;
}

public void setExtensions(List<Extension> extensions) {
this.extensions = extensions;
}

public String getHierarchyMeaning() {
return hierarchyMeaning;
}
Expand Down Expand Up @@ -291,4 +317,12 @@ public CodeSystemVersion getSnomedCodeSystemVersion() {
public String toString() {
return getId();
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}
}
53 changes: 50 additions & 3 deletions src/main/java/org/snomed/snowstorm/fhir/domain/FHIRConcept.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ca.uhn.fhir.jpa.entity.TermConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.entity.TermConceptProperty;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.*;
import org.snomed.snowstorm.core.data.domain.ConceptMini;
import org.snomed.snowstorm.core.data.domain.Description;
import org.snomed.snowstorm.core.pojo.LanguageDialect;
Expand All @@ -24,6 +24,8 @@
@Document(indexName = "#{@indexNameProvider.indexName('fhir-concept')}", createIndex = false)
public class FHIRConcept implements FHIRGraphNode {

public static final String EXTENSION_MARKER = "://";

public interface Fields {

String CODE_SYSTEM_VERSION = "codeSystemVersion";
Expand All @@ -33,6 +35,7 @@ public interface Fields {
String PARENTS = "parents";
String ANCESTORS = "ancestors";
String PROPERTIES = "properties";
String EXTENSIONS = "extensions";
}
@Id
// Internal ID
Expand Down Expand Up @@ -62,6 +65,8 @@ public interface Fields {

private Map<String, List<FHIRProperty>> properties;

private Map<String, List<FHIRProperty>> extensions;

public FHIRConcept() {
active = true;
}
Expand All @@ -80,11 +85,17 @@ public FHIRConcept(TermConcept termConcept, FHIRCodeSystemVersion codeSystemVers
}

properties = new HashMap<>();
for (TermConceptProperty property : termConcept.getProperties()) {
for (TermConceptProperty property : termConcept.getProperties().stream().filter(p -> !p.getKey().contains(EXTENSION_MARKER)).toList()) {
properties.computeIfAbsent(property.getKey(), (i) -> new ArrayList<>())
.add(new FHIRProperty(property));
}

extensions = new HashMap<>();
for (TermConceptProperty extension : termConcept.getProperties().stream().filter(p -> p.getKey().contains(EXTENSION_MARKER)).toList()) {
extensions.computeIfAbsent(extension.getKey(), (i) -> new ArrayList<>())
.add(new FHIRProperty(extension));
}

parents = new HashSet<>();
for (TermConceptParentChildLink parent : termConcept.getParents()) {
parents.add(parent.getParent().getCode());
Expand All @@ -109,9 +120,37 @@ public FHIRConcept(CodeSystem.ConceptDefinitionComponent definitionConcept, FHIR
Optional.ofNullable(definitionConcept.getDefinition()).ifPresent(x -> properties.put("definition",Collections.singletonList(new FHIRProperty("definition",null,x,FHIRProperty.STRING))));
definitionConcept.getProperty().stream().filter(x-> x.getCode().equals("status") && x.getValueCodeType().getCode().equals("retired") ).findFirst().ifPresentOrElse(x -> active= false, ()->active =true);
properties.put("inactive",Collections.singletonList(new FHIRProperty("inactive",null,Boolean.toString(!isActive()),FHIRProperty.BOOLEAN)));
extensions = new HashMap<>();
definitionConcept.getExtension().forEach(
e ->{
Optional.ofNullable(extensions.get(e.getUrl())).ifPresentOrElse(list ->{
list.add(new FHIRProperty(e.getUrl(), null,e.getValue().primitiveValue(), FHIRProperty.typeToFHIRPropertyType(e.getValue())));

}, ()->{
List<FHIRProperty> list = new ArrayList<>();
list.add(new FHIRProperty(e.getUrl(), null,e.getValue().primitiveValue(), FHIRProperty.typeToFHIRPropertyType(e.getValue())));
extensions.put(e.getUrl(), list);
});

}
);
parents = new HashSet<>();
for (CodeSystem.ConceptPropertyComponent propertyComponent : definitionConcept.getProperty()) {
properties.computeIfAbsent(propertyComponent.getCode(), k -> new ArrayList<>()).add(new FHIRProperty(propertyComponent));
if (properties.get(propertyComponent.getCode())==null && !propertyComponent.getCode().contains(EXTENSION_MARKER)){
properties.put(propertyComponent.getCode(),new ArrayList<>());
}
try{
if(!propertyComponent.getCode().contains(EXTENSION_MARKER)){
properties.get(propertyComponent.getCode()).add(new FHIRProperty(propertyComponent));
}
} catch( UnsupportedOperationException e){
List<FHIRProperty> unmodifiableList = properties.get(propertyComponent.getCode());
List<FHIRProperty> modifiableList = new ArrayList<>();
modifiableList.addAll(unmodifiableList);
properties.put(propertyComponent.getCode(), modifiableList);
properties.get(propertyComponent.getCode()).add(new FHIRProperty(propertyComponent));
}

if (propertyComponent.getCode().equals("parent") || propertyComponent.getCode().equals("subsumedBy")) {
parents.add(propertyComponent.hasValueCoding() ? propertyComponent.getValueCoding().getCode() : propertyComponent.getValue().toString());
}
Expand Down Expand Up @@ -228,4 +267,12 @@ public Map<String, List<FHIRProperty>> getProperties() {
public void setProperties(Map<String, List<FHIRProperty>> properties) {
this.properties = properties;
}

public Map<String, List<FHIRProperty>> getExtensions() {
return extensions;
}

public void setExtensions(Map<String, List<FHIRProperty>> extensions) {
this.extensions = extensions;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.snomed.snowstorm.fhir.domain;

import ca.uhn.fhir.jpa.entity.TermConceptDesignation;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ValueSet;
import org.snomed.snowstorm.core.data.domain.Description;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static org.snomed.snowstorm.fhir.config.FHIRConstants.SNOMED_URI;

public class FHIRDesignation {
Expand All @@ -13,6 +20,10 @@ public class FHIRDesignation {
private String use;
private String value;



private List<FHIRExtension> extensions;

public FHIRDesignation() {
}

Expand Down Expand Up @@ -43,14 +54,36 @@ public FHIRDesignation(CodeSystem.ConceptDefinitionDesignationComponent designat
language = designation.getLanguage();
value = designation.getValue();
setUse(designation.getUse());
designation.getExtension().forEach( ext -> {
if (extensions == null){
extensions = new ArrayList<>();
}
extensions.add(new FHIRExtension(ext));
});
}

public FHIRDesignation(ValueSet.ConceptReferenceDesignationComponent designation) {
language = designation.getLanguage();
value = designation.getValue();
setUse(designation.getUse());
designation.getExtension().forEach( ext -> {
if (extensions == null){
extensions = new ArrayList<>();
}
extensions.add(new FHIRExtension(ext));
});
}

public void setUse(Coding useCoding) {
setUse(useCoding.getSystem(), useCoding.getCode());
}

public void setUse(String useSystem, String useCode) {
use = useSystem + "|" + useCode;
if(useSystem == null && useCode == null){
use = null;
} else {
use = useSystem + "|" + useCode;
}
}

public Coding getUseCoding() {
Expand All @@ -65,6 +98,17 @@ public Coding getUseCoding() {
return null;
}

public ValueSet.ConceptReferenceDesignationComponent getHapi() {
ValueSet.ConceptReferenceDesignationComponent hapiConceptReferenceDesignationComponent = new ValueSet.ConceptReferenceDesignationComponent();
hapiConceptReferenceDesignationComponent.setLanguage(language);
hapiConceptReferenceDesignationComponent.setValue(value);
if (StringUtils.isNotEmpty(use)) {
hapiConceptReferenceDesignationComponent.setUse(this.getUseCoding());
}
hapiConceptReferenceDesignationComponent.setExtension(Optional.ofNullable(extensions).orElse(Collections.emptyList()).stream().map(d->d.getHapi()).toList());
return hapiConceptReferenceDesignationComponent;
}

private static Coding addKnownDisplays(Coding coding) {
if (coding != null) {
if (SNOMED_URI.equals(coding.getSystem())) {
Expand Down Expand Up @@ -107,4 +151,12 @@ public String getValue() {
public void setValue(String value) {
this.value = value;
}

public List<FHIRExtension> getExtensions() {
return extensions;
}

public void setExtensions(List<FHIRExtension> extensions) {
this.extensions = extensions;
}
}
Loading