feat(handler): server 模式健康档案查询端点(T-208)

- GET /api/health-record/find 按 idCard/phrid/personName/empiId 查询
- 回写平台完整响应(Result.Raw),未建模字段不丢失
- 抽 buildOSIClient 共用构造,verify 与 server 复用
- 默认仅绑 127.0.0.1(端点返回真实档案 PII,避免暴露局域网)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ila
2026-07-08 00:05:22 +08:00
co-authored by Claude Opus 4.8
parent 55289e0746
commit 47eaf1051e
6 changed files with 175 additions and 15 deletions
+51
View File
@@ -0,0 +1,51 @@
package handler
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"chis_osi/osi"
)
func TestHealthRecordFindReturnsRawPlatformResponse(t *testing.T) {
osiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"healthRecord":{"phrId":"phr-001","adressNumber":"下围村1号"}}]}`))
}))
defer osiServer.Close()
transport, err := osi.NewTransport(osi.TransportConfig{Timeout: time.Second})
if err != nil {
t.Fatalf("NewTransport: %v", err)
}
client := osi.NewClient(osi.ClientConfig{BaseURL: osiServer.URL, UserName: "dyytgw", Ask: "secret", Transport: transport})
h := NewHealthRecordHandler(client)
req := httptest.NewRequest(http.MethodGet, "/api/health-record/find?idCard=440100199001011234", nil)
rec := httptest.NewRecorder()
h.Find(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d", rec.Code)
}
body, _ := io.ReadAll(rec.Body)
// 完整回写:未建模字段 adressNumber 也应原样出现
if !strings.Contains(string(body), `"phr-001"`) || !strings.Contains(string(body), "adressNumber") {
t.Fatalf("body missing full archive content: %s", body)
}
}
func TestHealthRecordFindRequiresIdentifier(t *testing.T) {
h := NewHealthRecordHandler(nil) // 无标识符时在触达 client 前就返回 400
req := httptest.NewRequest(http.MethodGet, "/api/health-record/find", nil)
rec := httptest.NewRecorder()
h.Find(rec, req)
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want 400", rec.Code)
}
}