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