package handler import ( "net/http" "satusehat-rssa/internal/integration" "satusehat-rssa/internal/model" "satusehat-rssa/pkg/common" "github.com/gin-gonic/gin" ) type DiagnosisReportHandler struct { DiagnosisReport integration.DiagnosisReportInterface } func NewDiagnosisReportHandler(diagnosisReport integration.DiagnosisReportInterface) *DiagnosisReportHandler { return &DiagnosisReportHandler{DiagnosisReport: diagnosisReport} } func (d *DiagnosisReportHandler) CreateDiagnosisReport(c *gin.Context) { var req model.DiagnosticReportRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } identifier := common.GetIdentifier("diagnostic") identifier.System += "/lab" req.Identifier = append(req.Identifier, identifier) res, err := d.DiagnosisReport.CreateDiagnosisReport(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 (d *DiagnosisReportHandler) UpdateDiagnosisReport(c *gin.Context) { var req model.DiagnosticReportRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } req.Id = c.Param("id") identifier := common.GetIdentifier("diagnostic") identifier.System += "/lab" req.Identifier = append(req.Identifier, identifier) res, err := d.DiagnosisReport.UpdateDiagnosisReport(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) }