Skip to content
Snippets Groups Projects
Unverified Commit 386f9080 authored by K.Filippopolitis's avatar K.Filippopolitis Committed by GitHub
Browse files

Merge pull request #54 from HBPMedical/fix_on_pathologies_API

Fix on pathologies
parents 7723c773 e6644d43
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ package eu.hbp.mip.controllers; ...@@ -3,7 +3,7 @@ package eu.hbp.mip.controllers;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import eu.hbp.mip.models.DTOs.MIPEngineAttributesDTO; import eu.hbp.mip.models.DTOs.MIPEngineAttributesDTO;
import eu.hbp.mip.models.DTOs.MetadataHierarchyDTO; import eu.hbp.mip.models.DTOs.MIPEngineCommonDataElement;
import eu.hbp.mip.models.DTOs.PathologyDTO; import eu.hbp.mip.models.DTOs.PathologyDTO;
import eu.hbp.mip.services.ActiveUserService; import eu.hbp.mip.services.ActiveUserService;
import eu.hbp.mip.utils.*; import eu.hbp.mip.utils.*;
...@@ -77,14 +77,14 @@ public class PathologiesAPI { ...@@ -77,14 +77,14 @@ public class PathologiesAPI {
} }
public Map<String, List<PathologyDTO.EnumerationDTO>> getMIPEngineDatasetsPerPathology(Logger logger) { public Map<String, List<PathologyDTO.EnumerationDTO>> getMIPEngineDatasetsPerPathology(Logger logger) {
Map<String, Map<String, MetadataHierarchyDTO.CommonDataElement>> mipEngineCDEsMetadata; Map<String, Map<String, MIPEngineCommonDataElement>> mipEngineCDEsMetadata;
// Get MIPEngine algorithms // Get MIPEngine algorithms
try { try {
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
HTTPUtil.sendGet(mipengineCDEsMetadataUrl, response); HTTPUtil.sendGet(mipengineCDEsMetadataUrl, response);
mipEngineCDEsMetadata = gson.fromJson( mipEngineCDEsMetadata = gson.fromJson(
response.toString(), response.toString(),
new TypeToken<HashMap<String, Map<String, MetadataHierarchyDTO.CommonDataElement>>>() { new TypeToken<HashMap<String, Map<String, MIPEngineCommonDataElement>>>() {
}.getType() }.getType()
); );
} catch (Exception e) { } catch (Exception e) {
...@@ -122,14 +122,7 @@ public class PathologiesAPI { ...@@ -122,14 +122,7 @@ public class PathologiesAPI {
return null; return null;
} }
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; return mipEnginePathologyAttributes;
} }
} }
...@@ -18,19 +18,4 @@ public class MIPEngineAttributesDTO { ...@@ -18,19 +18,4 @@ public class MIPEngineAttributesDTO {
@SerializedName("tags") @SerializedName("tags")
private Object 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;
}
} }
package eu.hbp.mip.models.DTOs;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class MIPEngineCommonDataElement {
@SerializedName("is_categorical")
private Boolean is_categorical;
@SerializedName("code")
private String code;
@SerializedName("sql_type")
private String sql_type;
@SerializedName("description")
private String description;
@SerializedName("enumerations")
private Object enumerations;
@SerializedName("label")
private String label;
@SerializedName("units")
private String units;
@SerializedName("type")
private String type;
@SerializedName("methodology")
private String methodology;
@SerializedName("min")
private String min;
@SerializedName("max")
private String max;
}
...@@ -4,9 +4,7 @@ import com.google.gson.annotations.SerializedName; ...@@ -4,9 +4,7 @@ import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
...@@ -39,7 +37,7 @@ public class MetadataHierarchyDTO { ...@@ -39,7 +37,7 @@ public class MetadataHierarchyDTO {
private String description; private String description;
@SerializedName("enumerations") @SerializedName("enumerations")
private Object enumerations; private List<PathologyDTO.EnumerationDTO> enumerations;
@SerializedName("label") @SerializedName("label")
private String label; private String label;
...@@ -58,43 +56,8 @@ public class MetadataHierarchyDTO { ...@@ -58,43 +56,8 @@ public class MetadataHierarchyDTO {
@SerializedName("max") @SerializedName("max")
private String 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;
}
public boolean isDatasetCDEPresent(){ public boolean isDatasetCDEPresent(){
if (this.variables != null) { if (this.variables != null) {
......
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