package patient import ( "github.com/gin-gonic/gin" "github.com/google/uuid" "net/http" "os" "template_blueprint/internal/database" "template_blueprint/pkg/database/mongo" "template_blueprint/pkg/models/patient" ) func InsertPatient(c *gin.Context) { local := os.Getenv("MONGODB_DEV_LOCAL") db := database.New(local).GetDB() if db == nil { c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) return } mongoDB := mongo.NewDatabaseService(db) var reqInsert *patient.Patient err := c.Bind(&reqInsert) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()}) return } reqInsert.ID = uuid.New().String() errInsert := mongoDB.InsertPatient(reqInsert) if errInsert != nil { c.JSON(http.StatusInternalServerError, gin.H{"message": errInsert.Error()}) return } c.JSON(http.StatusOK, gin.H{"message": "Patient successfully inserted"}) } func GetAllPatient(c *gin.Context) { local := os.Getenv("MONGODB_DEV_LOCAL") db := database.New(local).GetDB() if db == nil { c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"}) return } mongoDB := mongo.NewDatabaseService(db) dataPatient, errSelect := mongoDB.GetAllDataPatient() if errSelect != nil { c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()}) return } c.JSON(http.StatusOK, dataPatient) }