-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ALS-7810: Add data dictionary table to PFB output (#127)
- Loading branch information
Showing
10 changed files
with
191 additions
and
26 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...ssing/src/main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/dictionary/Concept.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package edu.harvard.hms.dbmi.avillach.hpds.processing.dictionary; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
import java.util.Map; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public record Concept(String conceptPath, String name, String display, String dataset, String description, Map<String, String> meta) { | ||
} |
37 changes: 37 additions & 0 deletions
37
...main/java/edu/harvard/hms/dbmi/avillach/hpds/processing/dictionary/DictionaryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package edu.harvard.hms.dbmi.avillach.hpds.processing.dictionary; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.core.ParameterizedTypeReference; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@ConditionalOnProperty("dictionary.host") | ||
public class DictionaryService { | ||
|
||
public static final ParameterizedTypeReference<List<Concept>> CONCEPT_LIST_TYPE_REFERENCE = new ParameterizedTypeReference<>() { | ||
}; | ||
private final String dictionaryHost; | ||
private final RestTemplate restTemplate; | ||
|
||
@Autowired | ||
public DictionaryService(@Value("${dictionary.host}") String dictionaryHostTemplate, @Value("${TARGET_STACK:}") String targetStack) { | ||
if (targetStack != null && !targetStack.isEmpty()) { | ||
this.dictionaryHost = dictionaryHostTemplate.replace("___TARGET_STACK___", targetStack); | ||
} else { | ||
this.dictionaryHost = dictionaryHostTemplate; | ||
} | ||
this.restTemplate = new RestTemplate(); | ||
} | ||
|
||
public List<Concept> getConcepts(List<String> conceptPaths) { | ||
return restTemplate.exchange(dictionaryHost + "/pic-sure-api-2/PICSURE/proxy/dictionary-api/concepts/detail", HttpMethod.POST, new HttpEntity<>(conceptPaths), CONCEPT_LIST_TYPE_REFERENCE).getBody(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...g/src/test/java/edu/harvard/hms/dbmi/avillach/hpds/processing/dictionary/ConceptTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.harvard.hms.dbmi.avillach.hpds.processing.dictionary; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class ConceptTest { | ||
|
||
@Test | ||
public void jsonSerialization() throws JsonProcessingException { | ||
Concept[] concepts = new Concept[]{new Concept("\\demographics\\age\\", "age", "AGE", null, "patient age", Map.of("drs_uri", "[\"a-drs.uri\", \"another-drs.uri\"]"))}; | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
String serialized = objectMapper.writeValueAsString(concepts); | ||
Concept[] deserialized = objectMapper.readValue(serialized, Concept[].class); | ||
|
||
assertEquals(List.of(concepts), List.of(deserialized)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.