in wstl1/mapping_engine/harmonization/harmonizecode/remote_code_harmonizer.go [118:167]
func (h *RemoteCodeHarmonizer) Harmonize(sourceCode, sourceSystem, sourceName string) ([]HarmonizedCode, error) {
key := CodeLookupKey{
Code: sourceCode,
System: sourceSystem,
}
// Check cache before making http request.
if v, ok := h.cache.Get(key); ok {
return v.value, nil
}
u, err := url.Parse(h.address)
if err != nil {
return nil, fmt.Errorf("url is invalid %v", err)
}
u.Path = path.Join(u.Path, fmt.Sprintf("fhir/ConceptMap/%s/$translate", sourceName))
addr := u.String()
req, err := http.NewRequest(http.MethodGet, addr, nil)
if err != nil {
return nil, fmt.Errorf("error building new request %v", err)
}
q := req.URL.Query()
q.Add("code", sourceCode)
q.Add("system", sourceSystem)
req.URL.RawQuery = q.Encode()
raw, err := h.client.ExecuteRequest(context.Background(), req, "translate code", true)
if err != nil {
return nil, fmt.Errorf("error calling remote endpoint to harmonize code, %v", err)
}
res, err := rawToCodes(raw)
if err != nil {
return nil, fmt.Errorf("error unmarshalling translate result %v", err)
}
if len(res) == 0 {
res = append(res, HarmonizedCode{
Code: sourceCode,
System: fmt.Sprintf("%s-%s", sourceName, "unharmonized"),
})
}
// Add result to cache.
h.cache.Put(key, res)
return res, nil
}