comparison OrthancServer/Sources/ServerContext.cpp @ 4935:acd3f72e2a21 more-tags

split ExpandResource in 2: read from DB and serialize to json. This will allow us to merge requested tags from both the DB and the file system
author Alain Mazy <am@osimis.io>
date Thu, 10 Mar 2022 19:00:43 +0100
parents 309fb4f02704
children 8422e4f99a18
comparison
equal deleted inserted replaced
4934:94a7b681b340 4935:acd3f72e2a21
2090 void ServerContext::SetUnknownSopClassAccepted(bool accepted) 2090 void ServerContext::SetUnknownSopClassAccepted(bool accepted)
2091 { 2091 {
2092 boost::mutex::scoped_lock lock(dynamicOptionsMutex_); 2092 boost::mutex::scoped_lock lock(dynamicOptionsMutex_);
2093 isUnknownSopClassAccepted_ = accepted; 2093 isUnknownSopClassAccepted_ = accepted;
2094 } 2094 }
2095
2096
2097 static void SerializeExpandedResource(Json::Value& target,
2098 const ExpandedResource& resource,
2099 DicomToJsonFormat format)
2100 {
2101 target = Json::objectValue;
2102
2103 target["Type"] = GetResourceTypeText(resource.type_, false, true);
2104 target["ID"] = resource.id_;
2105
2106 switch (resource.type_)
2107 {
2108 case ResourceType_Patient:
2109 break;
2110
2111 case ResourceType_Study:
2112 target["ParentPatient"] = resource.parentId_;
2113 break;
2114
2115 case ResourceType_Series:
2116 target["ParentStudy"] = resource.parentId_;
2117 break;
2118
2119 case ResourceType_Instance:
2120 target["ParentSeries"] = resource.parentId_;
2121 break;
2122
2123 default:
2124 throw OrthancException(ErrorCode_InternalError);
2125 }
2126
2127 switch (resource.type_)
2128 {
2129 case ResourceType_Patient:
2130 case ResourceType_Study:
2131 case ResourceType_Series:
2132 {
2133 Json::Value c = Json::arrayValue;
2134
2135 for (std::list<std::string>::const_iterator
2136 it = resource.childrenIds_.begin(); it != resource.childrenIds_.end(); ++it)
2137 {
2138 c.append(*it);
2139 }
2140
2141 if (resource.type_ == ResourceType_Patient)
2142 {
2143 target["Studies"] = c;
2144 }
2145 else if (resource.type_ == ResourceType_Study)
2146 {
2147 target["Series"] = c;
2148 }
2149 else
2150 {
2151 target["Instances"] = c;
2152 }
2153 break;
2154 }
2155
2156 case ResourceType_Instance:
2157 break;
2158
2159 default:
2160 throw OrthancException(ErrorCode_InternalError);
2161 }
2162
2163 switch (resource.type_)
2164 {
2165 case ResourceType_Patient:
2166 case ResourceType_Study:
2167 break;
2168
2169 case ResourceType_Series:
2170 if (resource.expectedNumberOfInstances_ < 0)
2171 {
2172 target["ExpectedNumberOfInstances"] = Json::nullValue;
2173 }
2174 else
2175 {
2176 target["ExpectedNumberOfInstances"] = resource.expectedNumberOfInstances_;
2177 }
2178 target["Status"] = resource.status_;
2179 break;
2180
2181 case ResourceType_Instance:
2182 {
2183 target["FileSize"] = static_cast<unsigned int>(resource.fileSize_);
2184 target["FileUuid"] = resource.fileUuid_;
2185
2186 if (resource.indexInSeries_ < 0)
2187 {
2188 target["IndexInSeries"] = Json::nullValue;
2189 }
2190 else
2191 {
2192 target["IndexInSeries"] = resource.indexInSeries_;
2193 }
2194
2195 break;
2196 }
2197
2198 default:
2199 throw OrthancException(ErrorCode_InternalError);
2200 }
2201
2202 if (!resource.anonymizedFrom_.empty())
2203 {
2204 target["AnonymizedFrom"] = resource.anonymizedFrom_;
2205 }
2206
2207 if (!resource.modifiedFrom_.empty())
2208 {
2209 target["ModifiedFrom"] = resource.modifiedFrom_;
2210 }
2211
2212 if (resource.type_ == ResourceType_Patient ||
2213 resource.type_ == ResourceType_Study ||
2214 resource.type_ == ResourceType_Series)
2215 {
2216 target["IsStable"] = resource.isStable_;
2217
2218 if (!resource.lastUpdate_.empty())
2219 {
2220 target["LastUpdate"] = resource.lastUpdate_;
2221 }
2222 }
2223
2224 // serialize tags
2225
2226 static const char* const MAIN_DICOM_TAGS = "MainDicomTags";
2227 static const char* const PATIENT_MAIN_DICOM_TAGS = "PatientMainDicomTags";
2228
2229 DicomMap mainDicomTags;
2230 resource.tags_.ExtractResourceInformation(mainDicomTags, resource.type_);
2231
2232 target[MAIN_DICOM_TAGS] = Json::objectValue;
2233 FromDcmtkBridge::ToJson(target[MAIN_DICOM_TAGS], mainDicomTags, format);
2234
2235 if (resource.type_ == ResourceType_Study)
2236 {
2237 DicomMap patientMainDicomTags;
2238 resource.tags_.ExtractPatientInformation(patientMainDicomTags);
2239
2240 target[PATIENT_MAIN_DICOM_TAGS] = Json::objectValue;
2241 FromDcmtkBridge::ToJson(target[PATIENT_MAIN_DICOM_TAGS], patientMainDicomTags, format);
2242 }
2243
2244 }
2245
2246
2247 bool ServerContext::ExpandResource(Json::Value& target,
2248 const std::string& publicId,
2249 ResourceType level,
2250 DicomToJsonFormat format)
2251 {
2252 ExpandedResource resource;
2253
2254 if (GetIndex().ExpandResource(resource, publicId, level, format))
2255 {
2256 // check the main dicom tags list has not changed since the resource was stored
2257
2258 if (resource.mainDicomTagsSignature_ != DicomMap::GetMainDicomTagsSignature(resource.type_))
2259 {
2260 OrthancConfiguration::ReaderLock lock;
2261 if (lock.GetConfiguration().IsInconsistentDicomTagsLogsEnabled())
2262 {
2263 LOG(WARNING) << Orthanc::GetResourceTypeText(resource.type_, false , false) << " has been stored with another version of Main Dicom Tags list, you should POST to /" << Orthanc::GetResourceTypeText(resource.type_, true, false) << "/" << resource.id_ << "/reconstruct to update the list of tags saved in DB. Some tags might be missing from this answer.";
2264 }
2265 }
2266
2267 // MORE_TAGS: TODO: possibly merge missing requested tags from /tags
2268
2269 SerializeExpandedResource(target, resource, format);
2270
2271 return true;
2272 }
2273
2274 return false;
2275 }
2276
2095 } 2277 }