- GET /api/health-check/last(最近一次)+ /api/health-check/list(年度已检未检名单) - 回写平台完整响应 Result.Raw,抽 writeRawOrError 共用 - last 按 idCard/phrid/empiId;list 按 checkYear(必填)+idCard+checkType - 单测:路径/原样回写/缺参 400(脱敏假 OSI 后端);默认仅绑本机 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"chis_osi/osi"
|
|
)
|
|
|
|
// HealthCheckHandler 暴露健康体检查询的 HTTP 入口。
|
|
type HealthCheckHandler struct {
|
|
client *osi.Client
|
|
}
|
|
|
|
func NewHealthCheckHandler(client *osi.Client) *HealthCheckHandler {
|
|
return &HealthCheckHandler{client: client}
|
|
}
|
|
|
|
// Last 处理 GET /api/health-check/last?idCard=..|phrid=..|empiId=..
|
|
// 返回某人最近一次体检的平台完整响应(含全部子节点,见 docs/04 §11)。
|
|
func (h *HealthCheckHandler) Last(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
query := osi.FindHealthCheckQuery{
|
|
IDCard: q.Get("idCard"),
|
|
PHRID: q.Get("phrid"),
|
|
EMPIID: q.Get("empiId"),
|
|
}
|
|
if query.IDCard == "" && query.PHRID == "" && query.EMPIID == "" {
|
|
writeJSONError(w, http.StatusBadRequest, "provide one of: idCard, phrid, empiId")
|
|
return
|
|
}
|
|
_, result, err := h.client.LastHealthCheck(r.Context(), query)
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
// List 处理 GET /api/health-check/list?checkYear=..&idCard=..&checkType=..&page=..&rows=..
|
|
// 返回某年度已检/未检人员名单的平台完整响应(名单,非体检明细,见 docs/04 §11.4)。
|
|
func (h *HealthCheckHandler) List(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
if q.Get("checkYear") == "" {
|
|
writeJSONError(w, http.StatusBadRequest, "checkYear is required")
|
|
return
|
|
}
|
|
query := osi.ListHealthCheckQuery{
|
|
CheckYear: q.Get("checkYear"),
|
|
IDCard: q.Get("idCard"),
|
|
CheckType: q.Get("checkType"),
|
|
Page: q.Get("page"),
|
|
Rows: q.Get("rows"),
|
|
}
|
|
_, result, err := h.client.ListHealthCheckPeople(r.Context(), query)
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
// writeRawOrError 拿到平台响应就原样回写完整 JSON,否则按错误返回。
|
|
func writeRawOrError(w http.ResponseWriter, result osi.Result, err error) {
|
|
if len(result.Raw) > 0 {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
_, _ = w.Write(result.Raw)
|
|
return
|
|
}
|
|
if err != nil {
|
|
writeJSONError(w, http.StatusBadGateway, err.Error())
|
|
return
|
|
}
|
|
writeJSONError(w, http.StatusBadGateway, "empty response from OSI")
|
|
}
|