mastering bridging
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"satusehat-rssa/internal/integration"
|
||||
"satusehat-rssa/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ImagingStudyHandler struct {
|
||||
ImagingStudy integration.ImagingStudyInterface
|
||||
}
|
||||
|
||||
func NewImagingStudyHandler(ImagingStudy integration.ImagingStudyInterface) *ImagingStudyHandler {
|
||||
return &ImagingStudyHandler{ImagingStudy: ImagingStudy}
|
||||
}
|
||||
|
||||
func (h ImagingStudyHandler) CreateImagingStudy(c *gin.Context) {
|
||||
var req model.ImagingStudyRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Identifier) < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "identifier is required."})
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Identifier) > 0 {
|
||||
for k, i := range req.Identifier {
|
||||
if k == 0 && i.Value == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("identifier[%d].value (ACSN) required", k)})
|
||||
return
|
||||
}
|
||||
|
||||
// if k == 1 && i.Value == "" {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("identifier[%d].value (urn:dicom:uid) required", k)})
|
||||
// return
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
res, err := h.ImagingStudy.CreateImagingStudy(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 (h ImagingStudyHandler) UpdateImagingStudy(c *gin.Context) {
|
||||
var req model.ImagingStudyRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Identifier) < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "identifier is required."})
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Identifier) > 0 {
|
||||
for k, i := range req.Identifier {
|
||||
if k == 0 && i.Value == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("identifier[%d].value (ACSN) required", k)})
|
||||
return
|
||||
}
|
||||
|
||||
// if k == 1 && i.Value == "" {
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("identifier[%d].value (urn:dicom:uid) required", k)})
|
||||
// return
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
req.Id = c.Param("id")
|
||||
res, err := h.ImagingStudy.CreateImagingStudy(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)
|
||||
}
|
||||
Reference in New Issue
Block a user