Example usage for com.google.gwt.http.client RequestBuilder POST

List of usage examples for com.google.gwt.http.client RequestBuilder POST

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder POST.

Prototype

Method POST

To view the source code for com.google.gwt.http.client RequestBuilder POST.

Click Source Link

Document

Specifies that the HTTP POST method should be used.

Usage

From source file:org.freemedsoftware.gwt.client.widget.FinancialWidget.java

License:Open Source License

public void loadProcedureTableData() {
    procedureViewTable.clearData();/*ww w  .  jav  a  2s  .c o m*/
    if (Util.getProgramMode() == ProgramMode.STUBBED) {

    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { patientId.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.ProcedureModule.getProcedureInfo", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                public void onResponseReceived(Request request, Response response) {

                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            @SuppressWarnings("unchecked")
                            HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()),
                                            "HashMap<String,String>[]");
                            procedureViewTable.loadData(result);
                        } else {
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
            procedureViewTable.setVisible(true);
        }
    } else {
    }

}

From source file:org.freemedsoftware.gwt.client.widget.LedgerWidget.java

License:Open Source License

public void loadInsuranceList(final CustomListBox insList) {

    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // ////////////////////
        String[] params = { procId };

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.ProcedureModule.getCoverages", params)));
        try {//from   w  ww . j a  va2s  . c  o m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            try {
                                HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>[]");
                                if (result != null) {
                                    if (result.length != 0) {
                                        hasInsurance = true;
                                        for (int i = 0; i < result.length; i++) {
                                            insList.addItem(result[i].get("payer"), result[i].get("id"));
                                        }
                                    } else {

                                    }
                                } else {
                                    paymentTypeGroup.customRadioButtonGroup.get(1).setEnabled(false);
                                    paymentTypeGroup.customRadioButtonGroup.get(2).setEnabled(false);
                                }
                            } catch (Exception e) {
                                //Window.alert(e.getMessage());
                                //paymentTypeGroup.customRadioButtonGroup.get(2).setEnabled(false);
                            }
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.LedgerWidget.java

License:Open Source License

private void processPayment() {
    JsonUtil.debug("before saving");
    final LedgerWidget lw = this;
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(Util.getJsonRequest(functionName, params)));

    try {/*from w w w. j  a  va 2 s  .  co  m*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable ex) {
            }

            public void onResponseReceived(Request request, Response response) {

                if (200 == response.getStatusCode()) {
                    try {
                        Boolean result = (Boolean) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                        if (result) {
                            Util.showInfoMsg("Ledger", _("Payment operation succeeded."));
                            lw.removeFromParent();
                            if (paycat == PayCategory.PAYMENT || paycat == PayCategory.COPAY
                                    || paycat == PayCategory.DEDUCTABLE) {
                                if (CurrentState.getSystemConfig("auto_print_ptrcpt").equals("1")) {
                                    printShortPatientReceipt();
                                }
                            }
                            if ((paycat == PayCategory.REBILLED || paycat == PayCategory.WRITEOFF)
                                    && !procId.equals("0")) {
                                callback.jsonifiedData("close");
                            } else {
                                callback.jsonifiedData("update");
                            }
                        } else {
                            Util.showErrorMsg("Ledger", _("Payment operation failed."));
                        }
                    } catch (Exception e) {
                        Util.showErrorMsg("Ledger", _("Payment operation failed."));
                    }
                } else {
                    Util.showErrorMsg("Ledger", _("Payment operation failed."));
                }
            }
        });
    } catch (RequestException e) {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.LedgerWidget.java

License:Open Source License

private void getLedgerInfo() {
    final LedgerWidget lw = this;
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
            URL.encode(Util.getJsonRequest(functionName, params)));

    try {/* w  w  w.  j a  v a 2  s  .  co m*/
        builder.sendRequest(null, new RequestCallback() {
            public void onError(Request request, Throwable ex) {
            }

            @SuppressWarnings("unchecked")
            public void onResponseReceived(Request request, Response response) {

                if (200 == response.getStatusCode()) {

                    HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                            JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");

                    if (result.length > 0) {
                        for (int i = 0; i < result.length; i++) {
                            int row = ledgerInfoFlexTable.getRowCount();
                            if (i != (result.length - 1)) {
                                ledgerInfoFlexTable.setText(row, 0, result[i].get("date"));
                                ledgerInfoFlexTable.setText(row, 1, result[i].get("type"));
                                ledgerInfoFlexTable.setText(row, 2, result[i].get("desc"));
                                ledgerInfoFlexTable.setText(row, 3, result[i].get("charge"));
                                ledgerInfoFlexTable.setText(row, 4, result[i].get("payment"));
                                ledgerInfoFlexTable.setText(row, 5, "");
                                if ((i % 2) == 0) {
                                    RowFormatter rowFormatter = ledgerInfoFlexTable.getRowFormatter();
                                    rowFormatter.setStyleName(row, AppConstants.STYLE_TABLE_ROW);
                                } else {
                                    RowFormatter rowFormatter = ledgerInfoFlexTable.getRowFormatter();
                                    rowFormatter.setStyleName(row, AppConstants.STYLE_TABLE_ROW_ALTERNATE);
                                }
                            } else {
                                ledgerInfoFlexTable.setText(row, 0, _("Total"));
                                ledgerInfoFlexTable.setText(row, 3, result[i].get("total_charges"));
                                ledgerInfoFlexTable.setText(row, 4, result[i].get("total_payments"));
                                int charges = new Integer(result[i].get("total_charges"));
                                int payments = new Integer(result[i].get("total_payments"));
                                ledgerInfoFlexTable.setText(row, 5, "" + (charges - payments));
                                RowFormatter rowFormatter = ledgerInfoFlexTable.getRowFormatter();
                                rowFormatter.setStyleName(row, AppConstants.STYLE_TABLE_HEADER);
                            }
                        }
                    } else {
                    }
                } else {
                }
            }
        });
    } catch (RequestException e) {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.LedgerWidget.java

License:Open Source License

public void loadCoverageByType(final int type, final CustomListBox lb) {

    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // ////////////////////
        String[] params = { patientId, type + "" };

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.PatientCoverages.GetCoverageByType", params)));
        try {/*from   w  ww.  ja  v  a2  s . c  om*/
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        if (Util.checkValidSessionResponse(response.getText())) {
                            try {
                                // Window.alert("Response is:"+type+"
                                // :"+response.getText());
                                covCount++;
                                HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()),
                                                "HashMap<String,String>[]");
                                if (result != null) {
                                    if (result.length != 0) {
                                        hasInsurance = true;
                                        String typeName = "";
                                        if (type == 1)
                                            typeName = _("Primary") + " ";
                                        else if (type == 2)
                                            typeName = _("Secondary") + " ";
                                        else if (type == 3)
                                            typeName = _("Tertiary") + " ";
                                        else if (type == 4)
                                            typeName = _("Work Comp") + " ";
                                        for (int i = 0; i < result.length; i++) {
                                            HashMap<String, String> m = (HashMap<String, String>) result[i];

                                            lb.addItem(typeName + "- " + m.get("comp_name"), m.get("Id"));
                                        }
                                    } else {

                                    }
                                    if (covCount == 4 && !hasInsurance) {
                                        paymentTypeGroup.customRadioButtonGroup.get(1).setEnabled(false);
                                        paymentTypeGroup.customRadioButtonGroup.get(2).setEnabled(false);
                                    }
                                }
                            } catch (Exception e) {
                                // Window.alert(e.getMessage());
                            }
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.MessageBox.java

License:Open Source License

public void showMessage(Integer messageId, MessageView messageView) {
    final MessageView view = messageView;
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        if (messageId == 1) {
            view.setText(/*from  w  ww. java 2  s  .c o  m*/
                    "This is some sample message according to ID#1. Here you can see that the messages can be designed using <b>HTML</b> in a <i>very cool <b>way</b></i>. <br/>You can even <sub>subcase letters</sub>.");
        } else if (messageId == 2) {
            view.setText("Text to MessageId 2");
        }
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "MessagesModule", JsonUtil.jsonify(messageId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleGetRecordMethod", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                        if (r != null) {
                            view.setText(r.get("msgtext").replace("\\", "").replace("\n", "<br/>"));
                            view.setMsgFromId(Integer.parseInt(r.get("msgby")));
                            view.setMsgSubject(r.get("msgsubject"));
                            view.setMsgPatientId(Integer.parseInt(r.get("msgpatient")));
                            view.setMsgBody(r.get("msgtext"));
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }

    } else if (Util.getProgramMode() == ProgramMode.NORMAL) {

    }
}

From source file:org.freemedsoftware.gwt.client.widget.MessageBox.java

License:Open Source License

public void retrieveData(String searchtag) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Runs in STUBBED MODE => Feed with Sample Data
        HashMap<String, String>[] sampleData = getSampleData();
        loadData(sampleData);//from  www  . j  a va2  s .co m
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // Use JSON-RPC to retrieve the data
        String[] messagesparams = { searchtag, JsonUtil.jsonify(Boolean.FALSE) };
        // TODO: get Config setting to retrieve all mail, or only new one
        // if (state.getUserConfig("messagebox") == "retrieveall") {
        // messagesparams[1] = JsonUtil.jsonify(Boolean.TRUE) ;
        //   
        // }

        String[] countparams = { JsonUtil.jsonify(Boolean.FALSE), JsonUtil.jsonify(Boolean.FALSE) };

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.MessagesModule.UnreadMessages", countparams)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    GWT.log(request.toString(), ex);
                }

                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        Integer data = (Integer) JsonUtil
                                .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                        if (data != null) {
                            JsonUtil.debug("Msg count from server is:" + data);
                            loadCounter(data);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            // nothing here right now
        }

        wMessages.showloading(true);
        // Get data
        RequestBuilder dataBuilder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.MessagesModule.GetAllByTag", messagesparams)));
        try {
            dataBuilder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    GWT.log(request.toString(), ex);
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == 200) {
                        HashMap<String, String>[] data = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (data != null) {
                            setResult(data);
                            loadData(data);
                        } else
                            wMessages.showloading(false);
                    }
                }
            });
        } catch (RequestException e) {
            // nothing here right now
        }
    } else if (Util.getProgramMode() == ProgramMode.NORMAL) {
        // Use GWT-RPC to retrieve the data
        // TODO: Create that stuff
    }
}

From source file:org.freemedsoftware.gwt.client.widget.ModuleSearchWidget.java

License:Open Source License

protected void loadSuggestions(String req, final Request r, final Callback cb) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Handle in a stubbed sort of way
        List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
        map.clear();/* ww  w.j a  v a2 s .c om*/
        addKeyValuePair(items, new String("Hackenbush, Hugo Z"), new String("1"));
        addKeyValuePair(items, new String("Firefly, Rufus T"), new String("2"));
        cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        List<String> paramList = new ArrayList<String>();
        paramList.add(req);
        if (selctedModuleType != null)
            paramList.add(selctedModuleType);
        String[] params = paramList.toArray(new String[0]);
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.api.ModuleSearch.picklist", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Window.alert(ex.toString());
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {

                        if (Util.checkValidSessionResponse(response.getText())) {
                            HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");

                            if (result != null) {
                                Set<String> keys = result.keySet();
                                Iterator<String> iter = keys.iterator();

                                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                                map.clear();
                                while (iter.hasNext()) {
                                    String key = iter.next();
                                    String val = key;
                                    //String val = (String) result.get(key);
                                    addKeyValuePair(items, val, key);
                                }
                                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
                            }
                        }
                    } else {
                        Window.alert(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        ModuleSearchInterfaceAsync service = null;
        try {
            service = ((ModuleSearchInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.ModuleSearchInterface"));
        } catch (Exception e) {
        }

        service.Picklist(req, new AsyncCallback<HashMap<Integer, String>>() {
            public void onSuccess(HashMap<Integer, String> result) {

                Set<Integer> keys = result.keySet();
                Iterator<Integer> iter = keys.iterator();

                List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>();
                map.clear();
                while (iter.hasNext()) {
                    Integer keyInt = (Integer) iter.next();
                    String key = keyInt.toString();
                    // Log.debug("keyInt = " + keyInt.toString());
                    String val = (String) result.get(keyInt);
                    addKeyValuePair(items, val, key);
                }
                cb.onSuggestionsReady(r, new SuggestOracle.Response(items));
            }

            public void onFailure(Throwable t) {
                Window.alert(t.getMessage());
            }

        });
    }
}

From source file:org.freemedsoftware.gwt.client.widget.ModuleSearchWidget.java

License:Open Source License

@Override
public void getTextForValue(String val) {
    if (!val.equalsIgnoreCase("")) {
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            searchBox.setText("Hackenbush, Hugo Z (STUB)");
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            textBox.setEnabled(false);//from   w  ww.  j a v a 2 s .  com
            String[] params = { val };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.ModuleSearch.ToText", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                        textBox.setEnabled(true);
                        Window.alert(ex.toString());
                    }

                    public void onResponseReceived(com.google.gwt.http.client.Request request,
                            com.google.gwt.http.client.Response response) {
                        textBox.setEnabled(true);
                        if (Util.checkValidSessionResponse(response.getText())) {
                            if (200 == response.getStatusCode()) {
                                String result = (String) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(response.getText()), "String");
                                if (result != null) {
                                    searchBox.setText(result);
                                    if (callback != null) {
                                        callback.jsonifiedData("done");
                                    }
                                }
                            } else {
                                Window.alert(response.toString());
                            }
                        }
                    }
                });
            } catch (RequestException e) {
                textBox.setEnabled(true);
                Window.alert(e.toString());
            }
        }
    }
}

From source file:org.freemedsoftware.gwt.client.widget.MultiPageForm.java

License:Open Source License

/**
 * Perform RPC calls to load form based on record id.
 * /*  w w  w. j a  va2  s .c o m*/
 * @param form
 */
public void loadFormFromServer(Integer form) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // STUB
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "XmrDefinition", JsonUtil.jsonify(form) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleGetRecordMethod", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("XmrDefinition", _("Failed to load data."));
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    JsonUtil.debug("onResponseReceived");
                    if (200 == response.getStatusCode()) {
                        JsonUtil.debug(response.getText());
                        HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                        if (r != null) {
                            populateFormDefinition(r);
                        }
                    } else {
                        Util.showErrorMsg("XmrDefinition", _("Failed to load data."));
                    }
                }
            });
        } catch (RequestException e) {
            Window.alert(e.toString());
        }
    } else {
        ModuleInterfaceAsync service = null;
        try {
            service = (ModuleInterfaceAsync) Util
                    .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface");
        } catch (Exception e) {
            JsonUtil.debug(e.toString());
            Util.showErrorMsg("XmrDefinition", _("Failed to load data."));
        }
        service.ModuleGetRecordMethod("XmrDefinition", form, new AsyncCallback<HashMap<String, String>>() {
            public void onSuccess(HashMap<String, String> r) {
                populateFormDefinition(r);
            }

            public void onFailure(Throwable t) {
                Util.showErrorMsg("XmrDefinition", _("Failed to load data."));
            }
        });
    }
}