Skip to content

Commit

Permalink
update orthanc client and es query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
iamatsundere committed Apr 6, 2021
1 parent 0697167 commit 73199ce
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
2 changes: 1 addition & 1 deletion study/study_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (app *StudyAPI) GetStudy(c *gin.Context) {
return
}

oStudyID, err := app.studyOrthanC.FindStudy(fmt.Sprintf("%s.%s", study.ProjectID, study.DICOMTags.StudyInstanceUID[0]))
oStudyID, err := app.studyOrthanC.FindObjectByUID("Study", fmt.Sprintf("%s.%s", study.ProjectID, study.DICOMTags.StudyInstanceUID[0]))
if err != nil {
utils.LogError(err)
resp.ErrorCode = constants.ServerError
Expand Down
47 changes: 42 additions & 5 deletions study/study_orthanc.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,27 @@ func NewStudyOrthanC(uri string) *StudyOrthanC {
}
}

func (orthanc *StudyOrthanC) FindStudy(studyInstanceUID string) (string, error) {
func (orthanc *StudyOrthanC) FindObjectByUID(scope, uid string) (string, error) {
var buf bytes.Buffer

level := ""
switch scope {
case "Study":
level = "Study"
break
case "Series":
level = "Series"
break
case "SOP":
level = "Instance"
break
}

body := &kvStr2Inf{
"Level": "Study",
"Level": level,
"Limit": 100,
"Query": kvStr2Inf{
"StudyInstanceUID": studyInstanceUID,
fmt.Sprintf("%sInstanceUID", scope): uid,
},
}
if err := json.NewEncoder(&buf).Encode(body); err != nil {
Expand Down Expand Up @@ -79,7 +93,7 @@ func (orthanc *StudyOrthanC) FindStudy(studyInstanceUID string) (string, error)
}

func (orthanc *StudyOrthanC) DeleteDicomFile(studyOrthanC *StudyOrthanC, s Study) error {
orthancStudyID, err := studyOrthanC.FindStudy(fmt.Sprintf("%s.%s", s.ProjectID, s.DICOMTags.StudyInstanceUID[0]))
orthancStudyID, err := studyOrthanC.FindObjectByUID("Study", fmt.Sprintf("%s.%s", s.ProjectID, s.DICOMTags.StudyInstanceUID[0]))
if err != nil {
utils.LogError(err)
return err
Expand Down Expand Up @@ -111,7 +125,7 @@ func (orthanc *StudyOrthanC) DeleteStudy(orthancStudyID string) error {
return nil
}

func (orthanc *StudyOrthanC) GetInstances(orthancStudyID string) (*[]entities.OrthancInstance, error) {
func (orthanc *StudyOrthanC) GetInstancesByStudy(orthancStudyID string) (*[]entities.OrthancInstance, error) {
uri := fmt.Sprintf("%s/studies/%s/instances", orthanc.uri, orthancStudyID)
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
Expand All @@ -134,6 +148,29 @@ func (orthanc *StudyOrthanC) GetInstances(orthancStudyID string) (*[]entities.Or
return &tags, nil
}

func (orthanc *StudyOrthanC) GetInstancesBySeries(orthancStudyID string) (*[]entities.OrthancInstance, error) {
uri := fmt.Sprintf("%s/series/%s/instances", orthanc.uri, orthancStudyID)
req, err := http.NewRequest("GET", uri, nil)
if err != nil {
return nil, err
}
res, err := orthanc.httpClient.Do(req)
if err != nil {
return nil, err
}

tags := make([]entities.OrthancInstance, 0)
if err := json.NewDecoder(res.Body).Decode(&tags); err != nil {
return nil, err
}

if res.StatusCode != http.StatusOK {
return nil, errors.New(res.Status)
}

return &tags, nil
}

func (orthanc *StudyOrthanC) GetSimplifiedTagsByID(orthancImageID string) (*entities.OrthancSimplfiedTags, error) {
uri := fmt.Sprintf("%s/instances/%s/simplified-tags", orthanc.uri, orthancImageID)

Expand Down
7 changes: 4 additions & 3 deletions utils/es_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ConvertQueryParamsToMap(context *gin.Context) map[string][]string {
continue
default:
kw := ""
if _, isIntField := mapIntFields[k]; !isIntField {
if _, isKeywordField := nonKeywordFields[k]; !isKeywordField {
kw = ".keyword"
}

Expand All @@ -61,10 +61,11 @@ func ConvertQueryParamsToMap(context *gin.Context) map[string][]string {

type kvStr2Inf = map[string]interface{}

var mapIntFields = map[string]bool{
var nonKeywordFields = map[string]bool{
"created": true,
"time_inserted": true,
"modified": true,
"archived": true,
}

func MakeSortQuery(sortRaw string) []kvStr2Inf {
Expand All @@ -85,7 +86,7 @@ func MakeSortQuery(sortRaw string) []kvStr2Inf {
criteria = sort
}

if _, found := mapIntFields[criteria]; !found {
if _, found := nonKeywordFields[criteria]; !found {
criteria += ".keyword"
}

Expand Down

0 comments on commit 73199ce

Please sign in to comment.