feat(osi): 实现老年人自理能力查询(T-303)

This commit is contained in:
ila
2026-07-13 19:53:49 +08:00
parent ab5499acd4
commit d60b979785
13 changed files with 363 additions and 21 deletions
+35
View File
@@ -0,0 +1,35 @@
package handler
import (
"net/http"
"chis_osi/osi"
)
// ElderlyHandler 暴露老年人业务查询 HTTP 入口。
type ElderlyHandler struct {
client *osi.Client
}
func NewElderlyHandler(client *osi.Client) *ElderlyHandler {
return &ElderlyHandler{client: client}
}
// SelfCare 处理 GET /api/elderly/self-care?idCard=..&phrId=..&checkId=..
func (h *ElderlyHandler) SelfCare(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("idCard") == "" {
writeJSONError(w, http.StatusBadRequest, "idCard is required")
return
}
_, result, err := h.client.QueryElderlySelfCare(r.Context(), osi.ElderlySelfCareQuery{
IDCard: q.Get("idCard"),
PHRID: q.Get("phrId"),
CheckID: q.Get("checkId"),
})
writeRawOrError(w, result, err)
}
+40
View File
@@ -0,0 +1,40 @@
package handler
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestElderlySelfCareReturnsRawResponse(t *testing.T) {
client, seenPath := newTestClient(t, `{"code":"01","message":"操作成功","data":[{"checkId":"LNR-1","jc":"1","zpfs":"100"}]}`)
h := NewElderlyHandler(client)
req := httptest.NewRequest(http.MethodGet, "/api/elderly/self-care?idCard=TEST-ID&phrId=PHR-1", nil)
rec := httptest.NewRecorder()
h.SelfCare(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d", rec.Code)
}
if *seenPath != "/osi/api/auto/lnr/query" {
t.Fatalf("osi path = %q", *seenPath)
}
body, _ := io.ReadAll(rec.Body)
if !strings.Contains(string(body), `"zpfs":"100"`) {
t.Fatalf("body missing assessment content: %s", body)
}
}
func TestElderlySelfCareRequiresIDCard(t *testing.T) {
h := NewElderlyHandler(nil)
req := httptest.NewRequest(http.MethodGet, "/api/elderly/self-care?phrId=PHR-1", nil)
rec := httptest.NewRecorder()
h.SelfCare(rec, req)
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want 400", rec.Code)
}
}