Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jt/visually segmented case search groups #1511

Merged
merged 13 commits into from
Dec 13, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public class DisplayElement {
@Nullable
private String requiredMsg;

@Nullable
private String groupKey;

public DisplayElement() {
}

Expand All @@ -68,8 +71,8 @@ public DisplayElement(Action action, EvaluationContext ec) {
public DisplayElement(DisplayUnit displayUnit, EvaluationContext ec, String id,
@Nullable String input,
@Nullable String receive, @Nullable String hidden, @Nullable String value,
@Nullable String[] itemsetChoicesKeys, @Nullable String[] itemsetChoicesLabels, boolean allowBlankValue, boolean required,
String requiredMsg, String error) {
@Nullable String[] itemsetChoicesKeys, @Nullable String[] itemsetChoicesLabels, boolean allowBlankValue,
boolean required, String requiredMsg, String error, @Nullable String groupKey) {
this.id = id;
this.text = displayUnit.getText().evaluate(ec);
if (displayUnit.getImageURI() != null) {
Expand All @@ -91,6 +94,7 @@ public DisplayElement(DisplayUnit displayUnit, EvaluationContext ec, String id,
this.allowBlankValue = allowBlankValue;
this.required = required;
this.requiredMsg = requiredMsg;
this.groupKey = groupKey;
this.error = error;
}

Expand Down Expand Up @@ -187,4 +191,10 @@ public String getError() {
public String getRequiredMsg() {
return requiredMsg;
}

@JsonGetter(value = "groupKey")
shubham1g5 marked this conversation as resolved.
Show resolved Hide resolved
@Nullable
public String getGroupKey() {
return groupKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.commcare.modern.util.Pair;
import org.commcare.session.RemoteQuerySessionManager;
import org.commcare.suite.model.QueryPrompt;
import org.commcare.suite.model.QueryGroup;
import org.commcare.util.screen.QueryScreen;
import org.javarosa.core.model.condition.EvaluationContext;
import org.javarosa.core.model.utils.ItemSetUtils;
Expand All @@ -14,6 +15,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

/**
* Created by willpride on 4/13/16.
Expand All @@ -23,6 +25,7 @@ public class QueryResponseBean extends MenuBean {
private DisplayElement[] displays;
private final String type = "query";
private String description;
private OrderedHashtable<String, String> groupHeaders;

QueryResponseBean() {
}
Expand All @@ -43,6 +46,10 @@ private void setDisplays(DisplayElement[] displays) {
this.displays = displays;
}

public OrderedHashtable<String, String> getGroupHeaders(){
return groupHeaders;
}

public QueryResponseBean(QueryScreen queryScreen) {
OrderedHashtable<String, QueryPrompt> queryPromptMap = queryScreen.getUserInputDisplays();
Hashtable<String, String> currentAnswers = queryScreen.getCurrentAnswers();
Expand Down Expand Up @@ -79,10 +86,21 @@ public QueryResponseBean(QueryScreen queryScreen) {
queryPromptItem.isAllowBlankValue(),
isRequired,
requiredMessage,
errors.get(key)
errors.get(key),
queryPromptItem.getGroupKey()
);
count++;
}

OrderedHashtable<String, QueryGroup> queryGroupMap = queryScreen.getGroupHeaders();
groupHeaders = new OrderedHashtable<>();
for (Map.Entry<String, QueryGroup> entry : queryGroupMap.entrySet()) {
String key = entry.getKey();
QueryGroup queryGroupItem = entry.getValue();
String text = queryGroupItem.getDisplay().getText().evaluate(ec);
groupHeaders.put(key, text);
}

setTitle(queryScreen.getScreenTitle());
setDescription(queryScreen.getDescriptionText());
setQueryKey(queryScreen.getQueryKey());
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/commcare/formplayer/tests/CaseClaimTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,27 @@ public void testQueryPromptRequired() throws Exception {
assertTrue(queryResponseBean.getDisplays()[4].getRequiredMsg().contentEquals(expectedMessage));
}

@Test
public void testQueryPromptGrouped() throws Exception {
QueryData queryData = new QueryData();

QueryResponseBean queryResponseBean = sessionNavigateWithQuery(
new String[]{"1", "action 1"},
"caseclaim",
queryData,
QueryResponseBean.class);

String groupKey1 = "group_header_0";
String groupKey2 = "group_header_3";
String expectedHeader1 = "Group1 Header";
String expectedHeader2 = "Group2 Header";

assertEquals(queryResponseBean.getGroupHeaders().get(groupKey1), expectedHeader1);
assertEquals(queryResponseBean.getGroupHeaders().get(groupKey2), expectedHeader2);
assertEquals(queryResponseBean.getDisplays()[0].getGroupKey(), groupKey1);
assertEquals(queryResponseBean.getDisplays()[4].getGroupKey(), groupKey2);
}

@Test
public void testDependentItemsets_DependentChoicesChangeWithSelection() throws Exception {
Hashtable<String, String> inputs = new Hashtable<>();
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/archives/caseclaim/default/app_strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ search_property.m1.age.validation=age should be greater than 18
search_property.m1.age.required=One of age or DOB is required
search_property.m1.dob=Date of Birth
search_property.m1.dob.required=One of age or DOB is required
search_property.m0.group_header_0=Group1 Header
search_property.m0.group_header_3=Group2 Header
24 changes: 19 additions & 5 deletions src/test/resources/archives/caseclaim/suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,28 @@
<data ref="'case2'" key="case_type"/>
<data ref="'case3'" key="case_type"/>
<data ref="'False'" key="include_closed"/>
<prompt key="name" default="instance('commcaresession')/session/context/deviceid" required="true()">
<group key="group_header_0">
<display>
<text>
<locale id="search_property.m0.group_header_0"/>
</text>
</display>
</group>
<group key="group_header_3">
<display>
<text>
<locale id="search_property.m0.group_header_3"/>
</text>
</display>
</group>
<prompt key="name" default="instance('commcaresession')/session/context/deviceid" required="true()" group_key="group_header_0">
<display>
<text>
<locale id="search_property.m1.name"/>
</text>
</display>
</prompt>
<prompt key="state" input="select1" default="&quot;ka&quot;" allow_blank_value="true" required="true()">
<prompt key="state" input="select1" default="&quot;ka&quot;" allow_blank_value="true" required="true()" group_key="group_header_0">
<display>
<text>
<locale id="search_property.m1.state"/>
Expand All @@ -395,7 +409,7 @@
<sort ref="id"/>
</itemset>
</prompt>
<prompt key="district" input="select">
<prompt key="district" input="select" group_key="group_header_3">
<display>
<text>
<locale id="search_property.m1.district"/>
Expand All @@ -407,7 +421,7 @@
<sort ref="id"/>
</itemset>
</prompt>
<prompt key="age">
<prompt key="age" group_key="group_header_3">
<validation test="count(.) = 1 and int(instance('my-search-input')/input/field[@name='age'])>18">
<text>
<locale id="search_property.m1.age.validation"/>
Expand All @@ -424,7 +438,7 @@
</text>
</display>
</prompt>
<prompt key="dob">
<prompt key="dob" group_key="group_header_3">
<display>
<text>
<locale id="search_property.m1.dob"/>
Expand Down