- osi.QueryHealthChecks(/auto/jktj/query,返回全部体检数组) - contract.HealthCheckRecordSummary:驼峰 idCard(≠最近一次小写 idcard)、checkId 可空 - HTTP 端点 GET /api/health-check/all - 单测含 null checkId 场景;实测端点已部署 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
96 lines
3.1 KiB
Go
96 lines
3.1 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)
|
|
}
|
|
|
|
// All 处理 GET /api/health-check/all?idCard=..|phrid=..|empiId=..
|
|
// 返回某人全部体检(JKTJ00002 数组)的平台完整响应;历史记录 checkId 可能为空。
|
|
func (h *HealthCheckHandler) All(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.QueryHealthChecks(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")
|
|
}
|