| | 37 | protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response, Object obj, BindException errors) throws Exception { |
|---|
| | 38 | |
|---|
| | 39 | super.processFormSubmission(request, response, obj, errors); |
|---|
| | 40 | |
|---|
| | 41 | System.out.println("we are here"); |
|---|
| | 42 | |
|---|
| | 43 | newIdentifiers = new HashSet<PatientIdentifier>(); |
|---|
| | 44 | |
|---|
| | 45 | ShortPatientModel shortPatient = (ShortPatientModel)obj; |
|---|
| | 46 | |
|---|
| | 47 | log.debug("\nNOW GOING THROUGH PROCESSFORMSUBMISSION METHOD.......................................\n\n"); |
|---|
| | 48 | |
|---|
| | 49 | if (Context.isAuthenticated()) { |
|---|
| | 50 | PatientService ps = Context.getPatientService(); |
|---|
| | 51 | MessageSourceAccessor msa = getMessageSourceAccessor(); |
|---|
| | 52 | |
|---|
| | 53 | String action = request.getParameter("action"); |
|---|
| | 54 | if (action == null || action.equals(msa.getMessage("general.save"))) { |
|---|
| | 55 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name.familyName", "error.name"); |
|---|
| | 56 | |
|---|
| | 57 | String[] identifiers = request.getParameterValues("identifier"); |
|---|
| | 58 | String[] types = request.getParameterValues("identifierType"); |
|---|
| | 59 | String[] locs = request.getParameterValues("location"); |
|---|
| | 60 | pref = request.getParameter("preferred"); |
|---|
| | 61 | if (pref == null) |
|---|
| | 62 | pref = ""; |
|---|
| | 63 | |
|---|
| | 64 | if (log.isDebugEnabled()) { |
|---|
| | 65 | log.debug("identifiers: " + identifiers); |
|---|
| | 66 | for (String s : identifiers) |
|---|
| | 67 | log.debug(s); |
|---|
| | 68 | log.debug("types: " + types); |
|---|
| | 69 | for (String s : types) |
|---|
| | 70 | log.debug(s); |
|---|
| | 71 | log.debug("locations: " + locs); |
|---|
| | 72 | for (String s : locs) |
|---|
| | 73 | log.debug(s); |
|---|
| | 74 | log.debug("preferred: " + pref); |
|---|
| | 75 | } |
|---|
| | 76 | |
|---|
| | 77 | // loop over the identifiers to create the patient.identifiers set |
|---|
| | 78 | if (identifiers != null) { |
|---|
| | 79 | for (int i=0; i<identifiers.length;i++) { |
|---|
| | 80 | // arguments for the spring error messages |
|---|
| | 81 | String id = identifiers[i].trim(); |
|---|
| | 82 | String[] args = {id}; |
|---|
| | 83 | |
|---|
| | 84 | // add the new identifier only if they put in some identifier string |
|---|
| | 85 | if (id.length() > 0) { |
|---|
| | 86 | |
|---|
| | 87 | // set up the actual identifier java object |
|---|
| | 88 | PatientIdentifierType pit = null; |
|---|
| | 89 | if (types[i] == null || types[i].equals("")) { |
|---|
| | 90 | String msg = getMessageSourceAccessor().getMessage("PatientIdentifier.identifierType.null", args); |
|---|
| | 91 | errors.reject(msg); |
|---|
| | 92 | } |
|---|
| | 93 | else |
|---|
| | 94 | pit = ps.getPatientIdentifierType(Integer.valueOf(types[i])); |
|---|
| | 95 | |
|---|
| | 96 | Location loc = null; |
|---|
| | 97 | if (locs[i] == null || locs[i].equals("")) { |
|---|
| | 98 | String msg = getMessageSourceAccessor().getMessage("PatientIdentifier.location.null", args); |
|---|
| | 99 | errors.reject(msg); |
|---|
| | 100 | } |
|---|
| | 101 | else |
|---|
| | 102 | loc = null; |
|---|
| | 103 | |
|---|
| | 104 | PatientIdentifier pi = new PatientIdentifier(id, pit, loc); |
|---|
| | 105 | pi.setPreferred(pref.equals(id+types[i])); |
|---|
| | 106 | if (newIdentifiers.contains(pi)) |
|---|
| | 107 | newIdentifiers.remove(pi); |
|---|
| | 108 | |
|---|
| | 109 | newIdentifiers.add(pi); |
|---|
| | 110 | |
|---|
| | 111 | if (log.isDebugEnabled()) { |
|---|
| | 112 | log.debug("Creating patient identifier with identifier: " + id); |
|---|
| | 113 | log.debug("and type: " + types[i]); |
|---|
| | 114 | log.debug("and location: " + locs[i]); |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | } |
|---|
| | 118 | } |
|---|
| | 119 | } |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", "error.null"); |
|---|
| | 123 | |
|---|
| | 124 | // check patients birthdate against future dates and really old dates |
|---|
| | 125 | if (shortPatient.getBirthdate() != null) { |
|---|
| | 126 | if (shortPatient.getBirthdate().after(new Date())) |
|---|
| | 127 | errors.rejectValue("birthdate", "error.date.future"); |
|---|
| | 128 | else { |
|---|
| | 129 | Calendar c = Calendar.getInstance(); |
|---|
| | 130 | c.setTime(new Date()); |
|---|
| | 131 | c.add(Calendar.YEAR, -120); // patient cannot be older than 120 years old |
|---|
| | 132 | if (shortPatient.getBirthdate().before(c.getTime())){ |
|---|
| | 133 | errors.rejectValue("birthdate", "error.date.nonsensical"); |
|---|
| | 134 | } |
|---|
| | 135 | } |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | } |
|---|
| | 139 | |
|---|
| | 140 | // skip calling super.processFormSubmission so that setting up the page is done |
|---|
| | 141 | // again in the onSubmit method |
|---|
| | 142 | String[] loclistarr = {"address.address1","address.address2","address.country","address.stateProvince","address.countyDistrict","address.subRegion","address.region","address.townshipDivision","address.cityVillage","address.neighborhoodCell","address.postalCode","address.longitude","address.latitude"}; |
|---|
| | 143 | |
|---|
| | 144 | String dumm= ""; |
|---|
| | 145 | String str = ""; |
|---|
| | 146 | Integer count = Integer.valueOf(request.getParameter("count")); |
|---|
| | 147 | if(count != getService().getSizeOfPersonTable()){ |
|---|
| | 148 | |
|---|
| | 149 | for(int i=0;i<loclistarr.length;i++){ |
|---|
| | 150 | dumm = "address."+loclistarr[i]; |
|---|
| | 151 | str += "'"+request.getParameter(dumm)+"'"; |
|---|
| | 152 | str += ","; |
|---|
| | 153 | |
|---|
| | 154 | } |
|---|
| | 155 | List lastRow = getService().getLastRow(); |
|---|
| | 156 | Object[] x = (Object[]) lastRow.get(lastRow.size()-1); |
|---|
| | 157 | |
|---|
| | 158 | str += x[0].toString()+","; |
|---|
| | 159 | str += x[1].toString()+","; |
|---|
| | 160 | |
|---|
| | 161 | if((Boolean) x[2]){ |
|---|
| | 162 | str += "1,"+x[3].toString()+","+x[4].toString()+","+x[5].toString(); |
|---|
| | 163 | } |
|---|
| | 164 | else |
|---|
| | 165 | str += "0,null,null,null"; |
|---|
| | 166 | System.out.println(str); |
|---|
| | 167 | } |
|---|
| | 168 | ModelAndView fin = onSubmit(request, response, shortPatient, errors); |
|---|
| | 169 | System.out.println("now here"); |
|---|
| | 170 | |
|---|
| | 171 | return fin; |
|---|
| | 172 | } |
|---|
| 44 | | @Override |
|---|
| 45 | | protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException exceptions) throws Exception { |
|---|
| 46 | | //HttpSession httpSession = request.getSession(); |
|---|
| 47 | | String s= request.getAttribute("org.openmrs.portlet.userId").toString(); |
|---|
| 48 | | System.out.println(s); |
|---|
| 49 | | System.out.println("casjdhajsdasd"); |
|---|
| 50 | | |
|---|
| 51 | | PersonAddress pa = personAddress; |
|---|
| 52 | | String[] arr = {"Country","State/Province","City/Village","Neighborhood/Cell","County/District","Township/Division","Sub Region","Region","Postal Code","Longitude","Latitude"}; |
|---|
| 53 | | pa.setCountry(request.getParameter("Country")); |
|---|
| 54 | | pa.setStateProvince(request.getParameter("State/Province")); |
|---|
| 55 | | pa.setCityVillage(request.getParameter("City/Village")); |
|---|
| 56 | | pa.setNeighborhoodCell(request.getParameter("Neighborhood/Cell")); |
|---|
| 57 | | pa.setCountyDistrict(request.getParameter("County/District")); |
|---|
| 58 | | pa.setTownshipDivision(request.getParameter("Township/Division")); |
|---|
| 59 | | pa.setSubregion(request.getParameter("Sub Region")); |
|---|
| 60 | | pa.setRegion(request.getParameter("Region")); |
|---|
| 61 | | pa.setPostalCode(request.getParameter("Postal Code")); |
|---|
| 62 | | pa.setLongitude(request.getParameter("Longitude")); |
|---|
| 63 | | pa.setLatitude(request.getParameter("Latitude")); |
|---|
| 64 | | pa.setAddress1(request.getParameter("Address1")); |
|---|
| 65 | | pa.setAddress2(request.getParameter("Address2")); |
|---|
| 66 | | |
|---|
| 67 | | return new ModelAndView(new RedirectView(getSuccessView())); |
|---|
| 68 | | } |
|---|
| 69 | | |
|---|
| 70 | | |
|---|
| 71 | | |
|---|
| 72 | | |
|---|
| | 179 | |
|---|