1 #include <analyzer/service_data.hpp> 2 3 namespace analyzer 4 { 5 6 void ServiceData::addCallout(const nlohmann::json& i_callout) 7 { 8 // The new callout is either a hardware callout with a location code or a 9 // procedure callout. 10 11 std::string type{}; 12 if (i_callout.contains("LocationCode")) 13 { 14 type = "LocationCode"; 15 } 16 else if (i_callout.contains("Procedure")) 17 { 18 type = "Procedure"; 19 } 20 else 21 { 22 throw std::logic_error("Unsupported callout: " + i_callout.dump()); 23 } 24 25 // A map to determine the priority order. All of the medium priorities, 26 // including the medium group priorities, are all the same level. 27 static const std::map<std::string, unsigned int> m = { 28 {"H", 3}, {"M", 2}, {"A", 2}, {"B", 2}, {"C", 2}, {"L", 1}, 29 }; 30 31 bool addCallout = true; 32 33 for (auto& c : iv_calloutList) 34 { 35 if (c.contains(type) && (c.at(type) == i_callout.at(type))) 36 { 37 // The new callout already exists. Don't add a new callout. 38 addCallout = false; 39 40 if (m.at(c.at("Priority")) < m.at(i_callout.at("Priority"))) 41 { 42 // The new callout has a higher priority, update it. 43 c["Priority"] = i_callout.at("Priority"); 44 } 45 } 46 } 47 48 if (addCallout) 49 { 50 iv_calloutList.push_back(i_callout); 51 } 52 } 53 54 } // namespace analyzer 55