Subversion Repository Public Repository

emr_demo

Diff Revisions 3 vs 4 for /web_emr - Copy/src/main/java/com/bestray/security/service/FacilityMasterService.java

Diff revisions: vs.
  @@ -1,19 +1,28 @@
1 1 package com.bestray.security.service;
2 2
3 + import java.util.List;
3 4 import java.util.Optional;
4 5
5 6 import org.springframework.beans.factory.annotation.Autowired;
7 + import org.springframework.http.HttpStatus;
6 8 import org.springframework.stereotype.Service;
9 + import org.springframework.web.server.ResponseStatusException;
7 10
8 - import com.bestray.model.security.DepartmentMaster;
9 - import com.bestray.model.security.PharmacyMaster;
10 - import com.bestray.model.security.SpecialityMaster;
11 + import com.bestray.model.entity.SpecialityMaster;
12 + import com.bestray.model.entity.DepartmentMaster;
13 + import com.bestray.model.entity.ExpenditureMaster;
14 + import com.bestray.model.entity.LabMaster;
15 + import com.bestray.model.entity.PharmacyMaster;
11 16 import com.bestray.model.security.User;
12 17 import com.bestray.security.controller.ExceptionHandler_delete;
13 18 import com.bestray.security.controller.ExceptionHandler_update;
14 19 import com.bestray.security.repository.DepartmentRepository;
20 + import com.bestray.security.repository.ExpenditureRepository;
21 + import com.bestray.security.repository.LabRepository;
15 22 import com.bestray.security.repository.PharmacyRepository;
16 23 import com.bestray.security.repository.SpecialityRepository;
24 + import com.fasterxml.jackson.core.JsonProcessingException;
25 + import com.fasterxml.jackson.databind.ObjectMapper;
17 26
18 27 @Service
19 28 public class FacilityMasterService {
  @@ -23,7 +32,10 @@
23 32 private DepartmentRepository departmentRepository;
24 33 @Autowired
25 34 private PharmacyRepository pharmacyRepository;
26 -
35 + @Autowired
36 + private LabRepository labRepository;
37 + @Autowired
38 + private ExpenditureRepository expenditureRepository;
27 39 //save
28 40 public void saveDepartment(DepartmentMaster departmentMaster) throws ExceptionHandler_update {
29 41 String dept_name=departmentMaster.getDepartmentName();
  @@ -31,7 +43,7 @@
31 43 DepartmentMaster userExists =departmentRepository.findByDepartmentName(dept_name);
32 44 System.out.println("1@@@>"+dept_name);
33 45 if (userExists != null) {
34 - throw new ExceptionHandler_update();
46 + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "departmentMaster already avilable");
35 47
36 48 }else{
37 49 departmentMaster.setEnabled(true);
  @@ -53,7 +65,8 @@
53 65 departmentRepository.save(dept_new);
54 66 System.out.println("2@@@@@");
55 67 }else{
56 - throw new ExceptionHandler_update(); }
68 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
69 + }
57 70 }
58 71 }
59 72
  @@ -66,11 +79,46 @@
66 79 dept_new.setEnabled(false);
67 80 departmentRepository.save(dept_new);
68 81 }else{
69 - throw new ExceptionHandler_delete();
82 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
70 83
71 84 }
72 85 }
73 86 }
87 + //searchDepartment
88 + public String searchDepartment() throws ExceptionHandler_delete, JsonProcessingException {
89 + List<DepartmentMaster> userExists =departmentRepository.findAll();
90 + String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
91 + .writeValueAsString(userExists);
92 + if (userExists.isEmpty()) {
93 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
94 + }else{
95 + //throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
96 + for(int i=0;i<userExists.size();i++){
97 + userExists.get(i);
98 + System.out.println("#####################"+userExists.get(i).getDepartmentName());
99 + }
100 + }
101 + return json;
102 + }
103 + //searchDepartment
104 + public String searchDepartmentByName(String name) throws ExceptionHandler_delete, JsonProcessingException {
105 + DepartmentMaster userExists =departmentRepository.findByDepartmentName(name);
106 + String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
107 + .writeValueAsString(userExists);
108 + if (userExists != null) {
109 +
110 + }else{
111 + //throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
112 + // for(int i=0;i<userExists.size();i++){
113 + // userExists.get(i);
114 + // System.out.println("#####################"+userExists.get(i).getDepartmentName());
115 + // }
116 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not avilable");
117 + }
118 + return json;
119 + }
120 +
121 +
74 122
75 123 //saveSpeciality
76 124 public void saveSpeciality(SpecialityMaster speciality) throws ExceptionHandler_update {
  @@ -80,7 +128,7 @@
80 128 System.out.println("2@@@@@"+userExists);
81 129 if (userExists != null) {
82 130 System.out.println("4@@@@@");
83 - throw new ExceptionHandler_update();
131 + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Speciality Already avilable");
84 132 }else{
85 133 speciality.setEnabled(true);
86 134 System.out.println("3@@@@@");
  @@ -102,13 +150,13 @@
102 150 specialityRepository.save(spec_new);
103 151 System.out.println("2@@@@@");
104 152 }else{
105 - throw new ExceptionHandler_update();
153 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not found");
106 154 }
107 155 }
108 156 }
109 157
110 158 //deleteSpeciality
111 - public void daleteSpeciality(String id) throws ExceptionHandler_delete {
159 + public void delateSpeciality(String id) throws ExceptionHandler_delete {
112 160 Optional<SpecialityMaster> userExists =specialityRepository.findById(id);
113 161 if (userExists.isPresent()) {
114 162 SpecialityMaster spec_new = userExists.get();
  @@ -116,13 +164,29 @@
116 164 spec_new.setEnabled(false);
117 165 specialityRepository.save(spec_new);
118 166 }else{
119 - throw new ExceptionHandler_delete();
167 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not available");
120 168
121 169 }
122 170 }
123 171 }
124 -
125 172
173 + //serachSpeciality
174 + public String searchSpeciality() throws ExceptionHandler_delete, JsonProcessingException {
175 +
176 + List<SpecialityMaster> userExists =specialityRepository.findAll();
177 + String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
178 + .writeValueAsString(userExists);
179 + if (userExists.isEmpty()) {
180 +
181 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not available");
182 + }else{
183 +
184 + System.out.println("@@@@@@@@@@@@@@");
185 + }
186 + return json;
187 + }
188 +
189 +
126 190
127 191 //savePharmacy
128 192 public void savePharmacy(PharmacyMaster pharmacyMaster) throws ExceptionHandler_update {
  @@ -131,7 +195,7 @@
131 195 PharmacyMaster userExists =pharmacyRepository.findByPharmacyName(pharmacy_new);
132 196 System.out.println("1@@@>"+pharmacy_new);
133 197 if (userExists != null) {
134 - throw new ExceptionHandler_update();
198 + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Pharmacy Already avilable");
135 199
136 200 }else{
137 201 pharmacyMaster.setEnabled(true);
  @@ -153,7 +217,7 @@
153 217 pharmacyRepository.save(pharmacy_new);
154 218 System.out.println("2@@@@@");
155 219 }else{
156 - throw new ExceptionHandler_update();
220 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is already avilable");
157 221 }
158 222 }
159 223 }
  @@ -167,10 +231,159 @@
167 231 pharmacy_new.setEnabled(false);
168 232 pharmacyRepository.save(pharmacy_new);
169 233 }else{
170 - throw new ExceptionHandler_delete();
234 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
171 235
172 236 }
173 237 }
174 238 }
239 +
240 +
241 + //searchPharmacy
242 + public String searchPharmacy() throws ExceptionHandler_delete, JsonProcessingException {
243 + List<PharmacyMaster> userExists =pharmacyRepository.findAll();
244 + String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
245 + .writeValueAsString(userExists);
246 + if (userExists.isEmpty()) {
247 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
248 +
249 + }else{
250 +
251 + System.out.println("############");
252 + }
253 + return json;
254 + }
255 +
256 +
257 +
258 + //saveLab
259 + public void saveLab(LabMaster labMaster) throws ExceptionHandler_update {
260 + String lab_new=labMaster.getLabName();
261 +
262 + LabMaster userExists =labRepository.findByLabName(lab_new);
263 + // System.out.println("1@@@>"+pharmacy_new);
264 + if (userExists != null) {
265 + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Pharmacy Already avilable");
266 +
267 + }else{
268 + labMaster.setEnabled(true);
269 + labRepository.save(labMaster);
270 + System.out.println("2@@@@@");
271 + }
272 + }
273 +
274 +
275 +
276 + //editLab
277 + public void editLab(LabMaster labMaster,String id) throws ExceptionHandler_update {
278 + Optional<LabMaster> userExists =labRepository.findById(id);
279 + if (userExists.isPresent()){
280 + LabMaster lab_new = userExists.get();
281 + if (lab_new != null) {
282 + lab_new.setLabName(labMaster.getLabName());
283 + lab_new.setLabAddress(labMaster.getLabAddress());
284 + lab_new.setLabPhonenumber(labMaster.getLabPhonenumber());
285 + lab_new.setLabZipcode(labMaster.getLabZipcode());
286 + labRepository.save(lab_new);
287 + System.out.println("2@@@@@");
288 + }else{
289 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is already avilable");
290 + }
291 + }
292 + }
293 +
294 + //deleteLab
295 + public void delateLab(String id) throws ExceptionHandler_delete {
296 + Optional<LabMaster> userExists =labRepository.findById(id);
297 + if (userExists.isPresent()) {
298 + LabMaster lab_new = userExists.get();
299 + if(lab_new!=null){
300 + lab_new.setEnabled(false);
301 + labRepository.save(lab_new);
302 + }else{
303 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
304 +
305 + }
306 + }
307 + }
308 +
309 +
310 + //searchLab
311 + public String searchLab() throws ExceptionHandler_delete, JsonProcessingException {
312 + List<LabMaster> userExists =labRepository.findAll();
313 + String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
314 + .writeValueAsString(userExists);
315 + if (userExists.isEmpty()) {
316 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
317 +
318 + }else{
319 +
320 + System.out.println("############");
321 + }
322 + return json;
323 + }
324 + //saveExpendiure
325 + public void saveExpenditure(ExpenditureMaster expenditureMaster) throws ExceptionHandler_update {
326 + String expenditure_new=expenditureMaster.getExpenditureType();
327 +
328 + ExpenditureMaster userExists =expenditureRepository.findByExpenditureType(expenditure_new);
329 + // System.out.println("1@@@>"+pharmacy_new);
330 + if (userExists != null) {
331 + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Pharmacy Already avilable");
332 +
333 + }else{
334 + expenditureMaster.setEnabled(true);
335 + expenditureRepository.save(expenditureMaster);
336 + System.out.println("2@@@@@");
337 + }
338 + }
339 +
340 + //editExpenditure
341 + public void editExpenditure(ExpenditureMaster expenditureMaster,String id) throws ExceptionHandler_update {
342 + Optional<ExpenditureMaster> userExists =expenditureRepository.findById(id);
343 + if (userExists.isPresent()){
344 + ExpenditureMaster expenditure_new = userExists.get();
345 + if (expenditure_new != null) {
346 + expenditure_new.setExpenditureType(expenditureMaster.getExpenditureType());
347 + expenditure_new.setExpenditure_note(expenditureMaster.getExpenditure_note());
348 + expenditure_new.setExpenditureDate(expenditureMaster.getExpenditureDate());
349 + expenditure_new.setAmount(expenditureMaster.getAmount());
350 + expenditureRepository.save(expenditure_new);
351 + System.out.println("2@@@@@");
352 + }else{
353 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is already avilable");
354 + }
355 + }
356 + }
357 +
358 + //deleteExpenditure
359 + public void deleteExpenditure(String id) throws ExceptionHandler_delete {
360 + Optional<ExpenditureMaster> userExists =expenditureRepository.findById(id);
361 + if (userExists.isPresent()) {
362 + ExpenditureMaster expenditure_new = userExists.get();
363 + if(expenditure_new!=null){
364 + expenditure_new.setEnabled(false);
365 + expenditureRepository.save(expenditure_new);
366 + }else{
367 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
368 +
369 + }
370 + }
371 + }
372 +
373 + //searchExpenditure
374 + // public String searchExpenditure() throws ExceptionHandler_delete, JsonProcessingException {
375 + // List<ExpenditureMaster> userExists =expenditureRepository.findAll();
376 + // String json = new ObjectMapper().writerWithDefaultPrettyPrinter()
377 + // .writeValueAsString(userExists);
378 + // if (userExists.isEmpty()) {
379 + // throw new ResponseStatusException(HttpStatus.NOT_FOUND, "given id is not already avilable");
380 + //
381 + // }else{
382 + //
383 + // System.out.println("############");
384 + // }
385 + // return json;
386 + // }
387 +
175 388
176 389 }