Skip to content

Commit

Permalink
Merge pull request #54 from HBPMedical/fix_on_pathologies_API
Browse files Browse the repository at this point in the history
Fix on pathologies
  • Loading branch information
KFilippopolitis authored Dec 1, 2022
2 parents 7723c77 + e6644d4 commit 386f908
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 64 deletions.
15 changes: 4 additions & 11 deletions src/main/java/eu/hbp/mip/controllers/PathologiesAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
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.services.ActiveUserService;
import eu.hbp.mip.utils.*;
Expand Down Expand Up @@ -77,14 +77,14 @@ public ResponseEntity<String> getPathologies(Authentication authentication) {
}

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
try {
StringBuilder response = new StringBuilder();
HTTPUtil.sendGet(mipengineCDEsMetadataUrl, response);
mipEngineCDEsMetadata = gson.fromJson(
response.toString(),
new TypeToken<HashMap<String, Map<String, MetadataHierarchyDTO.CommonDataElement>>>() {
new TypeToken<HashMap<String, Map<String, MIPEngineCommonDataElement>>>() {
}.getType()
);
} catch (Exception e) {
Expand Down Expand Up @@ -122,14 +122,7 @@ public Map<String, MIPEngineAttributesDTO> getMIPEnginePathologyAttributes(Logge
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;
}
}
15 changes: 0 additions & 15 deletions src/main/java/eu/hbp/mip/models/DTOs/MIPEngineAttributesDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,4 @@ 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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;
}
39 changes: 1 addition & 38 deletions src/main/java/eu/hbp/mip/models/DTOs/MetadataHierarchyDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@AllArgsConstructor
Expand Down Expand Up @@ -39,7 +37,7 @@ public static class CommonDataElement {
private String description;

@SerializedName("enumerations")
private Object enumerations;
private List<PathologyDTO.EnumerationDTO> enumerations;

@SerializedName("label")
private String label;
Expand All @@ -58,43 +56,8 @@ public static class CommonDataElement {

@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;
}

public boolean isDatasetCDEPresent(){
if (this.variables != null) {
Expand Down

0 comments on commit 386f908

Please sign in to comment.