Skip to content

Commit 9bb28d7

Browse files
authored
Added check for entity name uniqueness (#1031)
1 parent a34507b commit 9bb28d7

53 files changed

Lines changed: 804 additions & 446 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/ohdsi/webapi/cohortanalysis/CohortSummary.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.ohdsi.webapi.cohortanalysis;
22

3-
import java.util.List;
3+
import org.ohdsi.webapi.cohortdefinition.dto.CohortDTO;
44

5-
import org.ohdsi.webapi.service.CohortDefinitionService.CohortDefinitionDTO;
5+
import java.util.List;
66

77
public class CohortSummary {
88

9-
private CohortDefinitionDTO cohortDefinition;
9+
private CohortDTO cohortDefinition;
1010

1111
private String totalPatients;
1212

@@ -23,14 +23,14 @@ public class CohortSummary {
2323
/**
2424
* @return the definition
2525
*/
26-
public CohortDefinitionDTO getCohortDefinition() {
26+
public CohortDTO getCohortDefinition() {
2727
return cohortDefinition;
2828
}
2929

3030
/**
3131
* @param definition the definition to set
3232
*/
33-
public void setCohortDefinition(CohortDefinitionDTO definition) {
33+
public void setCohortDefinition(CohortDTO definition) {
3434
this.cohortDefinition = definition;
3535
}
3636

src/main/java/org/ohdsi/webapi/cohortcharacterization/CcController.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
package org.ohdsi.webapi.cohortcharacterization;
22

33
import com.odysseusinc.arachne.commons.utils.ConverterUtils;
4+
5+
import java.util.Collections;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.Objects;
9+
import java.util.stream.Collectors;
10+
import javax.ws.rs.Consumes;
11+
import javax.ws.rs.DELETE;
12+
import javax.ws.rs.DefaultValue;
13+
import javax.ws.rs.GET;
14+
import javax.ws.rs.POST;
15+
import javax.ws.rs.PUT;
16+
import javax.ws.rs.Path;
17+
import javax.ws.rs.PathParam;
18+
import javax.ws.rs.Produces;
19+
import javax.ws.rs.QueryParam;
20+
import javax.ws.rs.core.MediaType;
21+
import javax.ws.rs.core.Response;
22+
423
import org.ohdsi.analysis.Utils;
524
import org.ohdsi.analysis.cohortcharacterization.design.CohortCharacterization;
625
import org.ohdsi.analysis.cohortcharacterization.design.StandardFeatureAnalysisType;
@@ -26,16 +45,7 @@
2645
import org.springframework.stereotype.Controller;
2746
import org.springframework.transaction.annotation.Transactional;
2847

29-
import javax.ws.rs.*;
30-
import javax.ws.rs.core.MediaType;
31-
import javax.ws.rs.core.Response;
3248
import java.io.ByteArrayOutputStream;
33-
import java.io.IOException;
34-
import java.util.Collections;
35-
import java.util.List;
36-
import java.util.Map;
37-
import java.util.Objects;
38-
import java.util.stream.Collectors;
3949

4050
@Path("/cohort-characterization")
4151
@Controller
@@ -120,6 +130,14 @@ public CohortCharacterizationDTO getDesign(@PathParam("id") final Long id) {
120130
return convertCcToDto(service.findByIdWithLinkedEntities(id));
121131
}
122132

133+
@GET
134+
@Path("/{id}/exists")
135+
@Produces(MediaType.APPLICATION_JSON)
136+
@Consumes(MediaType.APPLICATION_JSON)
137+
public int getCountCcWithSameName(@PathParam("id") @DefaultValue("0") final long id, @QueryParam("name") String name) {
138+
return service.getCountCcWithSameName(id, name);
139+
}
140+
123141
@DELETE
124142
@Path("/{id}")
125143
@Produces(MediaType.APPLICATION_JSON)

src/main/java/org/ohdsi/webapi/cohortcharacterization/CcService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public interface CcService {
1717
CohortCharacterizationEntity createCc(CohortCharacterizationEntity entity);
1818

1919
CohortCharacterizationEntity updateCc(CohortCharacterizationEntity entity);
20+
21+
int getCountCcWithSameName(Long id, String name);
2022

2123
void deleteCc(Long ccId);
2224

src/main/java/org/ohdsi/webapi/cohortcharacterization/CcServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ private CohortCharacterizationEntity saveCc(final CohortCharacterizationEntity e
193193
return repository.save(savedEntity);
194194
}
195195

196+
@Override
197+
public int getCountCcWithSameName(Long id, String name) {
198+
return repository.getCountCcWithSameName(id, name);
199+
}
200+
196201
@Override
197202
public void deleteCc(Long ccId) {
198203
repository.delete(ccId);

src/main/java/org/ohdsi/webapi/cohortcharacterization/repository/CcRepository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
import com.cosium.spring.data.jpa.entity.graph.repository.EntityGraphJpaRepository;
66
import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity;
7+
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.data.repository.query.Param;
79

810
public interface CcRepository extends EntityGraphJpaRepository<CohortCharacterizationEntity, Long> {
911
Optional<CohortCharacterizationEntity> findById(final Long id);
1012
int countByNameStartsWith(String pattern);
1113
Optional<CohortCharacterizationEntity> findByName(String name);
14+
15+
@Query("SELECT COUNT(cc) FROM CohortCharacterizationEntity cc WHERE cc.name = :ccName and cc.id <> :ccId")
16+
int getCountCcWithSameName(@Param("ccId") Long ccId, @Param("ccName") String ccName);
1217
}

src/main/java/org/ohdsi/webapi/cohortdefinition/CohortDefinitionRepository.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
package org.ohdsi.webapi.cohortdefinition;
1616

1717
import java.util.List;
18-
import org.ohdsi.webapi.cohortcharacterization.domain.CohortCharacterizationEntity;
1918
import org.springframework.data.domain.Page;
2019
import org.springframework.data.domain.Pageable;
2120
import org.springframework.data.jpa.repository.EntityGraph;
2221
import org.springframework.data.jpa.repository.Query;
2322
import org.springframework.data.repository.CrudRepository;
23+
import org.springframework.data.repository.query.Param;
2424

2525
/**
2626
*
@@ -35,8 +35,9 @@ public interface CohortDefinitionRepository extends CrudRepository<CohortDefinit
3535
@Query("select cd from CohortDefinition cd LEFT JOIN FETCH cd.createdBy LEFT JOIN FETCH cd.modifiedBy where cd.id = ?1")
3636
CohortDefinition findOneWithDetail(Integer id);
3737

38-
@Query("select cd from CohortDefinition AS cd JOIN FETCH cd.details as d")
38+
@Query("select cd from CohortDefinition AS cd JOIN FETCH cd.details LEFT JOIN FETCH cd.createdBy LEFT JOIN FETCH cd.modifiedBy")
3939
List<CohortDefinition> list();
4040

41-
List<CohortDefinition> findAllByCohortCharacterizations(CohortCharacterizationEntity mainEntity);
41+
@Query("select count(cd) from CohortDefinition AS cd WHERE cd.name = :name and cd.id <> :id")
42+
int getCountCDefWithSameName(@Param("id") Integer id, @Param("name") String name);
4243
}

src/main/java/org/ohdsi/webapi/cohortdefinition/converter/BaseCohortDefinitionToCohortMetadataDTOConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.ohdsi.webapi.cohortdefinition.CohortDefinition;
44
import org.ohdsi.webapi.cohortdefinition.dto.CohortMetadataDTO;
55
import org.ohdsi.webapi.converter.BaseConversionServiceAwareConverter;
6+
import org.ohdsi.webapi.util.UserUtils;
67

78
public abstract class BaseCohortDefinitionToCohortMetadataDTOConverter<T extends CohortMetadataDTO> extends BaseConversionServiceAwareConverter<CohortDefinition, T> {
89

@@ -13,6 +14,10 @@ public T convert(CohortDefinition def) {
1314
target.setId(def.getId());
1415
target.setName(def.getName());
1516
target.setDescription(def.getDescription());
17+
target.setCreatedBy(UserUtils.nullSafeLogin(def.getCreatedBy()));
18+
target.setCreatedDate(def.getCreatedDate());
19+
target.setModifiedBy(UserUtils.nullSafeLogin(def.getModifiedBy()));
20+
target.setModifiedDate(def.getModifiedDate());
1621
return target;
1722
}
1823

src/main/java/org/ohdsi/webapi/cohortdefinition/converter/CohortDefinitionToCohortDTOConverter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.ohdsi.webapi.cohortdefinition.converter;
22

3+
import org.ohdsi.analysis.Utils;
4+
import org.ohdsi.circe.cohortdefinition.CohortExpression;
35
import org.ohdsi.webapi.cohortdefinition.CohortDefinition;
46
import org.ohdsi.webapi.cohortdefinition.dto.CohortDTO;
57
import org.springframework.stereotype.Component;
@@ -12,7 +14,10 @@ public CohortDTO convert(final CohortDefinition source) {
1214

1315
final CohortDTO dto = super.convert(source);
1416
dto.setExpressionType(source.getExpressionType());
15-
dto.setExpression(source.getExpression());
17+
if (source.getDetails() != null) {
18+
CohortExpression expression = source.getDetails().getExpressionObject();
19+
dto.setExpression(Utils.serialize(expression));
20+
}
1621
return dto;
1722
}
1823

src/main/java/org/ohdsi/webapi/cohortdefinition/dto/CohortDTO.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
public class CohortDTO extends CohortMetadataDTO implements Cohort{
88

9-
private CohortExpression expression;
9+
private String expression;
1010
private ExpressionType expressionType;
1111

1212
public CohortExpression getExpression() {
13+
return CohortExpression.fromJson(expression);
14+
}
15+
16+
public String getExpressionStr() {
1317
return expression;
1418
}
1519

16-
public void setExpression(final CohortExpression expression) {
20+
public void setExpression(final String expression) {
1721
this.expression = expression;
1822
}
1923

src/main/java/org/ohdsi/webapi/cohortdefinition/dto/CohortMetadataDTO.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package org.ohdsi.webapi.cohortdefinition.dto;
22

3+
import com.fasterxml.jackson.annotation.JsonFormat;
34
import org.ohdsi.analysis.CohortMetadata;
45

6+
import java.util.Date;
7+
58
public class CohortMetadataDTO implements CohortMetadata {
69

710
private Integer id;
811
private String name;
912
private String description;
13+
private String createdBy;
14+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
15+
private Date createdDate;
16+
private String modifiedBy;
17+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
18+
private Date modifiedDate;
1019

1120
public Integer getId() {
1221

@@ -39,4 +48,36 @@ public void setDescription(String description) {
3948

4049
this.description = description;
4150
}
51+
52+
public String getCreatedBy() {
53+
return createdBy;
54+
}
55+
56+
public void setCreatedBy(String createdBy) {
57+
this.createdBy = createdBy;
58+
}
59+
60+
public Date getCreatedDate() {
61+
return createdDate;
62+
}
63+
64+
public void setCreatedDate(Date createdDate) {
65+
this.createdDate = createdDate;
66+
}
67+
68+
public String getModifiedBy() {
69+
return modifiedBy;
70+
}
71+
72+
public void setModifiedBy(String modifiedBy) {
73+
this.modifiedBy = modifiedBy;
74+
}
75+
76+
public Date getModifiedDate() {
77+
return modifiedDate;
78+
}
79+
80+
public void setModifiedDate(Date modifiedDate) {
81+
this.modifiedDate = modifiedDate;
82+
}
4283
}

0 commit comments

Comments
 (0)