diff --git a/src/main/java/com/iemr/hwc/controller/choApp/CHOAppSyncController.java b/src/main/java/com/iemr/hwc/controller/choApp/CHOAppSyncController.java index b90f7976..4e40bd2a 100644 --- a/src/main/java/com/iemr/hwc/controller/choApp/CHOAppSyncController.java +++ b/src/main/java/com/iemr/hwc/controller/choApp/CHOAppSyncController.java @@ -1,5 +1,6 @@ package com.iemr.hwc.controller.choApp; +import com.iemr.hwc.data.choApp.OutreachActivity; import com.iemr.hwc.data.choApp.UserActivityLogs; import com.iemr.hwc.data.doctor.PrescriptionTemplates; import com.iemr.hwc.service.choApp.CHOAppSyncService; @@ -129,4 +130,30 @@ public ResponseEntity deleteTemplate(@PathVariable Integer userID, return choappSyncService.deletePrescriptionTemplates(userID, tempID); } + // save new Outreach activity event + @ApiOperation(value = "Create new event for outreach activity", consumes = "application/json", produces = "application/json") + @RequestMapping(value = { "/activity/create" }, method = { RequestMethod.POST }) + public ResponseEntity createNewOutreachActivity(@RequestBody OutreachActivity activity, + @RequestHeader(value = "Authorization") String Authorization) { + + return choappSyncService.createNewOutreachActivity(activity, Authorization); + } + + // Get all outreach activities by user + @ApiOperation(value = "Get list of all outreach activities by user", consumes = "application/json", produces = "application/json") + @RequestMapping(value = { "/activity/{userId}/getAllByUser" }, method = { RequestMethod.GET }) + public ResponseEntity getActivitiesByUser(@PathVariable Integer userId, + @RequestHeader(value = "Authorization") String Authorization) { + + return choappSyncService.getActivitiesByUser(userId, Authorization); + } + + // Get an outreach activity by activityId + @ApiOperation(value = "Get an outreach activities by activityId", consumes = "application/json", produces = "application/json") + @RequestMapping(value = { "/activity/{activityId}/getById" }, method = { RequestMethod.GET }) + public ResponseEntity getActivityByIdr(@PathVariable Integer activityId, + @RequestHeader(value = "Authorization") String Authorization) { + + return choappSyncService.getActivityById(activityId, Authorization); + } } \ No newline at end of file diff --git a/src/main/java/com/iemr/hwc/data/choApp/OutreachActivity.java b/src/main/java/com/iemr/hwc/data/choApp/OutreachActivity.java new file mode 100644 index 00000000..1c3a009a --- /dev/null +++ b/src/main/java/com/iemr/hwc/data/choApp/OutreachActivity.java @@ -0,0 +1,122 @@ +package com.iemr.hwc.data.choApp; + +import com.google.gson.annotations.Expose; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.ArrayList; + +@Data +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "t_outreach_activity") +public class OutreachActivity { + + @Id + @Expose + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ActivityId") + private int activityId; + + @Expose + @Column(name = "UserId") + private Integer userId; + + @Expose + @Column(name = "UserName") + private String userName; + + @Expose + @Column(name = "ActivityName") + private String activityName; + + @Expose + @Column(name = "EventDesc") + private String eventDescription; + + @Expose + @Column(name = "NoOfParticipants") + private Integer noOfParticipants; + + @Expose + @Column(name = "ActivityDate") + private Timestamp activityDate; + + @Expose + @Column(name = "Img1TimeStamp") + private Timestamp img1TimeStamp; + + @Expose + @Column(name = "Img2TimeStamp") + private Timestamp img2TimeStamp; + + @Lob + @Column(name = "Img1", columnDefinition = "MEDIUMBLOB") + private byte[] img1Data; + + @Lob + @Column(name = "Img2", columnDefinition = "MEDIUMBLOB") + private byte[] img2Data; + + @Expose + @Transient + private String img1; + + @Expose + @Transient + private String img2; + + @Expose + @Column(name = "Img1Latitude") + private Double img1latitude ; + + @Expose + @Column(name = "Img1Longitude") + private Double img1longitude; + + @Expose + @Column(name = "Img1Address") + private String img1Address; + + @Expose + @Column(name = "Img2Address") + private String img2Address; + + @Expose + @Column(name = "Img2Latitude") + private Double img2latitude ; + + @Expose + @Column(name = "Img2Longitude") + private Double img2longitude; + + @Column(name = "Deleted", insertable = false, updatable = true) + private Boolean deleted; + + public OutreachActivity(Integer activityId, String activityName, String eventDescription, Integer noOfParticipants, + Timestamp activityDate, Integer userId, String userName) { + this.activityId = activityId; + this.activityName = activityName; + this.eventDescription = eventDescription; + this.noOfParticipants = noOfParticipants; + this.activityDate = activityDate; + this.userId = userId; + this.userName = userName; + } + + public static ArrayList getActivitiesForUser(ArrayList objList) { + ArrayList activityList = new ArrayList<>(); + OutreachActivity obj = null; + if (objList != null && !objList.isEmpty()) { + for (Object[] objArr : objList) { + obj = new OutreachActivity((Integer) objArr[0], (String) objArr[1], (String) objArr[2], + (Integer) objArr[3], (Timestamp) objArr[4],(Integer) objArr[5], (String) objArr[6]); + activityList.add(obj); + } + } + return activityList; + } +} diff --git a/src/main/java/com/iemr/hwc/repo/choApp/OutreachActivityRepo.java b/src/main/java/com/iemr/hwc/repo/choApp/OutreachActivityRepo.java new file mode 100644 index 00000000..b85e2e84 --- /dev/null +++ b/src/main/java/com/iemr/hwc/repo/choApp/OutreachActivityRepo.java @@ -0,0 +1,17 @@ +package com.iemr.hwc.repo.choApp; + +import com.iemr.hwc.data.choApp.OutreachActivity; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; +import java.util.ArrayList; + + +@Repository +public interface OutreachActivityRepo extends CrudRepository { + + @Query(" SELECT o.activityId, o.activityName, o.eventDescription," + + "o.noOfParticipants, o.activityDate, o.userId, o.userName FROM OutreachActivity o WHERE o.userId = :userId AND o.deleted = false ") + ArrayList getActivitiesByUserID(@Param("userId") Integer userId); +} diff --git a/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncService.java b/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncService.java index da064db2..92d1371e 100644 --- a/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncService.java +++ b/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncService.java @@ -1,5 +1,6 @@ package com.iemr.hwc.service.choApp; +import com.iemr.hwc.data.choApp.OutreachActivity; import com.iemr.hwc.data.choApp.UserActivityLogs; import com.iemr.hwc.data.doctor.PrescriptionTemplates; import com.iemr.hwc.utils.request.SyncSearchRequest; @@ -28,4 +29,10 @@ public interface CHOAppSyncService { ResponseEntity countFlowRecordsByVillageIDAndLastModifiedDate(SyncSearchRequest villageIDAndLastSyncDate, String authorization); ResponseEntity countBeneficiaryByVillageIDAndLastModifiedDate(SyncSearchRequest villageIDAndLastSyncDate, String authorization); + + ResponseEntity createNewOutreachActivity(OutreachActivity activity, String authorization); + + ResponseEntity getActivitiesByUser(Integer userId, String authorization); + + ResponseEntity getActivityById(Integer activityId, String authorization); } diff --git a/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncServiceImpl.java b/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncServiceImpl.java index a485333d..a7cd0530 100644 --- a/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncServiceImpl.java +++ b/src/main/java/com/iemr/hwc/service/choApp/CHOAppSyncServiceImpl.java @@ -2,11 +2,13 @@ import com.google.gson.*; import com.iemr.hwc.data.benFlowStatus.BeneficiaryFlowStatus; +import com.iemr.hwc.data.choApp.OutreachActivity; import com.iemr.hwc.data.choApp.UserActivityLogs; import com.iemr.hwc.data.doctor.PrescriptionTemplates; import com.iemr.hwc.data.nurse.BeneficiaryVisitDetail; import com.iemr.hwc.data.quickConsultation.BenChiefComplaint; import com.iemr.hwc.repo.benFlowStatus.BeneficiaryFlowStatusRepo; +import com.iemr.hwc.repo.choApp.OutreachActivityRepo; import com.iemr.hwc.repo.choApp.UserActivityLogsRepo; import com.iemr.hwc.repo.doctor.PrescriptionTemplatesRepo; import com.iemr.hwc.repo.nurse.BenAnthropometryRepo; @@ -79,6 +81,13 @@ public class CHOAppSyncServiceImpl implements CHOAppSyncService { private PrescriptionTemplatesRepo prescriptionTemplatesRepo; + private OutreachActivityRepo outreachActivityRepo; + + @Autowired + public void setOutreachActivityRepo(OutreachActivityRepo outreachActivityRepo){ + this.outreachActivityRepo = outreachActivityRepo; + } + @Autowired public void setPrescriptionTemplatesRepo(PrescriptionTemplatesRepo prescriptionTemplatesRepo){ this.prescriptionTemplatesRepo = prescriptionTemplatesRepo; @@ -631,4 +640,84 @@ public ResponseEntity deletePrescriptionTemplates(Integer userID, Intege } + @Override + public ResponseEntity createNewOutreachActivity(OutreachActivity activity, String authorization) { + OutputResponse outputResponse = new OutputResponse(); + HttpStatus statusCode = HttpStatus.OK; + + MultiValueMap headers = new LinkedMultiValueMap<>(); + headers.add("Content-Type", "application/json"); + + try{ + if(activity.getImg1() != null) { + byte[] imageByte1 = Base64.getDecoder().decode(activity.getImg1()); + activity.setImg1Data(imageByte1); + } + + if(activity.getImg2() != null) { + byte[] imageByte2 = Base64.getDecoder().decode(activity.getImg2()); + activity.setImg2Data(imageByte2); + } + + outreachActivityRepo.save(activity); + + outputResponse.setResponse("Data saved successfully"); + + } catch (DataIntegrityViolationException | + JsonSyntaxException | NumberFormatException e){ + logger.error("Encountered exception EITHER due to incorrect payload syntax OR" + + " because of missing userId. " + e); + outputResponse.setError(400,"Encountered exception EITHER due to incorrect payload syntax OR " + + "because of missing userId. Please check the payload. " + e); + statusCode = HttpStatus.BAD_REQUEST; + } catch (Exception e){ + logger.error("Encountered exception while saving outreach activity. " + e); + outputResponse.setError(500,"Encountered exception while saving outreach activity. " + e); + statusCode = HttpStatus.INTERNAL_SERVER_ERROR; + } + + return new ResponseEntity<>(outputResponse.toString(),headers,statusCode); + } + + @Override + public ResponseEntity getActivitiesByUser(Integer userId, String authorization) { + OutputResponse outputResponse = new OutputResponse(); + HttpStatus statusCode = HttpStatus.OK; + + MultiValueMap headers = new LinkedMultiValueMap<>(); + headers.add("Content-Type", "application/json"); + + ArrayList activitiesObj = outreachActivityRepo.getActivitiesByUserID(userId); + + ArrayList activities = OutreachActivity.getActivitiesForUser(activitiesObj); + + outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create().toJson(activities)); + + return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode); + } + + @Override + public ResponseEntity getActivityById(Integer activityId, String authorization) { + OutputResponse outputResponse = new OutputResponse(); + HttpStatus statusCode = HttpStatus.OK; + + MultiValueMap headers = new LinkedMultiValueMap<>(); + headers.add("Content-Type", "application/json"); + + OutreachActivity activity = outreachActivityRepo.findOne(activityId); + + if (activity != null && activity.getImg1Data() != null){ + String img1 = Base64.getEncoder().encodeToString(activity.getImg1Data()); + activity.setImg1(img1); + } + + if (activity != null && activity.getImg2Data() != null){ + String img2 = Base64.getEncoder().encodeToString(activity.getImg2Data()); + activity.setImg2(img2); + } + + outputResponse.setResponse(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create().toJson(activity)); + + return new ResponseEntity<>(outputResponse.toStringWithSerializeNulls(),headers,statusCode); + } }