Skip to content
Snippets Groups Projects
Commit 8ae96005 authored by kfilippopolitis's avatar kfilippopolitis Committed by ThanKarab
Browse files

Properly formatted the enumerations on the CommonDataElements.

parent 5d15d331
No related branches found
No related tags found
No related merge requests found
......@@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.net.ConnectException;
import java.util.*;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
......@@ -49,17 +47,14 @@ public class PathologiesAPI {
Logger logger = new Logger(activeUserService.getActiveUser().getUsername(), "(GET) /pathologies");
logger.LogUserAction("Loading pathologies ...");
Map<String, List<PathologyDTO.PathologyDatasetDTO>> datasetsPerPathology = getMIPEngineDatasetsPerPathology(logger);
System.out.println(datasetsPerPathology);
Map<String, List<PathologyDTO.EnumerationDTO>> datasetsPerPathology = getMIPEngineDatasetsPerPathology(logger);
Map<String, MIPEngineAttributesDTO> mipEnginePathologyAttributes = getMIPEnginePathologyAttributes(logger);
System.out.println(mipEnginePathologyAttributes);
List<PathologyDTO> pathologyDTOS = new ArrayList<>();
for (String pathology : mipEnginePathologyAttributes.keySet()) {
pathologyDTOS.add(new PathologyDTO(pathology, mipEnginePathologyAttributes.get(pathology), datasetsPerPathology.get(pathology)));
}
System.out.println(pathologyDTOS);
// If authentication is disabled return everything
if (!authenticationIsEnabled) {
......@@ -71,7 +66,7 @@ public class PathologiesAPI {
return ResponseEntity.ok().body(gson.toJson(ClaimUtils.getAuthorizedPathologies(logger, authentication, pathologyDTOS)));
}
public Map<String, List<PathologyDTO.PathologyDatasetDTO>> getMIPEngineDatasetsPerPathology(Logger logger) {
public Map<String, List<PathologyDTO.EnumerationDTO>> getMIPEngineDatasetsPerPathology(Logger logger) {
Map<String, Map<String, MetadataHierarchyDTO.CommonDataElement>> mipEngineCDEsMetadata;
// Get MIPEngine algorithms
try {
......@@ -87,15 +82,17 @@ public class PathologiesAPI {
return null;
}
Map<String, List<PathologyDTO.PathologyDatasetDTO>> datasetsPerPathology = new HashMap<>();
Map<String, List<PathologyDTO.EnumerationDTO>> datasetsPerPathology = new HashMap<>();
mipEngineCDEsMetadata.forEach( (pathology, cdePerDataset) -> {
List<PathologyDTO.PathologyDatasetDTO> pathologyDatasetDTOS = new ArrayList<>();
cdePerDataset.forEach((dataset, cde) -> pathologyDatasetDTOS.add(new PathologyDTO.PathologyDatasetDTO(dataset, cde.getLabel())));
List<PathologyDTO.EnumerationDTO> pathologyDatasetDTOS = new ArrayList<>();
Map datasetEnumerations = (Map) cdePerDataset.get("dataset").getEnumerations();
datasetEnumerations.forEach((code, label) -> pathologyDatasetDTOS.add(new PathologyDTO.EnumerationDTO((String) code, (String) label)));
datasetsPerPathology.put(pathology, pathologyDatasetDTOS);
});
return datasetsPerPathology;
}
......@@ -115,6 +112,14 @@ public class PathologiesAPI {
return null;
}
return mipEnginePathologyAttributes;
Map<String, MIPEngineAttributesDTO> mipEnginePathologyAttributesWithProperEnums = new HashMap<>();
for (Map.Entry<String, MIPEngineAttributesDTO> entry : mipEnginePathologyAttributes.entrySet()) {
String pathology = entry.getKey();
MIPEngineAttributesDTO attributes = entry.getValue();
attributes.updateAttributesWithProperEnums();
mipEnginePathologyAttributesWithProperEnums.put(pathology, attributes);
}
return mipEnginePathologyAttributesWithProperEnums;
}
}
package eu.hbp.mip.models.DTOs;
import com.google.gson.annotations.SerializedName;
import eu.hbp.mip.models.DTOs.MetadataHierarchyDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -17,4 +18,19 @@ public class MIPEngineAttributesDTO {
@SerializedName("tags")
private Object tags;
public void updateAttributesWithProperEnums(){
Map<String, List<MetadataHierarchyDTO>> updated_properties = new HashMap<>();
for (Map.Entry<String, List<MetadataHierarchyDTO>> entry : this.properties.entrySet()) {
String pathology = entry.getKey();
List<MetadataHierarchyDTO> hierarchyDTOS = entry.getValue();
List<MetadataHierarchyDTO> updatedHierarchyDTOS = new ArrayList<>();
for (MetadataHierarchyDTO hierarchyDTO : hierarchyDTOS) {
hierarchyDTO.updateGroupWithProperEnums();
updatedHierarchyDTOS.add(hierarchyDTO);
}
updated_properties.put(pathology,updatedHierarchyDTOS);
}
this.properties = updated_properties;
}
}
......@@ -4,9 +4,9 @@ import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Map;
@Data
@AllArgsConstructor
......@@ -19,15 +19,15 @@ public class MetadataHierarchyDTO {
private String code;
@SerializedName("groups")
private Object groups;
private List<MetadataHierarchyDTO> groups;
@SerializedName("label")
private String label;
@Data
@AllArgsConstructor
public static class CommonDataElement {
@SerializedName("isCategorical")
private Boolean isCategorical;
@SerializedName("is_categorical")
private Boolean is_categorical;
@SerializedName("code")
private String code;
......@@ -53,5 +53,46 @@ public class MetadataHierarchyDTO {
@SerializedName("methodology")
private String methodology;
@SerializedName("min")
private String min;
@SerializedName("max")
private String max;
private void updateEnumerations(){
if (this.enumerations != null){
Map old_enumeration = (Map) this.enumerations;
List<PathologyDTO.EnumerationDTO> enumerationDTOS = new ArrayList<>();
old_enumeration.forEach((cdeCode, cdeLabel) -> {
enumerationDTOS.add(new PathologyDTO.EnumerationDTO((String) cdeCode, (String) cdeLabel));
});
setEnumerations(enumerationDTOS);
}
}
}
public void updateVariableWithProperEnums(){
List<CommonDataElement> updated_variables = new ArrayList<>();
this.variables.forEach(commonDataElement -> {
commonDataElement.updateEnumerations();
updated_variables.add(commonDataElement);
});
setVariables(updated_variables);
}
public void updateGroupWithProperEnums(){
List<MetadataHierarchyDTO> updated_groups = new ArrayList<>();
for (MetadataHierarchyDTO hierarchyDTO : this.groups) {
if (hierarchyDTO.getVariables() != null) {
hierarchyDTO.updateVariableWithProperEnums();
}
if (hierarchyDTO.getGroups() != null) {
hierarchyDTO.updateGroupWithProperEnums();
}
updated_groups.add(hierarchyDTO);
}
this.groups = updated_groups;
}
}
......@@ -6,7 +6,6 @@ import lombok.Data;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@Data
@AllArgsConstructor
......@@ -26,14 +25,14 @@ public class PathologyDTO {
private MetadataHierarchyDTO metadataHierarchyDTO;
@SerializedName("datasets")
private List<PathologyDatasetDTO> datasets;
private List<EnumerationDTO> datasets;
public PathologyDTO(){
}
public PathologyDTO(String pathology, MIPEngineAttributesDTO mipEngineAttributesDTO, List<PathologyDatasetDTO> pathologyDatasetDTOS) {
public PathologyDTO(String pathology, MIPEngineAttributesDTO mipEngineAttributesDTO, List<EnumerationDTO> pathologyDatasetDTOS) {
MetadataHierarchyDTO metadataHierarchyDTO = mipEngineAttributesDTO.getProperties().get("cdes").get(0);
List<MetadataHierarchyDTO.CommonDataElement> variables = metadataHierarchyDTO.getVariables();
variables.stream().filter(cde -> cde.getCode().equals("dataset")).
......@@ -50,7 +49,7 @@ public class PathologyDTO {
@Data
@AllArgsConstructor
public static class PathologyDatasetDTO {
public static class EnumerationDTO {
@SerializedName("code")
private String code;
......
......@@ -68,8 +68,8 @@ public class ClaimUtils {
List<PathologyDTO> userPathologies = new ArrayList<>();
for (PathologyDTO curPathology : allPathologies) {
List<PathologyDTO.PathologyDatasetDTO> userPathologyDatasets = new ArrayList<>();
for (PathologyDTO.PathologyDatasetDTO dataset : curPathology.getDatasets()) {
List<PathologyDTO.EnumerationDTO> userPathologyDatasets = new ArrayList<>();
for (PathologyDTO.EnumerationDTO dataset : curPathology.getDatasets()) {
if (hasRoleAccess(authorities, ClaimUtils.getDatasetClaim(dataset.getCode()), logger)) {
logger.LogUserAction("Added dataset: " + dataset.getCode());
userPathologyDatasets.add(dataset);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment