Files
satusehat-bridging/internal/handler/patient_handler.go
2025-11-24 09:13:08 +07:00

48 lines
1.2 KiB
Go

package handler
import (
"net/http"
"satusehat-rssa/internal/integration"
"satusehat-rssa/internal/model"
"github.com/gin-gonic/gin"
)
type PatientHandler struct {
// Define any dependencies or services needed for the PatientHandler
Patient integration.PatientInterface
}
func NewPatientHandler(patient integration.PatientInterface) *PatientHandler {
return &PatientHandler{Patient: patient}
}
// Add methods for handling patient-related requests here
func (p *PatientHandler) GetPatientByNIK(c *gin.Context) {
param := c.Query("identifier")
res, err := p.Patient.GetPatientByNIK(param)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, res)
}
func (p *PatientHandler) CreatePatient(c *gin.Context) {
var req model.PatientRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
res, err := p.Patient.CreataPatient(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)
}