mirror of
https://github.com/AmanTahiliani/FHIR-Sandbox.git
synced 2026-08-07 19:56:17 -04:00
Improved FHIR handling
This commit is contained in:
40
app/handlers/patients.go
Normal file
40
app/handlers/patients.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/AmanTahiliani/FHIR-Sandbox/app/middleware"
|
||||
"github.com/AmanTahiliani/FHIR-Sandbox/app/models"
|
||||
)
|
||||
|
||||
// HandlePatients renders the list of all synced patients for the current EHR.
|
||||
// GET /patients
|
||||
func (h *Handler) HandlePatients(w http.ResponseWriter, r *http.Request) {
|
||||
sess := middleware.SessionFromContext(r.Context())
|
||||
practitionerUser := middleware.UserFromContext(r.Context())
|
||||
|
||||
if sess == nil || practitionerUser == nil {
|
||||
h.handleUnauthorized(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
patients, err := h.store.ListUsersByRole(models.RolePatient, sess.EHRURL)
|
||||
if err != nil {
|
||||
log.Printf("handlers: HandlePatients ListUsersByRole failed: %v", err)
|
||||
h.renderError(w, http.StatusInternalServerError, "Failed to retrieve patients from the database.")
|
||||
return
|
||||
}
|
||||
|
||||
h.render(w, "patients.html", patientsData{
|
||||
Patients: patients,
|
||||
Practitioner: practitionerUser,
|
||||
Session: sess,
|
||||
})
|
||||
}
|
||||
|
||||
type patientsData struct {
|
||||
Patients []models.User
|
||||
Practitioner *models.User
|
||||
Session *models.Session
|
||||
}
|
||||
Reference in New Issue
Block a user