package handler import ( "net/http" "satusehat-rssa/internal/integration" "satusehat-rssa/internal/model" "github.com/gin-gonic/gin" ) type ObservationHandler struct { // Define any dependencies needed for the handler Observation integration.ObservationInterface } func NewObservationHandler(observation integration.ObservationInterface) *ObservationHandler { return &ObservationHandler{Observation: observation} } // Add methods for handling observation-related requests here func (o *ObservationHandler) CreateObservation(c *gin.Context) { var req model.ObservationRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } res, err := o.Observation.CreateObservation(req) if err != nil { if res != nil { c.JSON(http.StatusInternalServerError, res) return } c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, res) } func (o *ObservationHandler) GetObservationByPatient(c *gin.Context) { id := c.Query("subject") if id == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "Subject is required"}) return } observation, err := o.Observation.GetObservationByPatient(id) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } if observation == nil { c.JSON(http.StatusNotFound, gin.H{"message": "Observation not found"}) return } c.JSON(http.StatusOK, observation) } func (o *ObservationHandler) UpdateObservation(c *gin.Context) { var req model.ObservationRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } req.Id = c.Param("id") res, err := o.Observation.UpdateObservation(req) if err != nil { if res != nil { c.JSON(http.StatusInternalServerError, res) return } c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, res) }