55 lines
1.3 KiB
Go
55 lines
1.3 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 OrganizationHandler struct {
|
|
Organization integration.OrganizationInterface
|
|
}
|
|
|
|
func NewOrganizationHandler(organization integration.OrganizationInterface) *OrganizationHandler {
|
|
return &OrganizationHandler{Organization: organization}
|
|
}
|
|
|
|
func (o OrganizationHandler) CreateOrganization(c *gin.Context) {
|
|
var bodyParam model.OrganizationRequest
|
|
if err := c.ShouldBindJSON(&bodyParam); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
bodyParam.Identifier = append(bodyParam.Identifier, common.GetIdentifier("organization"))
|
|
res, err := o.Organization.CreateOrganization(bodyParam)
|
|
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 OrganizationHandler) GetOrganizationPatient(c *gin.Context) {
|
|
id := c.Query("subject")
|
|
if id == "" {
|
|
c.JSON(http.StatusBadRequest, "Patient ID is required")
|
|
return
|
|
}
|
|
|
|
res, err := o.Organization.GetOrganizationPatient(id)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, res)
|
|
}
|