Skip to content

Commit 485b41a

Browse files
oleg-odysseusalex-odysseus
authored andcommitted
Fix for annotation search data shown as JSON instead of human readable format
1 parent 2b9c35a commit 485b41a

File tree

2 files changed

+66
-25
lines changed

2 files changed

+66
-25
lines changed

src/main/java/org/ohdsi/webapi/service/ConceptSetService.java

+38-24
Original file line numberDiff line numberDiff line change
@@ -895,18 +895,23 @@ private ConceptSetVersion saveVersion(int id) {
895895
public boolean saveConceptSetAnnotation(@PathParam("id") final int conceptSetId, SaveConceptSetAnnotationsRequest request) {
896896
removeAnnotations(conceptSetId, request);
897897
if (CollectionUtils.isNotEmpty(request.getNewAnnotation())) {
898-
List<ConceptSetAnnotation> annotationList = request.getNewAnnotation().stream().map(m -> {
898+
List<ConceptSetAnnotation> annotationList = request.getNewAnnotation()
899+
.stream()
900+
.map(newAnnotationData -> {
899901
ConceptSetAnnotation conceptSetAnnotation = new ConceptSetAnnotation();
900902
conceptSetAnnotation.setConceptSetId(conceptSetId);
901903
try {
902-
AnnotationDetailsDTO annotationDetailsDTO = mapper.readValue(mapper.writeValueAsString(m), AnnotationDetailsDTO.class);
904+
AnnotationDetailsDTO annotationDetailsDTO = new AnnotationDetailsDTO();
905+
annotationDetailsDTO.setId(newAnnotationData.getId());
906+
annotationDetailsDTO.setConceptId(newAnnotationData.getConceptId());
907+
annotationDetailsDTO.setSearchData(newAnnotationData.getSearchData());
903908
conceptSetAnnotation.setAnnotationDetails(mapper.writeValueAsString(annotationDetailsDTO));
904909
} catch (JsonProcessingException e) {
905910
throw new RuntimeException(e);
906911
}
907-
conceptSetAnnotation.setVocabularyVersion(m.getVocabularyVersion());
908-
conceptSetAnnotation.setConceptSetVersion(m.getConceptSetVersion());
909-
conceptSetAnnotation.setConceptId(m.getConceptId());
912+
conceptSetAnnotation.setVocabularyVersion(newAnnotationData.getVocabularyVersion());
913+
conceptSetAnnotation.setConceptSetVersion(newAnnotationData.getConceptSetVersion());
914+
conceptSetAnnotation.setConceptId(newAnnotationData.getConceptId());
910915
conceptSetAnnotation.setCreatedBy(getCurrentUser());
911916
conceptSetAnnotation.setCreatedDate(new Date());
912917
return conceptSetAnnotation;
@@ -955,26 +960,35 @@ public void copyAnnotations(CopyAnnotationsRequest copyAnnotationsRequest ) {
955960
@Produces(MediaType.APPLICATION_JSON)
956961
public List<AnnotationDTO> getConceptSetAnnotation(@PathParam("id") final int id) {
957962
List<ConceptSetAnnotation> annotationList = getConceptSetAnnotationRepository().findByConceptSetId(id);
958-
List<AnnotationDTO> annotationDTOList = new ArrayList<>();
959-
for (ConceptSetAnnotation conceptSetAnnotation : annotationList) {
960-
AnnotationDTO annotationDTO;
961-
try {
962-
annotationDTO = mapper.readValue(conceptSetAnnotation.getAnnotationDetails(), AnnotationDTO.class);
963-
annotationDTO.setId(conceptSetAnnotation.getId());
964-
annotationDTO.setVocabularyVersion(conceptSetAnnotation.getVocabularyVersion());
965-
annotationDTO.setConceptSetVersion(conceptSetAnnotation.getConceptSetVersion());
966-
annotationDTO.setCreatedBy(conceptSetAnnotation.getCreatedBy() != null ? conceptSetAnnotation.getCreatedBy().getName() : null);
967-
annotationDTO.setCreatedDate(conceptSetAnnotation.getCreatedDate() != null ? conceptSetAnnotation.getCreatedDate().toString() : null);
968-
969-
String searchDataJSON = annotationDTO.getSearchData();
970-
String humanReadableData = searchDataTransformer.convertJsonToReadableFormat(searchDataJSON);
971-
annotationDTO.setSearchData(humanReadableData);
972-
annotationDTOList.add(annotationDTO);
973-
} catch (IOException e) {
974-
throw new RuntimeException(e);
975-
}
963+
return annotationList.stream()
964+
.map(this::convertAnnotationEntityToDTO)
965+
.collect(Collectors.toList());
966+
}
967+
968+
969+
private AnnotationDTO convertAnnotationEntityToDTO(ConceptSetAnnotation conceptSetAnnotation) {
970+
AnnotationDetailsDTO annotationDetails;
971+
try {
972+
annotationDetails = mapper.readValue(conceptSetAnnotation.getAnnotationDetails(), AnnotationDetailsDTO.class);
973+
} catch (JsonProcessingException e) {
974+
throw new RuntimeException(e);
976975
}
977-
return annotationDTOList;
976+
977+
AnnotationDTO annotationDTO = new AnnotationDTO();
978+
979+
annotationDTO.setId(conceptSetAnnotation.getId());
980+
annotationDTO.setConceptId(conceptSetAnnotation.getConceptId());
981+
982+
String searchDataJSON = annotationDetails.getSearchData();
983+
String humanReadableData = searchDataTransformer.convertJsonToReadableFormat(searchDataJSON);
984+
annotationDTO.setSearchData(humanReadableData);
985+
986+
annotationDTO.setVocabularyVersion(conceptSetAnnotation.getVocabularyVersion());
987+
annotationDTO.setConceptSetVersion(conceptSetAnnotation.getConceptSetVersion());
988+
annotationDTO.setCreatedBy(conceptSetAnnotation.getCreatedBy() != null ? conceptSetAnnotation.getCreatedBy().getName() : null);
989+
annotationDTO.setCreatedDate(conceptSetAnnotation.getCreatedDate() != null ? conceptSetAnnotation.getCreatedDate().toString() : null);
990+
991+
return annotationDTO;
978992
}
979993

980994
@DELETE

src/main/java/org/ohdsi/webapi/service/dto/AnnotationDTO.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44

55
@JsonIgnoreProperties(ignoreUnknown = true)
6-
public class AnnotationDTO extends AnnotationDetailsDTO {
6+
public class AnnotationDTO {
77

8+
private Integer id;
89
private String createdBy;
910
private String createdDate;
1011
private String vocabularyVersion;
1112
private String conceptSetVersion;
13+
private String searchData;
14+
private Integer conceptId;
1215

1316
public String getCreatedBy() {
1417
return createdBy;
@@ -41,4 +44,28 @@ public String getConceptSetVersion() {
4144
public void setConceptSetVersion(String conceptSetVersion) {
4245
this.conceptSetVersion = conceptSetVersion;
4346
}
47+
48+
public Integer getId() {
49+
return id;
50+
}
51+
52+
public void setId(Integer id) {
53+
this.id = id;
54+
}
55+
56+
public String getSearchData() {
57+
return searchData;
58+
}
59+
60+
public void setSearchData(String searchData) {
61+
this.searchData = searchData;
62+
}
63+
64+
public Integer getConceptId() {
65+
return conceptId;
66+
}
67+
68+
public void setConceptId(Integer conceptId) {
69+
this.conceptId = conceptId;
70+
}
4471
}

0 commit comments

Comments
 (0)