99import com .google .gson .reflect .TypeToken ;
1010import com .vijay .jsonwizard .constants .JsonFormConstants ;
1111import com .vijay .jsonwizard .rules .RuleConstant ;
12+ import com .vijay .jsonwizard .utils .FormUtils ;
1213
1314import org .apache .commons .lang3 .StringUtils ;
1415import org .json .JSONArray ;
1516import org .json .JSONException ;
1617import org .json .JSONObject ;
1718import org .smartregister .anc .library .AncLibrary ;
1819import org .smartregister .anc .library .R ;
20+ import org .smartregister .anc .library .constants .ANCJsonFormConstants ;
1921import org .smartregister .anc .library .contract .ContactContract ;
2022import org .smartregister .anc .library .domain .Contact ;
2123import org .smartregister .anc .library .model .PartialContact ;
@@ -55,6 +57,7 @@ public class MainContactActivity extends BaseContactActivity implements ContactC
5557 private List <String > globalValueFields = new ArrayList <>();
5658 private List <String > editableFields = new ArrayList <>();
5759 private String baseEntityId ;
60+ private String womanOpenSRPId ;
5861 private String womanAge = "" ;
5962 private final List <String > invisibleRequiredFields = new ArrayList <>();
6063 private final String [] contactForms = new String []{ConstantsUtils .JsonFormUtils .ANC_QUICK_CHECK , ConstantsUtils .JsonFormUtils .ANC_PROFILE ,
@@ -72,6 +75,7 @@ protected void onResume() {
7275 (Map <String , String >) getIntent ().getSerializableExtra (ConstantsUtils .IntentKeyUtils .CLIENT_MAP );
7376 if (womanDetails != null && womanDetails .size () > 0 ) {
7477 womanAge = String .valueOf (Utils .getAgeFromDate (womanDetails .get (DBConstantsUtils .KeyUtils .DOB )));
78+ womanOpenSRPId = womanDetails .get (DBConstantsUtils .KeyUtils .ANC_ID );
7579 }
7680 if (!presenter .baseEntityIdExists ()) {
7781 presenter .setBaseEntityId (baseEntityId );
@@ -657,6 +661,16 @@ private void updateDefaultValues(JSONArray stepArray, int i, JSONObject fieldObj
657661 }
658662 }
659663 }
664+
665+ if (fieldObject .getString (JsonFormConstants .KEY ).equals (ANCJsonFormConstants .KeyConstants .OPTIBP_BUTTON )
666+ || fieldObject .getString (JsonFormConstants .KEY ).equals (ANCJsonFormConstants .KeyConstants .OPTIBP_BUTTON_SECOND )) {
667+ if (fieldObject .has (JsonFormConstants .OptibpConstants .OPTIBP_KEY_DATA )) {
668+ fieldObject .remove (JsonFormConstants .OptibpConstants .OPTIBP_KEY_DATA );
669+ }
670+ JSONObject optiBPData = FormUtils .createOptiBPDataObject (baseEntityId , womanOpenSRPId );
671+ fieldObject .put (JsonFormConstants .OptibpConstants .OPTIBP_KEY_DATA , optiBPData );
672+ }
673+
660674 }
661675
662676 private void getValueMap (JSONObject object ) throws JSONException {
0 commit comments