import DISNET.services.ServiceDisnet as ServiceDisnet import DISNET.objects.CuiMapObject as CuiMapObject import DISNET.objects.DisnetIdMapObject as DisnetIdMapObject import DISNET.Constants as Constants C = Constants.Constants # easier access to constants class ServiceMapping(ServiceDisnet.ServiceDisnet): """Class to instance objects to access methods related to the Mapping layer. It inherits from the ServiceDisnet class """ def __init__(self): ServiceDisnet.ServiceDisnet.__init__(self) def getDisnetIdsByCui(self, cui: (int,str)) -> list[DisnetIdMapObject.DisnetIdMapObject]: """Method to get all the mappings of a specified cui. :param cui: cui of the disease to map :raises NoResultsFoundException: when no results are found """ url = C.MAIN_PATH + C.PATH_MAPS + C.SLASH + cui + C.PATH_DISNET_ID_MAPS responseJson = self.connection(url) return self.__getAllDisnetIdMappings(responseJson) def getCuisByDisnetId(self, disnetId: (int,str)) -> list[CuiMapObject.CuiMapObject]: """Method to get all the cui mappings of a specified id. :param id: id of the disease to map :raises NoResultsFoundException: when no results are found """ url = C.MAIN_PATH + C.PATH_MAPS + C.SLASH + disnetId + C.PATH_CUI_MAPS responseJson = self.connection(url) return self.__getAllCuisMappings(responseJson) def __getAllDisnetIdMappings(self, responseJson): """Method to get all the Disnet Id Mappings from the response received in other methods :param response: json containing the response of the get petition """ returnList = [] listIdMapsJson = responseJson["data"] for idMapJson in listIdMapsJson: disnetId = idMapJson["disnetId"] vocabulary = idMapJson["vocabulary"] source = idMapJson["source"] disnetIdMap = DisnetIdMapObject.DisnetIdMapObject(disnetId,vocabulary,source) returnList.append(disnetIdMap) return returnList def __getAllCuisMappings(self, responseJson): """Method to get all the cui Mappings from the response received in other methods :param response: json containing the response of the get petition """ returnList = [] listCuiMapsJson = responseJson["data"] for cuiMapJson in listCuiMapsJson: cui = cuiMapJson["cui"] vocabulary = cuiMapJson["vocabulary"] source = cuiMapJson["source"] disnetIdMap = CuiMapObject.CuiMapObject(cui,vocabulary,source) returnList.append(disnetIdMap) return returnList