List of usage examples for com.google.gwt.http.client RequestBuilder POST
Method POST
To view the source code for com.google.gwt.http.client RequestBuilder POST.
Click Source Link
From source file:org.freemedsoftware.gwt.client.widget.PatientProblemList.java
License:Open Source License
public void deleteItem(Integer item, HashMap<String, String> data) { final String module = data.get("module"); final Integer internalId = Integer.parseInt(data.get("oid")); if (Util.getProgramMode() == ProgramMode.STUBBED) { } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { module, JsonUtil.jsonify(internalId) }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode( Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleDeleteMethod", params))); try {/*from w ww . j a v a 2 s . c o m*/ builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { JsonUtil.debug(ex.toString()); CurrentState.getToaster().addItem(module, _("Unable to remove entry."), Toaster.TOASTER_ERROR); } public void onResponseReceived(Request request, Response response) { JsonUtil.debug("onResponseReceived"); if (Util.checkValidSessionResponse(response.getText())) { if (200 == response.getStatusCode()) { JsonUtil.debug(response.getText()); Boolean r = (Boolean) JsonUtil .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean"); if (r) { loadData(); CurrentState.getToaster().addItem(module, _("Removed item."), Toaster.TOASTER_INFO); } else { CurrentState.getToaster().addItem(module, _("Unable to remove entry."), Toaster.TOASTER_ERROR); } } else { JsonUtil.debug(response.toString()); CurrentState.getToaster().addItem(module, _("Unable to remove entry."), Toaster.TOASTER_ERROR); } } } }); } catch (RequestException e) { JsonUtil.debug(e.toString()); CurrentState.getToaster().addItem(module, _("Unable to remove entry."), Toaster.TOASTER_ERROR); } } else { ModuleInterfaceAsync service = null; try { service = (ModuleInterfaceAsync) Util .getProxy("org.freemedsoftware.gwt.client.Api.ModuleInterface"); } catch (Exception e) { GWT.log("Failed to get proxy for ModuleInterface", e); } service.ModuleDeleteMethod(module, internalId, new AsyncCallback<Integer>() { @Override public void onFailure(Throwable caught) { JsonUtil.debug(caught.toString()); CurrentState.getToaster().addItem(module, _("Unable to remove entry."), Toaster.TOASTER_ERROR); } @Override public void onSuccess(Integer result) { loadData(); CurrentState.getToaster().addItem(module, _("Removed item."), Toaster.TOASTER_INFO); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientProblemList.java
License:Open Source License
@SuppressWarnings("unchecked") public void loadData() { // Clear mappings during populate selected.clear();//from ww w . ja v a 2 s .c o m actionBarMap.clear(); if (patientId.intValue() == 0) { JsonUtil.debug("ERROR: patientId not defined when loadData called for PatientProblemList"); } if (Util.getProgramMode() == ProgramMode.STUBBED) { List<HashMap<String, String>> a = new ArrayList<HashMap<String, String>>(); { HashMap<String, String> item = new HashMap<String, String>(); item.put("stamp", "2008-01-01"); item.put("type", "test"); item.put("summary", "Test item 1"); item.put("module", "ProgressNotes"); a.add(item); } { HashMap<String, String> item = new HashMap<String, String>(); item.put("stamp", "2008-01-02"); item.put("type", "test"); item.put("summary", "Test item 2"); item.put("module", "ProgressNotes"); a.add(item); } { HashMap<String, String> item = new HashMap<String, String>(); item.put("stamp", "2008-01-02"); item.put("type", "test"); item.put("summary", "Test item 3"); item.put("module", "Letters"); a.add(item); } { HashMap<String, String> item = new HashMap<String, String>(); item.put("stamp", "2008-01-03"); item.put("type", "test"); item.put("summary", "Test item 4"); item.put("module", "Letters"); a.add(item); } dataStore = (HashMap<String, String>[]) a.toArray(new HashMap<?, ?>[0]); populateData(dataStore); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { patientId.toString() }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util .getJsonRequest("org.freemedsoftware.api.PatientInterface.EmrAttachmentsByPatient", 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) { JsonUtil.debug("onResponseReceived"); if (Util.checkValidSessionResponse(response.getText())) { 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) { JsonUtil.debug( "PatientProblemList... r.length = " + new Integer(r.length).toString()); dataStore = r; populateData(dataStore); } } else { Window.alert(response.toString()); } } } }); } catch (RequestException e) { Window.alert(e.toString()); } } else { PatientInterfaceAsync service = null; try { service = (PatientInterfaceAsync) Util .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface"); } catch (Exception e) { GWT.log("Failed to get proxy for PatientInterface", e); } service.EmrAttachmentsByPatient(patientId, new AsyncCallback<HashMap<String, String>[]>() { public void onSuccess(HashMap<String, String>[] r) { dataStore = r; populateData(dataStore); } public void onFailure(Throwable t) { GWT.log("Exception", t); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java
License:Open Source License
/** * Update database to set new tag./*from w ww . j a v a2s. com*/ * * @param tag */ public void addTag(final String tag) { if (Util.getProgramMode() == ProgramMode.STUBBED) { wEntry.clear(); addTagToDisplay(tag); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { JsonUtil.jsonify(patientId), tag }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.CreateTag", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { Util.showInfoMsg("PatientTags", _("Failed to add tags.")); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { Boolean r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean"); if (r != null) { wEntry.clear(); addTagToDisplay(tag); Util.showInfoMsg("PatientTags", _("Tag added.")); } } else { Util.showErrorMsg("PatientTags", _("Failed to add tags.")); } } }); } catch (RequestException e) { Util.showErrorMsg("PatientTags", _("Failed to add tags.")); } } else { getProxy().CreateTag(patientId, tag, new AsyncCallback<Boolean>() { public void onSuccess(Boolean o) { wEntry.clear(); addTagToDisplay(tag); Util.showInfoMsg("PatientTags", _("Tag added.")); } public void onFailure(Throwable t) { GWT.log("Exception", t); Util.showErrorMsg("PatientTags", _("Failed to add tags.")); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java
License:Open Source License
/** * Actual addition of tag to display./*w w w . j ava2 s. c o m*/ * * @param tag */ protected void addTagToDisplay(String tag) { JsonUtil.debug("addTagToDisplay(" + tag + ")"); HorizontalPanel p = new HorizontalPanel(); p.setTitle(tag); final String oldTagName = tag.trim(); final HTML r = new HTML("<sup>X</sup>"); final Anchor tagLabel = new Anchor(tag); tagLabel.setStylePrimaryName("freemed-PatientTag"); JsonUtil.debug("addclicklistener"); tagLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent evt) { final Widget w = (Widget) evt.getSource(); final PopupPanel p = new PopupPanel(true); final FlexTable fT = new FlexTable(); fT.setWidget(0, 0, new HTML("<b>" + oldTagName + "</b>")); fT.setWidget(1, 0, new Label(_("Rename Tag"))); final TextBox newTagName = new TextBox(); fT.setWidget(2, 0, newTagName); final CustomButton changeTagButton = new CustomButton(_("Change"), AppConstants.ICON_MODIFY); fT.setWidget(2, 1, changeTagButton); changeTagButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent bEvt) { if (newTagName.getText().trim().length() > 0) { if (Util.getProgramMode() == ProgramMode.STUBBED) { // Stubbed mode p.hide(); p.removeFromParent(); ((HorizontalPanel) w.getParent()).removeFromParent(); addTagToDisplay(newTagName.getText().trim()); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { oldTagName, newTagName.getText().trim() }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest( "org.freemedsoftware.module.PatientTag.ChangeTag", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { Boolean r = (Boolean) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "Boolean"); if (r != null) { p.hide(); p.removeFromParent(); ((HorizontalPanel) w.getParent()).removeFromParent(); addTagToDisplay(newTagName.getText().trim()); } } else { } } }); } catch (RequestException e) { } } else { getProxy().ChangeTag(oldTagName, newTagName.getText().trim(), new AsyncCallback<Boolean>() { public void onSuccess(Boolean o) { p.hide(); p.removeFromParent(); ((HorizontalPanel) w.getParent()).removeFromParent(); addTagToDisplay(newTagName.getText().trim()); } public void onFailure(Throwable t) { GWT.log("Exception", t); } }); } } } }); final CustomButton searchButton = new CustomButton(_("Search"), AppConstants.ICON_SEARCH); fT.setWidget(2, 2, searchButton); searchButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent evt) { PatientTagSearchScreen searchScreen = new PatientTagSearchScreen(); searchScreen.setTagValue(oldTagName); Util.spawnTab(_("Tag Search"), searchScreen); p.hide(); } }); p.add(fT); p.setPopupPosition(tagLabel.getAbsoluteLeft() + 5, tagLabel.getAbsoluteTop() - 10); p.setStyleName("freemed-PatientTagPopup"); p.show(); } }); p.add(tagLabel); p.add(r); p.setStyleName("freemed-PatientTag"); r.addStyleName("freemed-PatientTagRemove"); r.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent evt) { if (Window.confirm("Are you sure you want to remove this tag?")) { HorizontalPanel container = (HorizontalPanel) ((Widget) evt.getSource()).getParent(); removeTag(container.getTitle(), container); } } }); flowPanel.add(p); }
From source file:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java
License:Open Source License
/** * Update database to remove tag./*from ww w .j av a 2 s . co m*/ * * @param tag */ public void removeTag(String tag, final HorizontalPanel hp) { if (Util.getProgramMode() == ProgramMode.STUBBED) { hp.removeFromParent(); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { JsonUtil.jsonify(patientId), tag }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.ExpireTag", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { Util.showErrorMsg("PatientTags", _("Failed to remove tag.")); } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { Boolean r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean"); if (r != null) { hp.removeFromParent(); Util.showInfoMsg("PatientTags", _("Tag removed.")); } } else { Util.showErrorMsg("PatientTags", _("Failed to remove tag.")); } } }); } catch (RequestException e) { Util.showErrorMsg("PatientTags", _("Failed to remove tag.")); } } else { getProxy().ExpireTag(patientId, tag, new AsyncCallback<Boolean>() { public void onSuccess(Boolean o) { hp.removeFromParent(); Util.showErrorMsg("PatientTags", _("Tag removed.")); } public void onFailure(Throwable t) { GWT.log("Exception", t); Util.showErrorMsg("PatientTags", _("Failed to remove tag.")); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientTagsWidget.java
License:Open Source License
/** * Populate the widget via RPC.// w w w.ja va2s . c o m */ protected void populate() { if (Util.getProgramMode() == ProgramMode.STUBBED) { addTagToDisplay("testTag1"); addTagToDisplay("Diabetes"); addTagToDisplay("LatePayment"); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { JsonUtil.jsonify(patientId) }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL .encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.TagsForPatient", params))); try { builder.sendRequest(null, new RequestCallback() { public void onError(Request request, Throwable ex) { } public void onResponseReceived(Request request, Response response) { if (200 == response.getStatusCode()) { JsonUtil.debug(response.getText()); String[] r = (String[]) JsonUtil .shoehornJson(JSONParser.parseStrict(response.getText()), "String[]"); if (r != null) { for (int iter = 0; iter < r.length; iter++) { addTagToDisplay(r[iter]); } } } else { } } }); } catch (RequestException e) { } } else { getProxy().TagsForPatient(patientId, new AsyncCallback<String[]>() { public void onSuccess(String[] tags) { for (int iter = 0; iter < tags.length; iter++) { addTagToDisplay(tags[iter]); } } public void onFailure(Throwable t) { GWT.log("Exception", t); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientTagWidget.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();/*from w w w. j a v a2 s. co m*/ addKeyValuePair(items, new String("Diabetes"), new String("Diabetes")); addKeyValuePair(items, new String("Neuropathy"), new String("Neuropathy")); cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { req }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.PatientTag.ListTags", params))); try { 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 (Util.checkValidSessionResponse(response.getText())) { if (200 == response.getStatusCode()) { HashMap<String, String> result = (HashMap<String, String>) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<String,String>"); if (result != null) { List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear(); Iterator<String> iter = result.values().iterator(); while (iter.hasNext()) { String x = iter.next(); addKeyValuePair(items, x, x); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } } else { GWT.log("Result " + response.getStatusText(), null); } } } }); } catch (RequestException e) { GWT.log("Exception thrown: ", e); } } else { PatientTagAsync service = null; try { service = ((PatientTagAsync) Util.getProxy("org.freemedsoftware.gwt.client.Module.PatientTag")); } catch (Exception e) { } service.ListTags(req, new AsyncCallback<HashMap<String, String>>() { @Override public void onSuccess(HashMap<String, String> result) { List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear(); Iterator<String> iter = result.values().iterator(); while (iter.hasNext()) { String x = iter.next(); addKeyValuePair(items, x, x); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } public void onFailure(Throwable t) { GWT.log("Exception thrown: ", t); Util.showErrorMsg("PatientTagWidget", "Exception: " + t.toString()); } }); } }
From source file:org.freemedsoftware.gwt.client.widget.PatientWidget.java
License:Open Source License
protected void loadSuggestions(String req, final Request r, final Callback cb) { if (req.length() < CurrentState.getMinCharCountForSmartSearch()) return;/*from www.jav a 2 s . c om*/ if (Util.getProgramMode() == ProgramMode.STUBBED) { // Handle in a stubbed sort of way List<SuggestOracle.Suggestion> items = new ArrayList<SuggestOracle.Suggestion>(); map.clear(); 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) { String[] params = { req, new Integer(20).toString() }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.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<Integer, String> result = (HashMap<Integer, String>) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<Integer,String>"); if (result != null) { 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(); String val = (String) result.get(keyInt); addKeyValuePair(items, val, key); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } } } else { Window.alert(response.toString()); } } }); } catch (RequestException e) { Window.alert(e.toString()); } } else { PatientInterfaceAsync service = null; try { service = ((PatientInterfaceAsync) Util .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface")); } catch (Exception e) { } service.Picklist(req, new Integer(20), 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.PatientWidget.java
License:Open Source License
@Override public void getTextForValue(Integer val) { if (val > 0) { if (Util.getProgramMode() == ProgramMode.STUBBED) { searchBox.setText("Hackenbush, Hugo Z (STUB)"); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { textBox.setEnabled(false);//w ww .j a v a 2s. co m String[] params = { val.toString() }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.api.PatientInterface.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()); } } else { PatientInterfaceAsync service = null; try { service = ((PatientInterfaceAsync) Util .getProxy("org.freemedsoftware.gwt.client.Api.PatientInterface")); } catch (Exception e) { } textBox.setEnabled(false); service.ToText(val, true, new AsyncCallback<String>() { public void onSuccess(String r) { textBox.setEnabled(true); searchBox.setText(r); } public void onFailure(Throwable t) { textBox.setEnabled(true); GWT.log("Exception", t); } }); } } }
From source file:org.freemedsoftware.gwt.client.widget.PharmacyWidget.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();/*from w ww . j a v a 2 s.c o m*/ addKeyValuePair(items, new String("Cranston GOP (Cranston, RI)"), new String("1")); cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } else if (Util.getProgramMode() == ProgramMode.JSONRPC) { String[] params = { req, new Integer(20).toString() }; RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(Util.getJsonRequest("org.freemedsoftware.module.Pharmacy.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<Integer, String> result = (HashMap<Integer, String>) JsonUtil.shoehornJson( JSONParser.parseStrict(response.getText()), "HashMap<Integer,String>"); if (result != null) { 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(); String val = (String) result.get(keyInt); addKeyValuePair(items, val, key); } cb.onSuggestionsReady(r, new SuggestOracle.Response(items)); } } } else { Window.alert(response.toString()); } } }); } catch (RequestException e) { Window.alert(e.toString()); } } else { // TODO GWT CODE GOES HERE } }