Skip to content

Commit

Permalink
Merge pull request #1511 from dimagi/jt/visually-segmented-case-searc…
Browse files Browse the repository at this point in the history
…h-groups

Jt/visually segmented case search groups
  • Loading branch information
Jtang-1 authored Dec 13, 2023
2 parents 56fe7e0 + 519223b commit eedb907
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
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,9 @@ public String getError() {
public String getRequiredMsg() {
return requiredMsg;
}

@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 Hashtable<String, String> groupHeaders;

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

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

public void setGroupHeaders(Hashtable<String, String> groupHeaders){
this.groupHeaders = groupHeaders;
}

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

setGroupHeaders(queryScreen.evalGroupHeaders());
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

0 comments on commit eedb907

Please sign in to comment.