3535import org .springframework .web .bind .annotation .RequestMethod ;
3636import org .springframework .web .bind .annotation .RestController ;
3737
38+ import com .iemr .admin .data .store .FacilityHierarchyRequest ;
39+ import com .iemr .admin .data .store .FacilityVillageMapping ;
3840import com .iemr .admin .data .store .M_Facility ;
3941import com .iemr .admin .data .store .M_facilityMap ;
4042import com .iemr .admin .data .store .V_FetchFacility ;
@@ -286,6 +288,23 @@ public String getMapStore(@RequestBody V_FetchFacility facilitymap) {
286288
287289 }
288290
291+ @ Operation (summary = "Get facilities by block/taluk" )
292+ @ RequestMapping (value = "/getFacilitiesByBlock" , headers = "Authorization" , method = { RequestMethod .POST }, produces = {
293+ "application/json" })
294+ public String getFacilitiesByBlock (@ RequestBody String request ) {
295+
296+ OutputResponse response = new OutputResponse ();
297+ try {
298+ M_Facility facility = InputMapper .gson ().fromJson (request , M_Facility .class );
299+ ArrayList <M_Facility > data = storeService .getFacilitiesByBlock (facility .getBlockID ());
300+ response .setResponse (data .toString ());
301+ } catch (Exception e ) {
302+ logger .error ("Unexpected error:" , e );
303+ response .setError (e );
304+ }
305+ return response .toString ();
306+ }
307+
289308 @ Operation (summary = "Check store code" )
290309 @ RequestMapping (value = "/checkStoreCode" , headers = "Authorization" , method = { RequestMethod .POST }, produces = {
291310 "application/json" })
@@ -311,4 +330,110 @@ public String checkStoreCode(@RequestBody String deleteManufacturer) {
311330 return response .toString ();
312331
313332 }
333+
334+ @ Operation (summary = "Get facilities by block and facility level" )
335+ @ RequestMapping (value = "/getFacilitiesByBlockAndLevel" , headers = "Authorization" , method = {
336+ RequestMethod .POST }, produces = { "application/json" })
337+ public String getFacilitiesByBlockAndLevel (@ RequestBody String request ) {
338+
339+ OutputResponse response = new OutputResponse ();
340+ try {
341+ com .iemr .admin .data .facilitytype .M_facilitytype reqObj = InputMapper .gson ().fromJson (request ,
342+ com .iemr .admin .data .facilitytype .M_facilitytype .class );
343+ ArrayList <M_Facility > data = storeService .getFacilitiesByBlockAndLevel (reqObj .getBlockID (),
344+ reqObj .getFacilityLevelID ());
345+ response .setResponse (data .toString ());
346+ } catch (Exception e ) {
347+ logger .error ("Unexpected error:" , e );
348+ response .setError (e );
349+ }
350+ return response .toString ();
351+ }
352+
353+ @ Operation (summary = "Create facility with hierarchy mapping" )
354+ @ RequestMapping (value = "/createFacilityWithHierarchy" , headers = "Authorization" , method = {
355+ RequestMethod .POST }, produces = { "application/json" })
356+ public String createFacilityWithHierarchy (@ RequestBody String request ) {
357+
358+ OutputResponse response = new OutputResponse ();
359+ try {
360+ FacilityHierarchyRequest reqObj = InputMapper .gson ().fromJson (request , FacilityHierarchyRequest .class );
361+ M_Facility savedFacility = storeService .createFacilityWithHierarchy (reqObj .getFacility (),
362+ reqObj .getVillageIDs (), reqObj .getChildFacilityIDs ());
363+ response .setResponse (savedFacility .toString ());
364+ } catch (Exception e ) {
365+ logger .error ("Unexpected error:" , e );
366+ response .setError (e );
367+ }
368+ return response .toString ();
369+ }
370+
371+ @ Operation (summary = "Get village IDs already mapped to facilities in a block" )
372+ @ RequestMapping (value = "/getMappedVillageIDs" , headers = "Authorization" , method = {
373+ RequestMethod .POST }, produces = { "application/json" })
374+ public String getMappedVillageIDs (@ RequestBody String request ) {
375+
376+ OutputResponse response = new OutputResponse ();
377+ try {
378+ M_Facility facility = InputMapper .gson ().fromJson (request , M_Facility .class );
379+ List <Integer > mappedIDs = storeService .getMappedVillageIDs (facility .getBlockID ());
380+ response .setResponse (mappedIDs .toString ());
381+ } catch (Exception e ) {
382+ logger .error ("Unexpected error:" , e );
383+ response .setError (e );
384+ }
385+ return response .toString ();
386+ }
387+
388+ @ Operation (summary = "Get village mappings for a facility" )
389+ @ RequestMapping (value = "/getVillageMappingsByFacility" , headers = "Authorization" , method = {
390+ RequestMethod .POST }, produces = { "application/json" })
391+ public String getVillageMappingsByFacility (@ RequestBody String request ) {
392+
393+ OutputResponse response = new OutputResponse ();
394+ try {
395+ M_Facility facility = InputMapper .gson ().fromJson (request , M_Facility .class );
396+ ArrayList <FacilityVillageMapping > mappings = storeService .getVillageMappingsByFacility (facility .getFacilityID ());
397+ response .setResponse (mappings .toString ());
398+ } catch (Exception e ) {
399+ logger .error ("Unexpected error:" , e );
400+ response .setError (e );
401+ }
402+ return response .toString ();
403+ }
404+
405+ @ Operation (summary = "Get child facilities by parent facility ID" )
406+ @ RequestMapping (value = "/getChildFacilitiesByParent" , headers = "Authorization" , method = {
407+ RequestMethod .POST }, produces = { "application/json" })
408+ public String getChildFacilitiesByParent (@ RequestBody String request ) {
409+
410+ OutputResponse response = new OutputResponse ();
411+ try {
412+ M_Facility facility = InputMapper .gson ().fromJson (request , M_Facility .class );
413+ ArrayList <M_Facility > children = storeService .getChildFacilitiesByParent (facility .getFacilityID ());
414+ response .setResponse (children .toString ());
415+ } catch (Exception e ) {
416+ logger .error ("Unexpected error:" , e );
417+ response .setError (e );
418+ }
419+ return response .toString ();
420+ }
421+
422+ @ Operation (summary = "Update facility with hierarchy mapping" )
423+ @ RequestMapping (value = "/updateFacilityWithHierarchy" , headers = "Authorization" , method = {
424+ RequestMethod .POST }, produces = { "application/json" })
425+ public String updateFacilityWithHierarchy (@ RequestBody String request ) {
426+
427+ OutputResponse response = new OutputResponse ();
428+ try {
429+ FacilityHierarchyRequest reqObj = InputMapper .gson ().fromJson (request , FacilityHierarchyRequest .class );
430+ M_Facility updatedFacility = storeService .updateFacilityWithHierarchy (reqObj .getFacility (),
431+ reqObj .getVillageIDs (), reqObj .getChildFacilityIDs ());
432+ response .setResponse (updatedFacility .toString ());
433+ } catch (Exception e ) {
434+ logger .error ("Unexpected error:" , e );
435+ response .setError (e );
436+ }
437+ return response .toString ();
438+ }
314439}
0 commit comments