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.screen.TriageScreen.java

License:Open Source License

/**
 * Called to request migrating a clinicregistration table entry to being
 * associated with an existing patient table entry. Is completely backend
 * functional, has no UI pieces of any import.
 * /*from ww  w.  j a v  a2 s . c o m*/
 * @param clinicRegistrationId
 * @param patientId
 */
protected void migrateToPatient(Integer clinicRegistrationId, Integer patientId) {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { JsonUtil.jsonify(clinicRegistrationId), JsonUtil.jsonify(patientId) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.module.ClinicRegistration.migrateToPatient", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            Boolean r = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (r != null) {
                            }
                        } else {
                        }

                        // Force refresh after migrate is complete.
                        loadData();
                    }
                }
            });
        } catch (RequestException e) {
            JsonUtil.debug(e.getMessage());
        }
    } else {
        JsonUtil.debug("NOT IMPLEMENTED YET");
    }
}

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

License:Open Source License

/**
 * Load table entries and reset form.// w  ww .  ja  va  2  s.  com
 */
@SuppressWarnings("unchecked")
protected void loadData() {
    flexTable.setVisible(false);
    mainHorizontalPanel.setVisible(true);
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
        results.add(new HashMap<String, String>() {
            private static final long serialVersionUID = -208742530745599186L;
            {
                // FIXME: need test values
                put("id", "1");
                put("uffdate", "2008-08-10");
                put("ufffilename", "testFile1.pdf");
            }
        });
        results.add(new HashMap<String, String>() {
            private static final long serialVersionUID = -2068691951700967021L;
            {
                // FIXME: need test values
                put("id", "2");
                put("uffdate", "2008-08-25");
                put("ufffilename", "testFile2.pdf");
            }
        });
        wTriagePendingList.loadData(results.toArray((HashMap<String, String>[]) new HashMap<?, ?>[0]));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        wTriagePendingList.showloading(true);
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                .encode(Util.getJsonRequest("org.freemedsoftware.module.ClinicRegistration.GetAll", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    wTriagePendingList.showloading(false);
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                store = r;
                                wTriagePendingList.loadData(r);
                            }
                        } else {
                            wTriagePendingList.showloading(false);
                        }
                    }
                }
            });
        } catch (RequestException e) {
            JsonUtil.debug(e.getMessage());
            wTriagePendingList.showloading(false);
        }
    } else {
        JsonUtil.debug("NOT IMPLEMENTED YET");
        /*
         * getDocumentsProxy().GetAll( new AsyncCallback<HashMap<String,
         * String>[]>() { public void onSuccess(HashMap<String, String>[]
         * res) { store = res; wTriagePendingList.loadData(res); }
         * 
         * public void onFailure(Throwable t) { GWT.log("Exception", t); }
         * });
         */
    }
}

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

License:Open Source License

public UnfiledDocuments() {
    super(moduleName);
    VerticalPanel parentVp = new VerticalPanel();
    parentVp.setSize("10o%", "100%");
    initWidget(parentVp);/*from   w  ww.j  a  v  a2s .  c o  m*/
    mainHorizontalPanel = new HorizontalPanel();
    parentVp.add(mainHorizontalPanel);

    mainHorizontalPanel.setSize("100%", "100%");

    batchSplitVp = new VerticalPanel();
    batchSplitVp.setSize("100%", "100%");
    batchSplitVp.setVisible(false);
    parentVp.add(batchSplitVp);
    final VerticalPanel verticalPanel = new VerticalPanel();
    mainHorizontalPanel.add(verticalPanel);
    verticalPanel.setSize("100%", "100%");

    wDocuments = new CustomTable();
    verticalPanel.add(wDocuments);
    wDocuments.setIndexName("id");
    wDocuments.addColumn(_("Date"), "uffdate");
    wDocuments.addColumn(_("Filename"), "ufffilename");
    wDocuments.addColumn(_("Action"), "action");
    wDocuments.setTableWidgetColumnSetInterface(new TableWidgetColumnSetInterface() {
        public Widget setColumn(String columnName, HashMap<String, String> data) {
            // Render only action column, otherwise skip renderer
            if (columnName.compareToIgnoreCase("action") != 0) {
                return null;
            }
            final CustomActionBar actionBar = new CustomActionBar(data);
            actionBar.applyPermissions(false, false, true, false, false);
            actionBar.setHandleCustomAction(new HandleCustomAction() {
                @Override
                public void handleAction(int id, HashMap<String, String> data, int action) {
                    if (action == HandleCustomAction.DELETE) {
                        try {
                            String[] params = { "" + id };
                            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                                    URL.encode(Util.getJsonRequest(
                                            "org.freemedsoftware.module.UnfiledDocuments.del", 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()) {
                                                try {
                                                    Boolean result = (Boolean) JsonUtil.shoehornJson(
                                                            JSONParser.parseStrict(response.getText()),
                                                            "Boolean");
                                                    if (result) {
                                                        Util.showInfoMsg("UnfiledDocuments",
                                                                _("Document successfully deleted."));
                                                        loadData();
                                                    }
                                                } catch (Exception e) {
                                                    Util.showErrorMsg("UnfiledDocuments",
                                                            _("Document failed to delete."));
                                                }
                                            } else {
                                                Util.showErrorMsg("UnfiledDocuments",
                                                        _("Document failed to delete."));
                                            }
                                        }
                                    }
                                });
                            } catch (RequestException e) {
                                Util.showErrorMsg("UnfiledDocuments", _("Document failed to delete."));
                            }
                        } catch (Exception e) {
                            Util.showErrorMsg("UnfiledDocuments", _("Document failed to delete"));
                        }
                    }
                }
            });

            // Push value back to table
            return actionBar;
        }
    });
    wDocuments.setTableRowClickHandler(new TableRowClickHandler() {
        @Override
        public void handleRowClick(HashMap<String, String> data, int col) {
            if (col == 0 || col == 1) {
                // Import current id
                try {
                    currentId = Integer.parseInt(data.get("id"));
                } catch (Exception ex) {
                    GWT.log("Exception", ex);
                } finally {
                    if (canWrite) {
                        // Populate
                        String pDate = data.get("uffdate");
                        Calendar thisCal = new GregorianCalendar();
                        thisCal.set(Calendar.YEAR, Integer.parseInt(pDate.substring(0, 4)));
                        thisCal.set(Calendar.MONTH, Integer.parseInt(pDate.substring(5, 6)) - 1);
                        thisCal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(pDate.substring(8, 9)));
                        wDate.setValue(thisCal.getTime());

                        // Show the form
                        flexTable.setVisible(true);
                        horizontalPanel.setVisible(true);
                    }
                    if (canRead) {
                        // Show the image in the viewer
                        djvuViewer.setInternalId(currentId);
                        /*
                        try {
                           djvuViewer.loadPage(1);
                        } catch (Exception ex) {
                           JsonUtil.debug(ex.toString());
                        }
                        djvuViewer.setVisible(true);
                        */
                    }
                }
            }
        }
    });
    wDocuments.setWidth("100%");

    flexTable = new FlexTable();
    verticalPanel.add(flexTable);
    flexTable.setWidth("100%");
    flexTable.setVisible(false);

    final Label dateLabel = new Label(_("Date") + " : ");
    flexTable.setWidget(0, 0, dateLabel);

    wDate = new CustomDatePicker();
    wDate.setValue(new Date());
    flexTable.setWidget(0, 1, wDate);

    final Label patientLabel = new Label(_("Patient") + " : ");
    flexTable.setWidget(1, 0, patientLabel);

    wPatient = new PatientWidget();
    flexTable.setWidget(1, 1, wPatient);

    final Label providerLabel = new Label(_("Provider") + " : ");
    flexTable.setWidget(2, 0, providerLabel);

    wProvider = new SupportModuleWidget();
    wProvider.setModuleName("ProviderModule");
    flexTable.setWidget(2, 1, wProvider);

    final Label noteLabel = new Label(_("Note") + " : ");
    flexTable.setWidget(3, 0, noteLabel);

    wNote = new TextBox();
    flexTable.setWidget(3, 1, wNote);
    wNote.setWidth("100%");

    final Label notifyLabel = new Label(_("Notify") + " : ");
    flexTable.setWidget(4, 0, notifyLabel);

    users = new UserMultipleChoiceWidget();
    flexTable.setWidget(4, 1, users);
    //wNote.setWidth("100%");

    final Label categoryLabel = new Label(_("Category") + " : ");
    flexTable.setWidget(5, 0, categoryLabel);

    wCategory = new SupportModuleWidget();
    wCategory.setModuleName("DocumentCategory");
    flexTable.setWidget(5, 1, wCategory);

    final Label faxNumberLabel = new Label(_("Fax Confirmation Number") + " : ");
    flexTable.setWidget(6, 0, faxNumberLabel);

    faxConfirmationNumber = new TextBox();
    flexTable.setWidget(6, 1, faxConfirmationNumber);

    final Label rotateLabel = new Label(_("Rotate") + " : ");
    flexTable.setWidget(7, 0, rotateLabel);

    wRotate = new ListBox();
    flexTable.setWidget(7, 1, wRotate);
    wRotate.addItem(_("No rotation"), "0");
    wRotate.addItem(_("Rotate left"), "270");
    wRotate.addItem(_("Rotate right"), "90");
    wRotate.addItem(_("Flip"), "180");
    wRotate.setVisibleItemCount(1);

    cbRemoveFirstPage = new CheckBox(_("Remove First Page"));
    flexTable.setWidget(8, 0, cbRemoveFirstPage);
    horizontalPanel = new HorizontalPanel();
    horizontalPanel.setVisible(false);
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    verticalPanel.add(horizontalPanel);
    horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    horizontalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);

    final PushButton sendToProviderButton = new PushButton();
    sendToProviderButton.setStylePrimaryName("freemed-PushButton");
    sendToProviderButton.setHTML(_("Send to Provider"));
    sendToProviderButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (validateForm()) {
                sendToProvider();
            }
        }
    });
    horizontalPanel.add(sendToProviderButton);

    final PushButton fileDirectlyButton = new PushButton();
    fileDirectlyButton.setHTML(_("File Directly"));
    fileDirectlyButton.setStylePrimaryName("freemed-PushButton");
    fileDirectlyButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (validateForm()) {
                fileDirectly();
            }
        }
    });
    horizontalPanel.add(fileDirectlyButton);

    final PushButton splitBatchButton = new PushButton();
    splitBatchButton.setHTML(_("Split Batch"));
    splitBatchButton.setStylePrimaryName("freemed-PushButton");
    splitBatchButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (djvuViewer.getPageCount() > 1) {

                final DocumentThumbnailsWidget dtw = new DocumentThumbnailsWidget(djvuViewer,
                        new CustomRequestCallback() {
                            @Override
                            public void onError() {

                            }

                            @Override
                            public void jsonifiedData(Object data) {
                                if (data instanceof Integer) {
                                    loadData();
                                } else if (data instanceof Integer[]) {
                                    splitBatch((Integer[]) data);
                                }

                            }
                        });
                batchSplitVp.add(dtw);
                mainHorizontalPanel.setVisible(false);
                batchSplitVp.setVisible(true);

            } else if (djvuViewer.getPageCount() == 1) {
                Window.alert(_("Current document has only one page."));
            }
        }
    });
    horizontalPanel.add(splitBatchButton);
    djvuViewer = new DjvuViewer();
    djvuViewer.setType(DjvuViewer.UNFILED_DOCUMENTS);
    mainHorizontalPanel.add(djvuViewer);
    djvuViewer.setVisible(false);
    djvuViewer.setSize("100%", "100%");

    // Last thing is to initialize, otherwise we're going to get some
    // NullPointerException errors
    if (canRead)
        loadData();
}

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

License:Open Source License

protected void fileDirectly() {
    HashMap<String, String> p = new HashMap<String, String>();
    p.put((String) "id", (String) currentId.toString());
    p.put((String) "patient", (String) wPatient.getValue().toString());
    p.put((String) "category", (String) wCategory.getValue().toString());
    p.put((String) "physician", (String) wProvider.getValue().toString());
    if (cbRemoveFirstPage.getValue())
        p.put((String) "withoutfirstpage", (String) "1");
    else/*from ww w . ja v a2s  .  com*/
        p.put((String) "withoutfirstpage", (String) "");
    p.put((String) "filedirectly", (String) "1");
    p.put((String) "note", (String) wNote.getText());
    p.put((String) "faxback", (String) faxConfirmationNumber.getText());
    p.put((String) "flip", (String) wRotate.getValue(wRotate.getSelectedIndex()));
    if (users.getCommaSeparatedValues() != null)
        p.put((String) "notify", users.getCommaSeparatedValues());
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        CurrentState.getToaster().addItem("UnfiledDocuments", "Processed unfiled document.",
                Toaster.TOASTER_INFO);
        loadData();
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "UnfiledDocuments", JsonUtil.jsonify(p) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleModifyMethod", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    CurrentState.getToaster().addItem("UnfiledDocuments", _("Failed to file document."),
                            Toaster.TOASTER_ERROR);
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                Util.showInfoMsg("UnfiledDocuments", _("Processed unfiled document."));
                                loadData();
                            }
                        } else {
                            Util.showErrorMsg("UnfiledDocuments", _("Failed to file document."));
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("UnfiledDocuments", _("Failed to file document."));
        }
    } else {
        getModuleProxy().ModuleModifyMethod("UnfiledDocuments", p, new AsyncCallback<Integer>() {
            public void onSuccess(Integer o) {
                Util.showInfoMsg("UnfiledDocuments", _("Processed unfiled document."));
                loadData();
            }

            public void onFailure(Throwable t) {
                Util.showErrorMsg("UnfiledDocuments", _("Failed to file document."));
                GWT.log("Exception", t);
            }
        });
    }
}

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

License:Open Source License

/**
 * Load table entries and reset form./*ww  w  .  j av  a 2 s.  com*/
 */
@SuppressWarnings("unchecked")
protected void loadData() {
    batchSplitVp.setVisible(false);
    batchSplitVp.clear();
    djvuViewer.setVisible(false);
    flexTable.setVisible(false);
    horizontalPanel.setVisible(false);
    mainHorizontalPanel.setVisible(true);
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
        {
            HashMap<String, String> item = new HashMap<String, String>();
            item.put("id", "1");
            item.put("uffdate", "2008-08-10");
            item.put("ufffilename", "testFile1.pdf");
            results.add(item);
        }
        {
            HashMap<String, String> item = new HashMap<String, String>();
            item.put("id", "2");
            item.put("uffdate", "2008-08-25");
            item.put("ufffilename", "testFile2.pdf");
            results.add(item);
        }
        wDocuments.loadData(results.toArray((HashMap<String, String>[]) new HashMap<?, ?>[0]));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        wDocuments.showloading(true);
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.UnfiledDocuments.GetAll", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                store = r;
                                wDocuments.loadData(r);
                            }
                        } else {
                            wDocuments.showloading(false);
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        getDocumentsProxy().GetAll(new AsyncCallback<HashMap<String, String>[]>() {
            public void onSuccess(HashMap<String, String>[] res) {
                store = res;
                wDocuments.loadData(res);
            }

            public void onFailure(Throwable t) {
                GWT.log("Exception", t);
            }
        });
    }
}

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

License:Open Source License

protected void sendToProvider() {
    HashMap<String, String> p = new HashMap<String, String>();
    p.put((String) "id", (String) currentId.toString());
    p.put((String) "patient", (String) wPatient.getValue().toString());
    p.put((String) "category", (String) "");
    p.put((String) "physician", (String) wProvider.getValue().toString());
    if (cbRemoveFirstPage.getValue())
        p.put((String) "withoutfirstpage", (String) "1");
    else/*from  w  w w  .  j  av a  2 s.  c  o  m*/
        p.put((String) "withoutfirstpage", (String) "");
    p.put((String) "filedirectly", (String) "0");
    p.put((String) "note", (String) wNote.getText());
    p.put((String) "faxback", (String) faxConfirmationNumber.getText());
    p.put((String) "flip", (String) wRotate.getValue(wRotate.getSelectedIndex()));
    if (users.getCommaSeparatedValues() != null)
        p.put((String) "notify", users.getCommaSeparatedValues());
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        CurrentState.getToaster().addItem("UnfiledDocuments", "Processed unfiled document.",
                Toaster.TOASTER_INFO);
        loadData();
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { "UnfiledDocuments", JsonUtil.jsonify(p) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode(
                Util.getJsonRequest("org.freemedsoftware.api.ModuleInterface.ModuleModifyMethod", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("UnfiledDocuments", _("Failed to send document to provider."));
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            Integer r = (Integer) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Integer");
                            if (r != null) {
                                Util.showInfoMsg("UnfiledDocuments", _("Sent to provider."));
                            }
                        } else {
                            Util.showErrorMsg("UnfiledDocuments", _("Failed to send document to provider."));
                        }
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("UnfiledDocuments", _("Failed to send document to provider."));
        }
    } else {
        getModuleProxy().ModuleModifyMethod("UnfiledDocuments", p, new AsyncCallback<Integer>() {
            public void onSuccess(Integer o) {
                Util.showInfoMsg("UnfiledDocuments", _("Sent to provider."));
            }

            public void onFailure(Throwable t) {
                Util.showErrorMsg("UnfiledDocuments", _("Failed to send document to provider."));
            }
        });
    }
}

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

License:Open Source License

public void splitBatch(Integer[] pageNos) {
    if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = { currentId.toString(), JsonUtil.jsonify(pageNos) };
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL
                .encode(Util.getJsonRequest("org.freemedsoftware.module.UnfiledDocuments.batchSplit", params)));
        try {// w ww .  j a  v a 2 s .co  m
            builder.sendRequest(null, new RequestCallback() {
                public void onError(com.google.gwt.http.client.Request request, Throwable ex) {
                    Util.showErrorMsg("UnfiledDocuments", _("Document failed to split."));
                }

                public void onResponseReceived(com.google.gwt.http.client.Request request,
                        com.google.gwt.http.client.Response response) {
                    if (200 == response.getStatusCode()) {
                        Boolean r = (Boolean) JsonUtil.shoehornJson(JSONParser.parseStrict(response.getText()),
                                "Boolean");
                        if (r != null && r) {
                            Util.showInfoMsg("UnfiledDocuments", _("Document successfully split."));
                            loadData();
                        } else {
                            Util.showErrorMsg("UnfiledDocuments", _("Document failed to split."));
                        }
                    } else {
                        Util.showErrorMsg("UnfiledDocuments", _("Document failed to split."));
                        JsonUtil.debug(response.toString());
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("UnfiledDocuments", _("Document failed to split."));
            JsonUtil.debug(e.toString());
        }

    } else {

    }
}

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

License:Open Source License

/**
 * Load table entries and reset form./*from   w w w .  j  a va2  s .  c  o  m*/
 */
@SuppressWarnings("unchecked")
protected void loadData() {
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        List<HashMap<String, String>> results = new ArrayList<HashMap<String, String>>();
        {
            HashMap<String, String> item = new HashMap<String, String>();
            item.put("id", "1");
            item.put("urfdate_mdy", "2008-08-10");
            item.put("patient", "abc III, def");
            item.put("urfnote", "test note 123.");
            results.add(item);
        }
        {
            HashMap<String, String> item = new HashMap<String, String>();
            item.put("id", "2");
            item.put("urfdate_mdy", "2008-08-10");
            item.put("patient", "xyz III, uvw");
            item.put("urfnote", "Test note xyz.");
            results.add(item);
        }
        wDocuments.loadData(results.toArray((HashMap<String, String>[]) new HashMap<?, ?>[0]));
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        wDocuments.showloading(true);
        String[] params = {};
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest("org.freemedsoftware.module.UnreadDocuments.GetAll", params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                }

                public void onResponseReceived(Request request, Response response) {
                    if (Util.checkValidSessionResponse(response.getText())) {
                        if (200 == response.getStatusCode()) {
                            HashMap<String, String>[] r = (HashMap<String, String>[]) JsonUtil.shoehornJson(
                                    JSONParser.parseStrict(response.getText()), "HashMap<String,String>[]");
                            if (r != null) {
                                store = r;
                                wDocuments.loadData(r);
                            }
                        } else {
                            wDocuments.showloading(false);
                        }
                    }
                }
            });
        } catch (RequestException e) {
        }
    } else {
        // TODO GWT STUFF
    }
}

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

License:Open Source License

protected void addUser() {
    String requestURL = "org.freemedsoftware.api.UserInterface.add";
    HashMap<String, String> hm = new HashMap<String, String>();
    if (userId != null) {
        hm.put("id", userId.toString());
        requestURL = "org.freemedsoftware.api.UserInterface.mod";
    }//  www . j ava 2s  .  c o  m

    hm.put("username", tbUsername.getText());
    if (tbPassword.isEnabled())
        hm.put("userpassword", tbPassword.getText());

    hm.put("userfname", tbUserFirstName.getText());
    hm.put("userlname", tbUserLastName.getText());
    hm.put("usermname", tbUserMiddleName.getText());
    hm.put("usertitle", tbUserTitle.getWidgetValue());
    hm.put("userdescrip", tbDescription.getText());
    String usertype = lbUserType.getValue(lbUserType.getSelectedIndex());
    hm.put("usertype", usertype);
    if (usertype == "phy") {
        hm.put("userrealphy", lbActualPhysician.getValue().toString());
    }

    String userfac = "";
    Iterator<Integer> itr = facilitiesCheckBoxesMap.keySet().iterator();
    while (itr.hasNext()) {
        Integer id = itr.next();
        CheckBox checkBox = facilitiesCheckBoxesMap.get(id);
        if (checkBox.getValue())
            userfac = userfac + id.toString() + ",";
    }
    hm.put("userfac", userfac);
    String useracl = "";
    itr = aclSelectedGroupsIdsList.iterator();
    while (itr.hasNext()) {
        useracl = useracl + itr.next().toString();
        if (itr.hasNext())
            useracl = useracl + ",";
    }
    hm.put("useracl", useracl);

    List paramsList = new ArrayList();
    paramsList.add(JsonUtil.jsonify(hm));

    if (customizePermissionsTable.isVisible()) {
        calculateBlockedAndAllowedACLSections();
        if (blockedPermissionsMap.size() > 0)
            paramsList.add(JsonUtil.jsonify(blockedPermissionsMap));
        else
            paramsList.add("");
        if (allowedPermissionsMap.size() > 0)
            paramsList.add(JsonUtil.jsonify(allowedPermissionsMap));
        else
            paramsList.add("");
    }
    if (Util.getProgramMode() == ProgramMode.STUBBED) {
        // Do nothing.
    } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
        String[] params = (String[]) paramsList.toArray(new String[0]);
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                URL.encode(Util.getJsonRequest(requestURL, params)));
        try {
            builder.sendRequest(null, new RequestCallback() {
                public void onError(Request request, Throwable ex) {
                    Util.showErrorMsg("UserManagementScreen", _("Failed to add user."));
                }

                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("UserManagementScreen", _("Successfully added user."));
                            retrieveAllUsers();
                            clearForm();
                        } else {
                            Boolean b = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (b) {
                                Util.showInfoMsg("UserManagementScreen", _("Successfully modified user."));
                                retrieveAllUsers();
                                clearForm();
                            }
                        }
                    } else {
                        Util.showErrorMsg("UserManagementScreen", _("Failed to add user."));
                    }
                }
            });
        } catch (RequestException e) {
            Util.showErrorMsg("UserManagementScreen", _("Failed to add user."));
        }
    } else {
        // TODO: Create GWT-RPC stuff here
    }

}

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

License:Open Source License

protected void deleteUser() {
    if (true) {//from w  w  w .  j  a  va 2 s. co  m
        if (Util.getProgramMode() == ProgramMode.STUBBED) {
            // Do nothing.
        } else if (Util.getProgramMode() == ProgramMode.JSONRPC) {
            String[] params = { JsonUtil.jsonify(userId) };
            RequestBuilder builder = new RequestBuilder(RequestBuilder.POST,
                    URL.encode(Util.getJsonRequest("org.freemedsoftware.api.UserInterface.del", params)));
            try {
                builder.sendRequest(null, new RequestCallback() {
                    public void onError(Request request, Throwable ex) {
                        Util.showErrorMsg("UserManagementScreen", _("Failed to delete user."));
                    }

                    public void onResponseReceived(Request request, Response response) {
                        if (200 == response.getStatusCode()) {
                            Boolean flag = (Boolean) JsonUtil
                                    .shoehornJson(JSONParser.parseStrict(response.getText()), "Boolean");
                            if (flag) {
                                Util.showInfoMsg("UserManagementScreen", _("Successfully deleted user."));
                                retrieveAllUsers();
                                clearForm();
                            }
                        } else {
                            Util.showErrorMsg("UserManagementScreen", _("Failed to delete user."));
                        }
                    }
                });
            } catch (RequestException e) {
                Util.showErrorMsg("UserManagementScreen", _("Failed to delete user."));
            }
        } else {
            // TODO: Create GWT-RPC stuff here
        }

    }
}