- DrugQuery.PageNo 去 omitempty(pageNo=0 也上送)+ 加 PageSize - handler Drugs 改 pageNo 必填(parseRequiredInt,缺则返回 400)+ 读 pageSize - 补缺 pageNo 返回 400 的测试 - 依 docx;YPML00001 未真实联调,pageNo 是否真必填待厂家样本核对 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
109 lines
3.0 KiB
Go
109 lines
3.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"chis_osi/osi"
|
|
)
|
|
|
|
// PublicHandler 暴露 OSI 公开查询类 HTTP 入口。
|
|
type PublicHandler struct {
|
|
client *osi.Client
|
|
}
|
|
|
|
func NewPublicHandler(client *osi.Client) *PublicHandler {
|
|
return &PublicHandler{client: client}
|
|
}
|
|
|
|
// GridAddresses 处理 GET /api/dictionaries/grid-addresses?parentCode=..&pageNo=..&operateUser=..
|
|
func (h *PublicHandler) GridAddresses(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
pageNo, ok := parseOptionalInt(w, q.Get("pageNo"), "pageNo")
|
|
if !ok {
|
|
return
|
|
}
|
|
_, result, err := h.client.QueryGridAddress(r.Context(), osi.GridAddressQuery{
|
|
ParentCode: q.Get("parentCode"),
|
|
PageNo: pageNo,
|
|
OperateUser: q.Get("operateUser"),
|
|
})
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
// Doctors 处理 GET /api/dictionaries/doctors?manaUnitId=..&operateUser=..
|
|
func (h *PublicHandler) Doctors(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
_, result, err := h.client.QueryDoctors(r.Context(), osi.DoctorQuery{
|
|
ManaUnitID: q.Get("manaUnitId"),
|
|
OperateUser: q.Get("operateUser"),
|
|
})
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
// Drugs 处理 GET /api/dictionaries/drugs?ypmc=..&pym=..&pageNo=..
|
|
func (h *PublicHandler) Drugs(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
pageNo, ok := parseRequiredInt(w, q.Get("pageNo"), "pageNo") // docx: 药品目录是分页查询,pageNo 必填
|
|
if !ok {
|
|
return
|
|
}
|
|
pageSize, ok := parseOptionalInt(w, q.Get("pageSize"), "pageSize")
|
|
if !ok {
|
|
return
|
|
}
|
|
_, result, err := h.client.QueryDrugs(r.Context(), osi.DrugQuery{
|
|
PageNo: pageNo,
|
|
PageSize: pageSize,
|
|
YPMC: q.Get("ypmc"),
|
|
PYM: q.Get("pym"),
|
|
})
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
// Orgs 处理 GET /api/dictionaries/orgs?organizCode=..&parentId=..
|
|
func (h *PublicHandler) Orgs(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method != http.MethodGet {
|
|
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
|
|
return
|
|
}
|
|
q := r.URL.Query()
|
|
_, result, err := h.client.QueryOrgs(r.Context(), osi.OrgQuery{
|
|
OrganizCode: q.Get("organizCode"),
|
|
ParentID: q.Get("parentId"),
|
|
})
|
|
writeRawOrError(w, result, err)
|
|
}
|
|
|
|
func parseRequiredInt(w http.ResponseWriter, raw string, name string) (int, bool) {
|
|
if raw == "" {
|
|
writeJSONError(w, http.StatusBadRequest, name+" is required")
|
|
return 0, false
|
|
}
|
|
return parseOptionalInt(w, raw, name)
|
|
}
|
|
|
|
func parseOptionalInt(w http.ResponseWriter, raw string, name string) (int, bool) {
|
|
if raw == "" {
|
|
return 0, true
|
|
}
|
|
value, err := strconv.Atoi(raw)
|
|
if err != nil {
|
|
writeJSONError(w, http.StatusBadRequest, name+" must be an integer")
|
|
return 0, false
|
|
}
|
|
return value, true
|
|
}
|