package main import ( "fmt" "net/http" "chis_osi/config" "chis_osi/handler" "chis_osi/osi" ) // runServer 启动 server 模式 HTTP 服务。 func runServer(cfg config.Config, addr string) error { client, err := buildOSIClient(cfg) if err != nil { return fmt.Errorf("build osi client: %w", err) } mux := newServerMux(client, newServerHealthRecordUpserter(client)) fmt.Printf("chis_osi server listening on %s\n", addr) fmt.Printf(" POST http://%s/api/health-record/upsert\n", addr) fmt.Printf(" GET http://%s/api/health-record/find?idCard=<身份证>\n", addr) fmt.Printf(" GET http://%s/api/health-record/crowd?idCard=<身份证>\n", addr) fmt.Printf(" GET http://%s/api/health-check/last?idCard=<身份证>\n", addr) fmt.Printf(" GET http://%s/api/health-check/all?idCard=<身份证>\n", addr) fmt.Printf(" GET http://%s/api/health-check/list?checkYear=<年度>&idCard=<身份证>\n", addr) fmt.Printf(" GET http://%s/api/elderly/self-care?idCard=<身份证>&phrId=<档案号>&checkId=<检查主键>\n", addr) fmt.Printf(" GET http://%s/api/dictionaries/grid-addresses?parentCode=<区划码>&pageNo=1\n", addr) fmt.Printf(" GET http://%s/api/dictionaries/doctors?manaUnitId=<机构码>&operateUser=<操作人>\n", addr) fmt.Printf(" GET http://%s/api/dictionaries/drugs?pageNo=1&pageSize=10&ypmc=<药品名>&pym=<拼音码>\n", addr) fmt.Printf(" GET http://%s/api/dictionaries/orgs?organizCode=<机构码>&parentId=<上级机构ID>\n", addr) server := &http.Server{Addr: addr, Handler: mux} return server.ListenAndServe() } func newServerMux(client *osi.Client, upserter handler.HealthRecordUpserter) *http.ServeMux { hr := handler.NewHealthRecordHandler(client) hu := handler.NewHealthRecordUpsertHandler(upserter) hc := handler.NewHealthCheckHandler(client) elderly := handler.NewElderlyHandler(client) pub := handler.NewPublicHandler(client) mux := http.NewServeMux() mux.HandleFunc("/api/health-record/upsert", hu.Upsert) mux.HandleFunc("/api/health-record/find", hr.Find) mux.HandleFunc("/api/health-record/crowd", hr.Crowd) mux.HandleFunc("/api/health-check/last", hc.Last) mux.HandleFunc("/api/health-check/all", hc.All) mux.HandleFunc("/api/health-check/list", hc.List) mux.HandleFunc("/api/elderly/self-care", elderly.SelfCare) mux.HandleFunc("/api/dictionaries/grid-addresses", pub.GridAddresses) mux.HandleFunc("/api/dictionaries/doctors", pub.Doctors) mux.HandleFunc("/api/dictionaries/drugs", pub.Drugs) mux.HandleFunc("/api/dictionaries/orgs", pub.Orgs) return mux }