Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#280 create concept map
Browse files Browse the repository at this point in the history
  • Loading branch information
harpatel1 committed Mar 12, 2021
1 parent ea6db50 commit 38a06fe
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 21 deletions.

Large diffs are not rendered by default.

Expand Up @@ -46,7 +46,7 @@ public class ValueSetConverter extends BaseConverter {
"on c1.mnemonic = c3.mnemonic and c1.created_at = c3.created_at";

private static final Map<String,Object> collReferenceParamMap = new HashMap<>();
private static final String insertCollectionsReferences = "insert into collections_references (collection_id,collectionreference_id) values (?,?)";
private static final String insertCollectionsReferences = "insert into collections_references (collection_id,collectionreference_id) values (?,?) on conflict do nothing";
private static final String insertCollectionsConcepts = "insert into collections_concepts (collection_id,concept_id) values (?,?) on conflict do nothing";

public ValueSetConverter(SourceRepository sourceRepository, ConceptRepository conceptRepository, OclFhirUtil oclFhirUtil,
Expand Down
Expand Up @@ -5,6 +5,7 @@
import ca.uhn.fhir.rest.server.interceptor.auth.IAuthRule;
import ca.uhn.fhir.rest.server.interceptor.auth.RuleBuilder;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.ConceptMap;
import org.hl7.fhir.r4.model.ValueSet;
import org.springframework.stereotype.Component;

Expand All @@ -31,7 +32,9 @@ private RuleBuilder getDefaultRuleBuilder() {
.allow().write().resourcesOfType(CodeSystem.class).withAnyId().andThen()
.allow().delete().resourcesOfType(CodeSystem.class).withAnyId().andThen()
.allow().write().resourcesOfType(ValueSet.class).withAnyId().andThen()
//.allow().write().resourcesOfType(ConceptMap.class).withAnyId().andThen()
.allow().delete().resourcesOfType(ValueSet.class).withAnyId().andThen()
.allow().write().resourcesOfType(ConceptMap.class).withAnyId().andThen()
.allow().delete().resourcesOfType(ConceptMap.class).withAnyId().andThen()
.allow().operation().withAnyName().atAnyLevel().andAllowAllResponses();
return ruleBuilder;
}
Expand Down
Expand Up @@ -27,6 +27,9 @@ public class Mapping extends BaseOclEntity implements Serializable {
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

@Column
private String mnemonic;

@Column
private String comment;

Expand Down Expand Up @@ -146,6 +149,14 @@ public void setId(Long id) {
this.id = id;
}

public String getMnemonic() {
return this.mnemonic;
}

public void setMnemonic(String mnemonic) {
this.mnemonic = mnemonic;
}

public String getComment() {
return this.comment;
}
Expand Down
Expand Up @@ -52,25 +52,7 @@ protected List<Source> getSources(List<String> access) {
}

protected List<Source> getSourceByUrl(StringType url, StringType version, List<String> access) {
List<Source> sources = new ArrayList<>();
if (isVersionAll(version)) {
// get all versions
sources.addAll(sourceRepository.findByCanonicalUrlAndPublicAccessIn(url.getValue(), access).stream()
.sorted(Comparator.comparing(Source::getVersion).reversed()).collect(Collectors.toList()));
} else {
final Source source;
if (!isValid(version)) {
// get most recent released version
source = oclFhirUtil.getMostRecentReleasedSourceByUrl(url, access);
} else {
// get a given version
source = sourceRepository.findFirstByCanonicalUrlAndVersionAndPublicAccessIn(url.getValue(), version.getValue(), access);
}
if (source != null) sources.add(source);
}
if (sources.isEmpty())
throw new ResourceNotFoundException(notFound(CodeSystem.class, url, version));
return sources;
return oclFhirUtil.getSourceByUrl(url, version, access);
}

protected List<Source> getSourceByOwner(StringType owner, List<String> access) {
Expand Down
@@ -1,6 +1,7 @@
package org.openconceptlab.fhir.provider;

import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
Expand All @@ -18,6 +19,7 @@
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;
import java.util.Collections;
import java.util.List;

import static org.openconceptlab.fhir.util.OclFhirConstants.*;
Expand All @@ -43,6 +45,23 @@ public Class<? extends IBaseResource> getResourceType() {
return ConceptMap.class;
}

@Create
@Transactional
public MethodOutcome createConceptMap(@ResourceParam ConceptMap conceptMap, RequestDetails requestDetails) {
if (conceptMap == null) {
throw new InvalidRequestException("The ConceptMap can not be empty");
}
String accessionId = getAccessionIdentifier(Collections.singletonList(conceptMap.getIdentifier()));
if (!isValid(accessionId)) {
throw new InvalidRequestException("The ConceptMap.identifier is empty or identifier of type ACSN is empty.");
}
if (!isValid(conceptMap.getUrl())) {
throw new InvalidRequestException("The ConceptMap.url can not be empty. Please provide canonical url.");
}
conceptMapConverter.createConceptMap(conceptMap, accessionId, requestDetails.getHeader(AUTHORIZATION));
return new MethodOutcome();
}

/**
* Returns all public {@link ConceptMap}.
*
Expand Down
@@ -0,0 +1,6 @@
package org.openconceptlab.fhir.repository;

public interface ConceptIdMnemonic {
Long getId();
String getMnemonic();
}
Expand Up @@ -28,6 +28,15 @@ public interface ConceptRepository extends BaseOclRepository<Concept>{
") order by c2.mnemonic asc")
Page<Concept> findConcepts(@Param("sourceId") Long sourceId, Pageable pageable);

@Query(nativeQuery = true, value = "select c2.id, c2.mnemonic from concepts c2 where c2.id in (" +
"select concept_id from (\n" +
"select max(cs.concept_id) as concept_id , c1.mnemonic from concepts_sources cs \n" +
"inner join concepts c1 on c1.id = cs.concept_id \n" +
"where cs.source_id = :sourceId\n" +
"group by c1.mnemonic) as val \n" +
") order by c2.mnemonic asc")
List<ConceptIdMnemonic> findConceptIds(@Param("sourceId") Long sourceId);

@Query(nativeQuery = true, value = "select count(*) from (select max(cs.concept_id) as concept_id , c1.mnemonic from concepts_sources cs \n" +
"inner join concepts c1 on c1.id = cs.concept_id \n" +
"where cs.source_id = :sourceId\n" +
Expand Down
Expand Up @@ -122,6 +122,7 @@ public final class OclFhirConstants {
public static final String CONCEPTS = "concepts";
public static final String COLLECTIONS = "collections";
public static final String SOURCES = "sources";
public static final String MAPPINGS = "mappings";
public static final String EXPRESSION = "expression";
public static final String LAST_RESOLVED_AT = "last_resolved_at";
public static final boolean True = true;
Expand All @@ -131,4 +132,17 @@ public final class OclFhirConstants {
public static final String TRANSLATE = "$translate";

public static final String OWNER_URL = "ownerUrl";
public static final String FROM_SOURCE_URL = "from_source_url";
public static final String FROM_SOURCE_VERSION = "from_source_version";
public static final String FROM_SOURCE_ID = "from_source_id";
public static final String FROM_CONCEPT_CODE = "from_concept_code";
public static final String FROM_CONCEPT_NAME = "from_concept_name";
public static final String FROM_CONCEPT_ID = "from_concept_id";
public static final String TO_SOURCE_URL = "to_source_url";
public static final String TO_SOURCE_VERSION = "to_source_version";
public static final String TO_SOURCE_ID = "to_source_id";
public static final String TO_CONCEPT_CODE = "to_concept_code";
public static final String TO_CONCEPT_NAME = "to_concept_name";
public static final String TO_CONCEPT_ID = "to_concept_id";
public static final String MAP_TYPE = "map_type";
}

0 comments on commit 38a06fe

Please sign in to comment.