Skip to content

Commit

Permalink
Cnft2 1992 value missing (#1145)
Browse files Browse the repository at this point in the history
* still fixing SQL query to check the correct table

* search endpoint works, but not get all

* completed implementation

* everything has been fixed

* fixing tests
  • Loading branch information
alaapbharadwaj authored Mar 7, 2024
1 parent aed6375 commit 2de212d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ class PageRuleFinder {
[rule].target_question_identifier as [targetQuestions],
[question1].question_label as [sourceQuestionLabel],
[CodeSet].code_set_nm as [sourceQuestionCodeSet],
[question1].wa_question_uid as [sourceQuestionId],
STRING_AGG([question2].question_label, ',') WITHIN GROUP
STRING_AGG(CONVERT(NVARCHAR(max),[question2].question_label), ',') WITHIN GROUP
(ORDER BY CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',')) as [targetQuestionLabels],
0 as [TotalCount]
from WA_rule_metadata [rule]
left join WA_question [question1] on [rule].source_question_identifier = [question1].question_identifier
left join WA_UI_Metadata [question1] on [rule].source_question_identifier = [question1].question_identifier
left join [NBS_SRTE]..Codeset [CodeSet] on [question1].code_set_group_id = [CodeSet].code_set_group_id
left join WA_question [question2]
left join WA_UI_Metadata [question2]
on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',') > 0
where [rule].wa_rule_metadata_uid =:ruleId
where [rule].wa_rule_metadata_uid = :ruleId
group by
[rule].wa_rule_metadata_uid,
Expand All @@ -55,7 +54,6 @@ on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_qu
[rule].target_question_identifier,
[question1].question_label,
[CodeSet].code_set_nm,
[question1].wa_question_uid,
[rule].add_time
""";
private String findByPageId =
Expand All @@ -73,24 +71,23 @@ on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_qu
[rule].target_question_identifier as [targetQuestions],
[question1].question_label as [sourceQuestionLabel],
[CodeSet].code_set_nm as [sourceQuestionCodeSet],
[question1].wa_question_uid as [sourceQuestionId],
STRING_AGG([question2].question_label, ', ') WITHIN GROUP
STRING_AGG(CONVERT(NVARCHAR(max),[question2].question_label), ', ') WITHIN GROUP
(ORDER BY CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ','))
as [targetQuestionLabels],
(SELECT COUNT(DISTINCT [rule].wa_rule_metadata_uid)
from WA_rule_metadata [rule]
left join WA_question [question1] on [rule].source_question_identifier = [question1].question_identifier
left join WA_UI_Metadata [question1] on [rule].source_question_identifier = [question1].question_identifier
left join [NBS_SRTE]..Codeset [CodeSet] on [question1].code_set_group_id = [CodeSet].code_set_group_id
left join WA_question [question2]
left join WA_UI_Metadata [question2]
on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',') > 0
where [rule].wa_template_uid =:pageId
where [rule].wa_template_uid =:pageId and [question1].wa_template_uid = :pageId and [question2].wa_template_uid = :pageId
) as [totalCount]
from WA_rule_metadata [rule]
left join WA_question [question1] on [rule].source_question_identifier = [question1].question_identifier
left join WA_UI_Metadata [question1] on [rule].source_question_identifier = [question1].question_identifier
left join [NBS_SRTE]..Codeset [CodeSet] on [question1].code_set_group_id = [CodeSet].code_set_group_id
left join WA_question [question2]
left join WA_UI_Metadata [question2]
on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',') > 0
where [rule].wa_template_uid =:pageId
where [rule].wa_template_uid =:pageId and [question1].wa_template_uid = :pageId and [question2].wa_template_uid = :pageId
group by
[rule].wa_rule_metadata_uid,
[rule].wa_template_uid,
Expand All @@ -104,7 +101,6 @@ on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_qu
[rule].target_question_identifier,
[question1].question_label,
[CodeSet].code_set_nm,
[question1].wa_question_uid,
[rule].add_time
""";

Expand All @@ -121,19 +117,18 @@ on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_qu
[rule].logic as [comparator],
[rule].target_type as [targetType],
[rule].target_question_identifier as [targetQuestions],
[question1].question_label as [sourceQuestionLabel],
[question1].question_label as [sourceQuestionLabel],
[CodeSet].code_set_nm as [sourceQuestionCodeSet],
[question1].wa_question_uid as [sourceQuestionId],
STRING_AGG([question2].question_label, ', ') WITHIN GROUP
STRING_AGG(CONVERT(NVARCHAR(max),[question2].question_label), ', ') WITHIN GROUP
(ORDER BY CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ','))
as [targetQuestionLabels],
(SELECT COUNT(DISTINCT [rule].wa_rule_metadata_uid)
from WA_rule_metadata [rule]
left join WA_question [question1] on [rule].source_question_identifier = [question1].question_identifier
left join WA_UI_metadata [question1] on [rule].source_question_identifier = [question1].question_identifier
left join [NBS_SRTE]..Codeset [CodeSet] on [question1].code_set_group_id = [CodeSet].code_set_group_id
left join WA_question [question2]
left join WA_UI_metadata [question2]
on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',') > 0
where [rule].wa_template_uid =:pageId
where [rule].wa_template_uid =:pageId and [question1].wa_template_uid = :pageId and [question2].wa_template_uid = :pageId
and
(
UPPER([rule].source_question_identifier) LIKE CONCAT('%', UPPER(:searchValue), '%')
Expand All @@ -144,11 +139,11 @@ OR CHARINDEX(',' + :searchValue + ',', ',' + [question2].question_label + ',') >
)
) as [totalCount]
from WA_rule_metadata [rule]
left join WA_question [question1] on [rule].source_question_identifier = [question1].question_identifier
left join WA_UI_metadata [question1] on [rule].source_question_identifier = [question1].question_identifier
left join [NBS_SRTE]..Codeset [CodeSet] on [question1].code_set_group_id = [CodeSet].code_set_group_id
left join WA_question [question2]
left join WA_UI_metadata [question2]
on CHARINDEX(',' + [question2].question_identifier + ',', ',' + [rule].target_question_identifier + ',') > 0
where [rule].wa_template_uid =:pageId
where [rule].wa_template_uid =:pageId and [question1].wa_template_uid = :pageId and [question2].wa_template_uid = :pageId
and
(
UPPER([rule].source_question_identifier) LIKE CONCAT('%', UPPER(:searchValue), '%')
Expand All @@ -170,7 +165,6 @@ OR CHARINDEX(',' + :searchValue + ',', ',' + [question2].question_label + ',') >
[rule].target_question_identifier,
[question1].question_label,
[CodeSet].code_set_nm,
[question1].wa_question_uid,
[rule].add_time
order by sortReplace
offset :offset rows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@Component
class PageRuleMapper implements RowMapper<Rule> {
record Column(int ruleId, int template, int ruleFunction, int description, int sourceQuestion, int ruleExpression,
int sourceValues, int comparator, int targetType, int targetQuestions, int sourceQuestionLabel,
int sourceQuestionCodeSet, int sourceQuestionId, int targetQuestionsLabels, int totalCount) {
int sourceValues, int comparator, int targetType, int targetQuestions, int sourceQuestionLabel,
int sourceQuestionCodeSet, int targetQuestionsLabels, int totalCount) {

}

Expand All @@ -27,7 +27,7 @@ record Column(int ruleId, int template, int ruleFunction, int description, int s
PageRuleMapper() {
this.columns = new PageRuleMapper.Column(1, 2, 3, 4,
5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15);
11, 12, 13, 14);
}

private Long totalRowsCount = 0l;
Expand All @@ -45,13 +45,12 @@ public Rule mapRow(final ResultSet rs, final int rowNum) throws SQLException {
String targetType = rs.getString(columns.targetType());
String sourceQuestionLabel = rs.getString(columns.sourceQuestionLabel());
String sourceQuestionCodeSet = rs.getString(columns.sourceQuestionCodeSet());
long sourceQuestionId = rs.getLong(columns.sourceQuestionId());
totalRowsCount = rs.getLong(columns.totalCount());
Rule.RuleFunction functionEnum = getFunctionEnum(function);
Rule.Comparator comparatorEnum = getComparatorEnum(comparator);
Rule.TargetType targetTypeEnum = getTargetTypeEnum(targetType);
Rule.SourceQuestion sourceQuestionInfo =
new Rule.SourceQuestion(sourceQuestionId, sourceQuestionIdentifier, sourceQuestionLabel, sourceQuestionCodeSet);
new Rule.SourceQuestion(sourceQuestionIdentifier, sourceQuestionLabel, sourceQuestionCodeSet);
boolean anySource = ruleExpression.contains("( )");
List<String> sourceValuesList = null;
if (sourceValues != null)
Expand All @@ -65,11 +64,9 @@ public Rule mapRow(final ResultSet rs, final int rowNum) throws SQLException {
}

private List<Rule.Target> getTargets(String identifiers, String labels) {
List<String> targetQuestions = identifiers != null ?
Arrays.stream(identifiers.split(",")).toList() : null;
List<String> targetQuestions = identifiers != null ? Arrays.stream(identifiers.split(",")).toList() : null;

List<String> targetQuestionsLabels = labels != null ?
Arrays.stream(labels.split(",")).toList() : null;
List<String> targetQuestionsLabels = labels != null ? Arrays.stream(labels.split(",")).toList() : null;

List<Rule.Target> targets = new ArrayList<>();
if (targetQuestions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public record Rule(
List<String> sourceValues,
@ApiModelProperty(required = true) Comparator comparator,
@ApiModelProperty(required = true) TargetType targetType,
@ApiModelProperty(required = true) List<Target> targets
) {
@ApiModelProperty(required = true) List<Target> targets) {

public record CreateRuleRequest(
@ApiModelProperty(required = true) RuleFunction ruleFunction,
Expand All @@ -35,7 +34,7 @@ public record SourceValue(String id, String text) {
}


public record SourceQuestion(long questionId, String questionIdentifier, String label, String codeSetName) {
public record SourceQuestion(String questionIdentifier, String label, String codeSetName) {
}


Expand All @@ -50,6 +49,7 @@ public enum RuleFunction {
HIDE("Hide"),
REQUIRE_IF("Require If"),
UNHIDE("Unhide");

private final String value;

RuleFunction(String value) {
Expand All @@ -69,6 +69,7 @@ public enum Comparator {
GREATER_THAN_OR_EQUAL_TO(">="),
LESS_THAN("<"),
LESS_THAN_OR_EQUAL_TO("<=");

private final String value;

Comparator(String value) {
Expand All @@ -90,4 +91,3 @@ public enum TargetType {
}



Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private List<Rule> getRuleList() {
List<String> sourceValues = new ArrayList<>();
List<Rule.Target> targetQuestions = new ArrayList<>();
List<Rule> content = new ArrayList<>();
Rule.SourceQuestion sourceQuestion = new Rule.SourceQuestion(1000l, "identifier", "label", "codeSet");
Rule.SourceQuestion sourceQuestion = new Rule.SourceQuestion("identifier", "label", "codeSet");
content.add(new Rule(100l, 123l, Rule.RuleFunction.ENABLE, "testDesc", sourceQuestion,
false, sourceValues, Rule.Comparator.EQUAL_TO, Rule.TargetType.QUESTION, targetQuestions));
return content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ void testMapRow() throws SQLException {
when(resultSet.getString(10)).thenReturn("test456,test789,test123");
when(resultSet.getString(11)).thenReturn("label123");
when(resultSet.getString(12)).thenReturn("codeSetName");
when(resultSet.getLong(13)).thenReturn(1000l);
when(resultSet.getString(14)).thenReturn("test456_label,test789_label");
when(resultSet.getLong(15)).thenReturn(10l);
when(resultSet.getString(13)).thenReturn("test456_label,test789_label");
when(resultSet.getLong(14)).thenReturn(10l);
Rule actualResponse = pageRuleMapper.mapRow(resultSet, 1);
validate(actualResponse);
long rowsCount = pageRuleMapper.getTotalRowsCount();
Expand All @@ -55,7 +54,6 @@ private void validate(Rule response) {
assertEquals(3, response.sourceValues().size());
assertEquals("EQUAL_TO", response.comparator().toString());
assertEquals("QUESTION", response.targetType().toString());
assertEquals(1000l, response.sourceQuestion().questionId());
assertEquals("test456", response.targets().get(0).targetIdentifier());
assertEquals("test456_label", response.targets().get(0).label());
}
Expand All @@ -76,9 +74,8 @@ void testMapRow_null_values() throws SQLException {
when(resultSet.getString(10)).thenReturn(null);
when(resultSet.getString(11)).thenReturn("label123");
when(resultSet.getString(12)).thenReturn("codeSetName");
when(resultSet.getLong(13)).thenReturn(1000l);
when(resultSet.getString(14)).thenReturn(null);
when(resultSet.getLong(15)).thenReturn(10l);
when(resultSet.getString(13)).thenReturn(null);
when(resultSet.getLong(14)).thenReturn(10l);
Rule actualResponse = pageRuleMapper.mapRow(resultSet, 1);

assertNull(actualResponse.sourceValues());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Feature: Create Business Rule
And the business rule should have "target type" of "QUESTION"
And the business rule should have target questions list of:
| id | label |
| INV143 | Age at Onset |
| INV143 | Age at Illness Onset: |

And the business rule should have "source values" of:
| Male |
Expand Down Expand Up @@ -106,7 +106,7 @@ Feature: Create Business Rule
And the business rule should have "target type" of "QUESTION"
And the business rule should have target questions list of:
| id | label |
| INV143 | Age at Onset |
| INV143 | Age at Illness Onset: |
And the business rule should have "source values" of:
| Male |
| Female |
Expand Down Expand Up @@ -138,7 +138,7 @@ Feature: Create Business Rule
And the business rule should have "target type" of "QUESTION"
And the business rule should have target questions list of:
| id | label |
| INV143 | Age at Onset |
| INV143 | Age at Illness Onset: |
And the business rule should have "source values" of:
| Male |
| Female |
Expand Down Expand Up @@ -170,7 +170,7 @@ Feature: Create Business Rule
And the business rule should have "target type" of "QUESTION"
And the business rule should have target questions list of:
| id | label |
| INV143 | Age at Onset |
| INV143 | Age at Illness Onset: |
And the business rule should have "source values" of:
| Male |
| Female |

0 comments on commit 2de212d

Please sign in to comment.