Files
chis_osi/server.go
T

46 lines
1.8 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"net/http"
"chis_osi/config"
"chis_osi/handler"
)
// 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)
}
hr := handler.NewHealthRecordHandler(client)
hc := handler.NewHealthCheckHandler(client)
pub := handler.NewPublicHandler(client)
mux := http.NewServeMux()
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/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)
fmt.Printf("chis_osi server listening on %s\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/dictionaries/grid-addresses?parentCode=<区划码>\n", addr)
fmt.Printf(" GET http://%s/api/dictionaries/doctors?manaUnitId=<机构码>\n", addr)
fmt.Printf(" GET http://%s/api/dictionaries/drugs?ypmc=<药品名>\n", addr)
fmt.Printf(" GET http://%s/api/dictionaries/orgs?parentId=<上级机构ID>\n", addr)
server := &http.Server{Addr: addr, Handler: mux}
return server.ListenAndServe()
}