81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"satusehat-rssa/internal/integration"
|
|
"satusehat-rssa/internal/model"
|
|
"satusehat-rssa/pkg/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type EpisodeOfCareHandler struct {
|
|
// Define any dependencies needed for the handler
|
|
EpisodeOfCare integration.EpisodeOfCareInterface
|
|
}
|
|
|
|
func NewEpisodeOfCareHandler(episodeOfCare integration.EpisodeOfCareInterface) *EpisodeOfCareHandler {
|
|
return &EpisodeOfCareHandler{EpisodeOfCare: episodeOfCare}
|
|
}
|
|
|
|
// Add methods for handling episode of care-related requests here
|
|
func (e *EpisodeOfCareHandler) CreateEpisodeOfCare(c *gin.Context) {
|
|
var req model.EpisodeOfCareRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
req.Identifier = append(req.Identifier, common.GetIdentifier("episode-of-care"))
|
|
res, err := e.EpisodeOfCare.CreateEpisodeOfCare(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 (e *EpisodeOfCareHandler) GetEpisodeOfCareByPatient(c *gin.Context) {
|
|
id := c.Query("patient")
|
|
if id == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "Patient is required"})
|
|
return
|
|
}
|
|
|
|
episodeOfCare, err := e.EpisodeOfCare.GetEpisodeOfCareByPatient(id)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
if episodeOfCare == nil {
|
|
c.JSON(http.StatusNotFound, gin.H{"message": "Episode of care not found"})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, episodeOfCare)
|
|
}
|
|
|
|
func (e *EpisodeOfCareHandler) UpdateEpisodeOfCare(c *gin.Context) {
|
|
var req model.EpisodeOfCareRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
req.Id = c.Param("id")
|
|
req.Identifier = append(req.Identifier, common.GetIdentifier("episode-of-care"))
|
|
res, err := e.EpisodeOfCare.UpdateEpisodeOfCare(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)
|
|
}
|