89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"inou/lib"
|
|
)
|
|
|
|
func handleSlices(w http.ResponseWriter, r *http.Request) {
|
|
ctx := getAccessContextOrFail(w, r)
|
|
if ctx == nil {
|
|
return
|
|
}
|
|
|
|
dossierID := r.URL.Query().Get("dossier")
|
|
if dossierID == "" {
|
|
dossierID = r.URL.Query().Get("token")
|
|
}
|
|
seriesID := r.URL.Query().Get("series")
|
|
if dossierID == "" || seriesID == "" {
|
|
http.Error(w, "dossier and series required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
// RBAC: Check read access to dossier
|
|
if !requireDossierAccess(w, ctx, dossierID) {
|
|
return
|
|
}
|
|
|
|
entries, err := lib.EntryChildrenByType(dossierID, seriesID, "slice")
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
slices := make([]map[string]interface{}, 0)
|
|
|
|
for _, e := range entries {
|
|
var data struct {
|
|
SliceLocation float64 `json:"slice_location"`
|
|
SliceThickness float64 `json:"slice_thickness"`
|
|
Rows int `json:"rows"`
|
|
Cols int `json:"cols"`
|
|
WindowCenter float64 `json:"window_center"`
|
|
WindowWidth float64 `json:"window_width"`
|
|
WindowCenter2 float64 `json:"window_center_2"`
|
|
WindowWidth2 float64 `json:"window_width_2"`
|
|
PixelSpacingR float64 `json:"pixel_spacing_row"`
|
|
PixelSpacingC float64 `json:"pixel_spacing_col"`
|
|
PosX float64 `json:"image_position_x"`
|
|
PosY float64 `json:"image_position_y"`
|
|
PosZ float64 `json:"image_position_z"`
|
|
ImageOrientation string `json:"image_orientation"`
|
|
}
|
|
json.Unmarshal([]byte(e.Data), &data)
|
|
|
|
slice := map[string]interface{}{
|
|
"id": e.EntryID,
|
|
"image_url": "https://inou.com/image/" + e.EntryID,
|
|
"instance_number": e.Ordinal,
|
|
"orientation": e.Type,
|
|
"slice_location": data.SliceLocation,
|
|
"slice_thickness": data.SliceThickness,
|
|
"rows": data.Rows,
|
|
"cols": data.Cols,
|
|
"window_center": data.WindowCenter,
|
|
"window_width": data.WindowWidth,
|
|
"window_center_2": data.WindowCenter2,
|
|
"window_width_2": data.WindowWidth2,
|
|
"pixel_spacing_row": data.PixelSpacingR,
|
|
"pixel_spacing_col": data.PixelSpacingC,
|
|
"pos_x": data.PosX,
|
|
"pos_y": data.PosY,
|
|
"pos_z": data.PosZ,
|
|
"image_orientation": data.ImageOrientation,
|
|
}
|
|
slices = append(slices, slice)
|
|
}
|
|
|
|
response := map[string]interface{}{
|
|
"slices": slices,
|
|
"contact_sheet_url": "https://inou.com/contact-sheet.webp/" + seriesID + "?token=" + dossierID,
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
json.NewEncoder(w).Encode(response)
|
|
}
|