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

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

Introduction

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

Prototype

public Request sendRequest(String requestData, RequestCallback callback) throws RequestException 

Source Link

Document

Sends an HTTP request based on the current builder configuration with the specified data and callback.

Usage

From source file:org.freemedsoftware.gwt.client.screen.ModuleFieldCheckerTypeEntryScreen.java

License:Open Source License

public void retrieveAndFillListData() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: STUBBED
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // JSON-RPC
        String[] params = {};/*from  w  w  w  . j  a v  a2s . c om*/
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module." + MODULE_NAME + ".GetRecords", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    JsonUtil.debug("Error on retrieving data");
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        if (response.getText().compareToIgnoreCase("false") != 0) {
                            HashMap<String, String>[] result = (HashMap<String, String>[]) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()),
                                            "HashMap<String,String>[]");
                            if (result != null) {
                                containerModuleFieldCheckerTypeTable.loadData(result);

                            }
                        } else {
                            JsonUtil.debug("Received dummy response from JSON backend");
                        }
                    } else {
                        Util.showErrorMsg(moduleName, _("Failed to get items!"));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg(moduleName, _("Failed to get items!"));
        }
    } else {
        // GWT-RPC
    }
}

From source file:org.freemedsoftware.gwt.client.screen.ModuleFieldCheckerTypeEntryScreen.java

License:Open Source License

public void saveFormData(final String moduleName, HashMap<String, String> data, boolean isModify) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: STUBBED
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // JSON-RPC
        String moduleURL = "org.freemedsoftware.module." + moduleName + (isModify ? ".Mod" : ".Add");
        String[] params = { JsonUtil.jsonify(data) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest(moduleURL, params)));
        try {//from  w w  w  . j a v  a  2 s  . c  om
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Integer r = (Integer) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Integer");
                        if (r != null) {
                            populateAvailableData();
                            Util.showInfoMsg(moduleName, _("Entry successfully added."));
                        } else {
                            Boolean b = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (b != null)
                                Util.showInfoMsg(moduleName, _("Entry successfully modified."));
                        }
                    } else {
                        Util.showErrorMsg(moduleName, _("Failed to save data!"));
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // GWT-RPC
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.AllergyEntryScreen.java

License:Open Source License

public void saveForm() {
    data.put("patient", patientScreen.getPatient().toString());

    data.put("allergy", allergyTextBox.getText());
    data.put("reaction", reactionTextBox.getText());
    data.put("severity", severityTextBox.getText());

    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        Util.showInfoMsg(className, _("Allergy added."));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(data) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Allergies.add", params)));
        try {// w  ww .j  a  v a  2 s  .  c  o m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg(className, _("Failed to add allergy."));
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        Integer r = (Integer) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Integer");
                        if (r != null) {
                            Util.showInfoMsg(className, _("Allergy added."));
                            patientScreen.getSummaryScreen().populateClinicalInformation();
                        }
                    } else {
                        Util.showErrorMsg(className, _("Failed to add allergy."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg(className, _("Failed to add allergy."));
        }
    } else {
        // TODO: GWT-RPC Stuff
    }

}

From source file:org.freemedsoftware.gwt.client.screen.patient.AllergyEntryScreen.java

License:Open Source License

public void populate() {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(patientId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Allergies.GetMostRecent", params)));
        try {//from w w  w .  j a va  2  s.com
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        @SuppressWarnings("unchecked")
                        HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (r != null) {
                            allergyTextBox.setText(r[0].get("allergy"));
                            reactionTextBox.setText(r[0].get("reaction"));
                            severityTextBox.setText(r[0].get("severity"));
                        }
                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.ClinicalOrdersEntry.java

License:Open Source License

public void save() {
    HashMap<String, String> data = new HashMap<String, String>();
    data.put("patient", Integer.toString(patientId));

    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // TODO: STUBBED
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        // JSON-RPC
        String[] params = { JsonUtil.jsonify(data) };

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.ClinicalOrders.add", params)));
        try {// w  ww . java2 s . co m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("ClinicalOrdersEntry", _("Failed to add order."));
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {
                        if (response.getText().compareToIgnoreCase("false") != 0) {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (r != null) { // Successful
                                Util.showInfoMsg("ClinicalOrdersEntry", _("Successfully added order."));
                            }
                        } else {
                            JsonUtil.debug("Received dummy response from JSON backend");
                        }
                    } else {
                        Util.showErrorMsg("ClinicalOrdersEntry", _("Failed to add orders."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("ClinicalOrdersEntry", _("Failed to add orders."));
        }

    } else {
        // GWT-RPC
    }

}

From source file:org.freemedsoftware.gwt.client.screen.patient.EncounterScreen.java

License:Open Source License

public void loadEncountersList() {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {

        String[] params = { patientId.toString() };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.EncounterNotes.getEncountersList", params)));

        try {/*from   w w w  .j  a va2 s .  c  om*/
            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()) {
                        try {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                enotesCustomTable.loadData(r);
                            } else {

                            }
                        } catch (Exception e) {

                        }

                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.EncounterScreen.java

License:Open Source License

public void laodEncounterNoteInfo(String id) {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { id };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.EncounterNotes.getEncounterNoteInfo", params)));

        try {/*from   w  w  w  .j  a v  a2 s .  c om*/
            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()) {
                        try {
                            HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (r != null) {
                                moddata = r;
                                if (r.get("pnotestemplate") == null || r.get("pnotestemplate").equals("")
                                        || r.get("pnotestemplate").equals("0")) {

                                    entryVerticalPanel.clear();
                                    createEncounterNotesAdditionTab();

                                } else {
                                    getTemplateValues(moddata.get("pnotestemplate"));
                                }
                            } else {
                            }
                        } catch (Exception e) {
                        }

                    } else {
                    }
                }
            });
        } catch (RequestException e) {
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.EncounterScreen.java

License:Open Source License

public void getTemplateValues(String templateId) {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { templateId };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util
                .getJsonRequest("org.freemedsoftware.module.EncounterNotesTemplate.getTemplateInfo", params)));

        try {/*from  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()) {
                        try {
                            HashMap<String, String> r = (HashMap<String, String>) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>");
                            if (r != null) {
                                String secStr = r.get("pnotestsections");
                                sections = (HashMap<String, List<String>>) JsonUtil
                                        .shoehornJson(JSONParser.parseStrict(secStr), "HashMap<String,List>");
                                entryVerticalPanel.clear();
                                createEncounterNotesAdditionTab();
                            } else {

                            }
                        } catch (Exception e) {

                        }

                    } else {

                    }
                }
            });
        } catch (RequestException e) {
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.EncounterScreen.java

License:Open Source License

public void deleteNote(String id) {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { id };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.EncounterNotes.del", params)));

        try {//from w  w w.  j  ava2 s.  com
            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 r = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (r) {
                                Util.showInfoMsg("EncounterNotes", _("Encounter Note successfully deleted."));
                                loadEncountersList();
                            }

                        } catch (Exception e) {

                        }

                    } else {

                    }
                }
            });
        } catch (RequestException e) {
        }
    }
}

From source file:org.freemedsoftware.gwt.client.screen.patient.GrowthChartScreen.java

License:Open Source License

public void populateStockData(boolean height, final GrowthChart chart) {
    Boolean infant = false;//from ww w  .  ja  v  a 2s  .co  m
    if (getMonthsAge(birthDate) < 36) {
        infant = true;
    } else {
        infant = false;
    }

    if (Util.getProgramMode() == ProgramMode.STUBBED) {
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { gender, JsonUtil.jsonify(height), JsonUtil.jsonify(infant) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.GrowthCharts.GetGrowthChartValues", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("GrowthCharts", "Failed to retrieve stock growth chart data.");
                }

                @SuppressWarnings("unchecked")
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode() || response.getText() == "false") {
                        HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                        if (r != null) {
                            chart.setStockData(r);
                            chart.drawStockCurves();
                        }
                    } else {
                        Util.showErrorMsg("GrowthCharts", _("Failed to retrieve stock growth chart data."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("GrowthCharts", _("Failed to retrieve stock growth chart data."));
        }
    } else {
        JsonUtil.debug("Unimplemented GrowthCharts RPC");
    }

}