2022-09-08 23:53:54 -06:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
2022-09-14 22:56:32 -06:00
|
|
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
2022-09-08 23:53:54 -06:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2022-09-14 22:56:32 -06:00
|
|
|
func ListResourceFhir(c *gin.Context) {
|
2022-09-08 23:53:54 -06:00
|
|
|
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
|
|
|
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
|
|
|
|
2022-09-14 22:56:32 -06:00
|
|
|
listResourceQueryOptions := models.ListResourceQueryOptions{}
|
|
|
|
if len(c.Query("sourceResourceType")) > 0 {
|
|
|
|
listResourceQueryOptions.SourceResourceType = c.Query("sourceResourceType")
|
|
|
|
}
|
|
|
|
if len(c.Query("sourceID")) > 0 {
|
|
|
|
listResourceQueryOptions.SourceID = c.Query("sourceID")
|
|
|
|
}
|
|
|
|
|
|
|
|
wrappedResourceModels, err := databaseRepo.ListResources(c, listResourceQueryOptions)
|
2022-09-08 23:53:54 -06:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Errorln("An error occurred while retrieving resources", err)
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": wrappedResourceModels})
|
|
|
|
}
|
2022-09-14 22:56:32 -06:00
|
|
|
|
|
|
|
//this endpoint retrieves a specific resource by its ID
|
|
|
|
func GetResourceFhir(c *gin.Context) {
|
|
|
|
logger := c.MustGet("LOGGER").(*logrus.Entry)
|
|
|
|
databaseRepo := c.MustGet("REPOSITORY").(database.DatabaseRepository)
|
|
|
|
|
|
|
|
resourceId := strings.Trim(c.Param("resourceId"), "/")
|
|
|
|
wrappedResourceModel, err := databaseRepo.GetResource(c, resourceId)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
logger.Errorln("An error occurred while retrieving resource", err)
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"success": true, "data": wrappedResourceModel})
|
|
|
|
}
|