Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerContext.cpp @ 5287:c04230962098 am-experimental
wip: 'dicomWeb' json format + 'include' get arguments
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 28 Apr 2023 10:42:27 +0200 |
parents | a7d95f951f8a |
children | c9ea57d73603 |
comparison
equal
deleted
inserted
replaced
5286:28f0e38e4082 | 5287:c04230962098 |
---|---|
1985 | 1985 |
1986 | 1986 |
1987 static void SerializeExpandedResource(Json::Value& target, | 1987 static void SerializeExpandedResource(Json::Value& target, |
1988 const ExpandedResource& resource, | 1988 const ExpandedResource& resource, |
1989 DicomToJsonFormat format, | 1989 DicomToJsonFormat format, |
1990 const std::set<DicomTag>& requestedTags) | 1990 const std::set<DicomTag>& requestedTags, |
1991 ExpandResourceFlags expandFlags) | |
1991 { | 1992 { |
1992 target = Json::objectValue; | 1993 target = Json::objectValue; |
1993 | 1994 |
1994 target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true); | 1995 target["Type"] = GetResourceTypeText(resource.GetLevel(), false, true); |
1995 target["ID"] = resource.GetPublicId(); | 1996 target["ID"] = resource.GetPublicId(); |
2013 | 2014 |
2014 default: | 2015 default: |
2015 throw OrthancException(ErrorCode_InternalError); | 2016 throw OrthancException(ErrorCode_InternalError); |
2016 } | 2017 } |
2017 | 2018 |
2018 switch (resource.GetLevel()) | 2019 if (expandFlags & ExpandResourceFlags_IncludeChildren) |
2019 { | 2020 { |
2020 case ResourceType_Patient: | 2021 switch (resource.GetLevel()) |
2021 case ResourceType_Study: | 2022 { |
2022 case ResourceType_Series: | 2023 case ResourceType_Patient: |
2023 { | 2024 case ResourceType_Study: |
2024 Json::Value c = Json::arrayValue; | 2025 case ResourceType_Series: |
2025 | 2026 { |
2026 for (std::list<std::string>::const_iterator | 2027 Json::Value c = Json::arrayValue; |
2027 it = resource.childrenIds_.begin(); it != resource.childrenIds_.end(); ++it) | 2028 |
2028 { | 2029 for (std::list<std::string>::const_iterator |
2029 c.append(*it); | 2030 it = resource.childrenIds_.begin(); it != resource.childrenIds_.end(); ++it) |
2030 } | 2031 { |
2031 | 2032 c.append(*it); |
2032 if (resource.GetLevel() == ResourceType_Patient) | 2033 } |
2033 { | 2034 |
2034 target["Studies"] = c; | 2035 if (resource.GetLevel() == ResourceType_Patient) |
2035 } | 2036 { |
2036 else if (resource.GetLevel() == ResourceType_Study) | 2037 target["Studies"] = c; |
2037 { | 2038 } |
2038 target["Series"] = c; | 2039 else if (resource.GetLevel() == ResourceType_Study) |
2039 } | 2040 { |
2040 else | 2041 target["Series"] = c; |
2041 { | 2042 } |
2042 target["Instances"] = c; | 2043 else |
2043 } | 2044 { |
2044 break; | 2045 target["Instances"] = c; |
2045 } | 2046 } |
2046 | 2047 break; |
2047 case ResourceType_Instance: | 2048 } |
2048 break; | 2049 |
2049 | 2050 case ResourceType_Instance: |
2050 default: | 2051 break; |
2051 throw OrthancException(ErrorCode_InternalError); | 2052 |
2052 } | 2053 default: |
2053 | 2054 throw OrthancException(ErrorCode_InternalError); |
2055 } | |
2056 } | |
2057 | |
2054 switch (resource.GetLevel()) | 2058 switch (resource.GetLevel()) |
2055 { | 2059 { |
2056 case ResourceType_Patient: | 2060 case ResourceType_Patient: |
2057 case ResourceType_Study: | 2061 case ResourceType_Study: |
2058 break; | 2062 break; |
2111 target["LastUpdate"] = resource.lastUpdate_; | 2115 target["LastUpdate"] = resource.lastUpdate_; |
2112 } | 2116 } |
2113 } | 2117 } |
2114 | 2118 |
2115 // serialize tags | 2119 // serialize tags |
2116 | 2120 if (expandFlags & ExpandResourceFlags_IncludeMainDicomTags) |
2117 static const char* const MAIN_DICOM_TAGS = "MainDicomTags"; | 2121 { |
2118 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags"; | 2122 static const char* const MAIN_DICOM_TAGS = "MainDicomTags"; |
2119 | 2123 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags"; |
2120 DicomMap mainDicomTags; | 2124 |
2121 resource.GetMainDicomTags().ExtractResourceInformation(mainDicomTags, resource.GetLevel()); | 2125 DicomMap mainDicomTags; |
2122 | 2126 resource.GetMainDicomTags().ExtractResourceInformation(mainDicomTags, resource.GetLevel()); |
2123 target[MAIN_DICOM_TAGS] = Json::objectValue; | 2127 |
2124 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], mainDicomTags, format); | 2128 target[MAIN_DICOM_TAGS] = Json::objectValue; |
2125 | 2129 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], mainDicomTags, format); |
2126 if (resource.GetLevel() == ResourceType_Study) | 2130 |
2127 { | 2131 if (resource.GetLevel() == ResourceType_Study) |
2128 DicomMap patientMainDicomTags; | 2132 { |
2129 resource.GetMainDicomTags().ExtractPatientInformation(patientMainDicomTags); | 2133 DicomMap patientMainDicomTags; |
2130 | 2134 resource.GetMainDicomTags().ExtractPatientInformation(patientMainDicomTags); |
2131 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue; | 2135 |
2132 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format); | 2136 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue; |
2133 } | 2137 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format); |
2134 | 2138 } |
2135 if (requestedTags.size() > 0) | 2139 } |
2140 | |
2141 if ((expandFlags & ExpandResourceFlags_IncludeRequestedTags) | |
2142 && requestedTags.size() > 0) | |
2136 { | 2143 { |
2137 static const char* const REQUESTED_TAGS = "RequestedTags"; | 2144 static const char* const REQUESTED_TAGS = "RequestedTags"; |
2138 | 2145 |
2139 DicomMap tags; | 2146 DicomMap tags; |
2140 resource.GetMainDicomTags().ExtractTags(tags, requestedTags); | 2147 resource.GetMainDicomTags().ExtractTags(tags, requestedTags); |
2142 target[REQUESTED_TAGS] = Json::objectValue; | 2149 target[REQUESTED_TAGS] = Json::objectValue; |
2143 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format); | 2150 FromDcmtkBridge::ToJson(target[REQUESTED_TAGS], tags, format); |
2144 | 2151 |
2145 } | 2152 } |
2146 | 2153 |
2154 if (expandFlags & ExpandResourceFlags_IncludeLabels) | |
2147 { | 2155 { |
2148 Json::Value labels = Json::arrayValue; | 2156 Json::Value labels = Json::arrayValue; |
2149 | 2157 |
2150 for (std::set<std::string>::const_iterator it = resource.labels_.begin(); it != resource.labels_.end(); ++it) | 2158 for (std::set<std::string>::const_iterator it = resource.labels_.begin(); it != resource.labels_.end(); ++it) |
2151 { | 2159 { |
2376 bool ServerContext::ExpandResource(Json::Value& target, | 2384 bool ServerContext::ExpandResource(Json::Value& target, |
2377 const std::string& publicId, | 2385 const std::string& publicId, |
2378 ResourceType level, | 2386 ResourceType level, |
2379 DicomToJsonFormat format, | 2387 DicomToJsonFormat format, |
2380 const std::set<DicomTag>& requestedTags, | 2388 const std::set<DicomTag>& requestedTags, |
2389 ExpandResourceFlags expandFlags, | |
2381 bool allowStorageAccess) | 2390 bool allowStorageAccess) |
2382 { | 2391 { |
2383 std::string unusedInstanceId; | 2392 std::string unusedInstanceId; |
2384 Json::Value* unusedDicomAsJson = NULL; | 2393 Json::Value* unusedDicomAsJson = NULL; |
2385 DicomMap unusedMainDicomTags; | 2394 DicomMap unusedMainDicomTags; |
2386 | 2395 |
2387 return ExpandResource(target, publicId, unusedMainDicomTags, unusedInstanceId, unusedDicomAsJson, level, format, requestedTags, allowStorageAccess); | 2396 return ExpandResource(target, publicId, unusedMainDicomTags, unusedInstanceId, unusedDicomAsJson, level, format, requestedTags, expandFlags, allowStorageAccess); |
2388 } | 2397 } |
2389 | 2398 |
2390 bool ServerContext::ExpandResource(Json::Value& target, | 2399 bool ServerContext::ExpandResource(Json::Value& target, |
2391 const std::string& publicId, | 2400 const std::string& publicId, |
2392 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available) | 2401 const DicomMap& mainDicomTags, // optional: the main dicom tags for the resource (if already available) |
2393 const std::string& instanceId, // optional: the id of an instance for the resource (if already available) | 2402 const std::string& instanceId, // optional: the id of an instance for the resource (if already available) |
2394 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available) | 2403 const Json::Value* dicomAsJson, // optional: the dicom-as-json for the resource (if already available) |
2395 ResourceType level, | 2404 ResourceType level, |
2396 DicomToJsonFormat format, | 2405 DicomToJsonFormat format, |
2397 const std::set<DicomTag>& requestedTags, | 2406 const std::set<DicomTag>& requestedTags, |
2407 ExpandResourceFlags expandFlags, | |
2398 bool allowStorageAccess) | 2408 bool allowStorageAccess) |
2399 { | 2409 { |
2400 ExpandedResource resource; | 2410 ExpandedResource resource; |
2401 | 2411 |
2402 if (ExpandResource(resource, publicId, mainDicomTags, instanceId, dicomAsJson, level, requestedTags, ExpandResourceFlags_Default, allowStorageAccess)) | 2412 if (ExpandResource(resource, publicId, mainDicomTags, instanceId, dicomAsJson, level, requestedTags, expandFlags, allowStorageAccess)) |
2403 { | 2413 { |
2404 SerializeExpandedResource(target, resource, format, requestedTags); | 2414 SerializeExpandedResource(target, resource, format, requestedTags, expandFlags); |
2405 return true; | 2415 return true; |
2406 } | 2416 } |
2407 | 2417 |
2408 return false; | 2418 return false; |
2409 } | 2419 } |