-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix: Return correct count values for RC/DRC and PC/DPC (#2405)
Fixes #2296
- Loading branch information
Showing
7 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/resources/ddl/results/achilles_result_concept_count.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
IF OBJECT_ID('@results_schema.achilles_result_concept_count', 'U') IS NULL | ||
CREATE TABLE @results_schema.achilles_result_concept_count ( | ||
concept_id int, | ||
record_count bigint, | ||
descendant_record_count bigint, | ||
person_count bigint, | ||
descendant_person_count bigint | ||
); |
81 changes: 81 additions & 0 deletions
81
src/test/java/org/ohdsi/webapi/test/CDMResultsServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.ohdsi.webapi.test; | ||
|
||
import com.odysseusinc.arachne.commons.types.DBMSType; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.ohdsi.circe.helper.ResourceHelper; | ||
import org.ohdsi.sql.SqlRender; | ||
import org.ohdsi.sql.SqlTranslate; | ||
import org.ohdsi.webapi.source.SourceRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
public class CDMResultsServiceIT extends WebApiIT { | ||
private static final String CDM_RESULTS_FILE_PATH = "/database/cdm_results.sql"; | ||
|
||
@Value("${cdmResultsService.endpoint.conceptRecordCount}") | ||
private String conceptRecordCountEndpoint; | ||
|
||
@Autowired | ||
private SourceRepository sourceRepository; | ||
|
||
@Before | ||
public void init() throws Exception { | ||
truncateTable(String.format("%s.%s", "public", "source")); | ||
resetSequence(String.format("%s.%s", "public", "source_sequence")); | ||
sourceRepository.saveAndFlush(getCdmSource()); | ||
prepareCdmSchema(); | ||
prepareResultSchema(); | ||
addCDMResults(); | ||
} | ||
|
||
private void addCDMResults() { | ||
String resultSql = SqlRender.renderSql(ResourceHelper.GetResourceAsString( | ||
CDM_RESULTS_FILE_PATH), | ||
new String[] { "results_schema" }, new String[] { RESULT_SCHEMA_NAME }); | ||
String sql = SqlTranslate.translateSql(resultSql, DBMSType.POSTGRESQL.getOhdsiDB()); | ||
jdbcTemplate.execute(sql); | ||
} | ||
|
||
@Test | ||
public void requestConceptRecordCounts_firstTime_returnsResults() { | ||
|
||
// Arrange | ||
List<Integer> conceptIds = Arrays.asList(1); | ||
Map<String, String> queryParameters = new HashMap<String, String>(); | ||
queryParameters.put("sourceName", SOURCE_KEY); | ||
|
||
List<LinkedHashMap<String, List<Integer>>> list = new ArrayList<>(); | ||
@SuppressWarnings("unchecked") | ||
Class<List<LinkedHashMap<String, List<Integer>>>> returnClass = (Class<List<LinkedHashMap<String, List<Integer>>>>)list.getClass(); | ||
|
||
// Act | ||
final ResponseEntity<List<LinkedHashMap<String, List<Integer>>>> entity = getRestTemplate().postForEntity(this.conceptRecordCountEndpoint, conceptIds, | ||
returnClass, queryParameters ); | ||
|
||
// Assertion | ||
assertOK(entity); | ||
List<LinkedHashMap<String, List<Integer>>> results = entity.getBody(); | ||
assertEquals(1, results.size()); | ||
LinkedHashMap<String, List<Integer>> resultHashMap = results.get(0); | ||
assertEquals(1, resultHashMap.size()); | ||
assertTrue(resultHashMap.containsKey("1")); | ||
List<Integer> counts = resultHashMap.get("1"); | ||
assertEquals(100, counts.get(0).intValue()); | ||
assertEquals(101, counts.get(1).intValue()); | ||
assertEquals(102, counts.get(2).intValue()); | ||
assertEquals(103, counts.get(3).intValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
insert into @results_schema.achilles_result_concept_count (concept_id, record_count, descendant_record_count, person_count, descendant_person_count) | ||
values (1,100,101,102,103); |