Get the relations for a given respondentId or patientNr + organizationId combination

@param type $respondentId
@param type $patientNr
@param type $organizationId
@return array
161148
public function getRelationsFor($respondentId, $patientNr = null, $organizationId = null, $onlyActive = true)
    {
        static $relationsCache = array();

        if (is_null($respondentId)) {
            $respondentId = $this->loader->getUtil()->getDbLookup()->getRespondentId($patientNr, $organizationId);
        }

        if (!array_key_exists($respondentId, $relationsCache)) {
            $relations = array();
            $filter = array('grr_id_respondent'=>$respondentId);
            if ($onlyActive) {
                $filter['grr_active'] = 1;
            }
            $rawRelations = $this->load($filter);
            foreach ($rawRelations as $relation)
            {
                $relations[$relation['grr_id']] = join(' ', array($relation['grr_type'], $relation['grr_first_name'], $relation['grr_last_name']));
            }
            $relationsCache[$respondentId] = $relations;
        }

        return $relationsCache[$respondentId];
    }
1147503
public function getMembership($userId, $organization = '')
    {
        $contents = $this
            ->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]))
            ->getBody()
            ->getContents();

        return $this->getSingleMemberShipFromJsonResponse($contents);
    }
1177435
public function setOrganization($id, $organizationId)
    {
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idOrganization/'.rawurlencode($organizationId));
    }
625109
def index_relations(sender, pid_type, json=None,
                    record=None, index=None, **kwargs):
    """"""
    if not json:
        json = {}
    pid = PersistentIdentifier.query.filter(
        PersistentIdentifier.object_uuid == record.id,
        PersistentIdentifier.pid_type == pid_type,
    ).one_or_none()
    relations = None
    if pid:
        relations = serialize_relations(pid)
        if relations:
            json['relations'] = relations
    return json
663737
public function unassignChild ($relationIdentifier, $id, $childId)
		{
			$relation = $this->getRelation($relationIdentifier);

			if (!$relation) {
				throw new RelationException('Invalid relation `' . $relationIdentifier);
			}

			if ($relation instanceof OneToMany) {
				$this->database->createQuery()
					->update()
					->table($relation->getRelatedTable())
					->set(
						array(
							$relation->getRelatedKey() => null,
						)
					)
					->whereEqual($relation->getRelatedKey(), $id)
					->whereEqual($relation->getKey(), $childId)
					->execute();
			} else if ($relation instanceof ManyToMany) {
				$this->database->createQuery()
					->delete()
					->from($relation->getRelationalTable())
					->whereEqual($relation->getKey(), $id)
					->whereEqual($relation->getRelatedKey(), $childId)
					->execute();
			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}
		}
463373
public function getOrganizationsByInnKpp($inn, $kpp = null, $includeRelations = false)
    {
        $response = $this->doRequest(
            self::RESOURCE_GET_ORGANIZATIONS_BY_INN_KPP,
            [
                'inn' => $inn,
                'kpp' => $kpp,
                'includeRelations' => $includeRelations?'true':'false'
            ]
        );

        return OrganizationList::fromStream($response);
    }
748447
public function show($id)
    {
        $ret = $this->get('/relations/'.urlencode($id).'.json');
        if (null === $ret) {
            return [];
        }

        return $ret['relation'];
    }
503058
public function mfaUpdate($id, $employeeId, $label)
    {
        $result = $this->mfaUpdateInternal([
            'id' => $id,
            'employee_id' => $employeeId,
            'label' => $label,
        ]);
        $statusCode = (int)$result[ 'statusCode' ];

        if ($statusCode === 200) {
            return $this->getResultAsArrayWithoutStatusCode($result);
        }

        $this->reportUnexpectedResponse($result, 1543879805);
    }
859739
public function findRelatedSourceRecords(int $sourceId, int $limit = null): array
    {
        /** @var Relations $relations */
        $relations = $this->framework->getAdapter(Relations::class);

        if (false === ($relation = $relations->getRelation($this->sourceTable, $this->sourceField))) {
            throw new \RuntimeException(\sprintf('The field %s.%s is not related', $this->sourceTable, $this->sourceField));
        }

        /** @var Model $relationsModel */
        $relationsModel = $this->framework->getAdapter(Model::class);

        $tagIds = $relationsModel->getRelatedValues($this->sourceTable, $this->sourceField, $sourceId);
        $tagIds = \array_values(\array_unique($tagIds));
        $tagIds = \array_map('intval', $tagIds);

        // Return if there are no tags
        if (0 === \count($tagIds)) {
            return [];
        }

        $query = \sprintf(
            'SELECT %s, COUNT(*) AS relevance FROM %s WHERE %s IN (%s) AND %s != ? GROUP BY %s ORDER BY relevance DESC',
            $relation['reference_field'],
            $relation['table'],
            $relation['related_field'],
            \implode(',', $tagIds),
            $relation['reference_field'],
            $relation['reference_field']
        );

        // Set the limit
        if ($limit > 0) {
            $query .= \sprintf(' LIMIT %s', $limit);
        }

        $related = [];

        // Generate the related records
        foreach ($this->db->fetchAll($query, [$sourceId]) as $record) {
            $related[$record[$relation['reference_field']]] = [
                'total' => \count($tagIds),
                'found' => $record['relevance'],
                'prcnt' => ($record['relevance'] / \count($tagIds)) * 100,
            ];
        }

        return $related;
    }
926709
public function getChildren ($relationIdentifier, $id, $inputQuery = null)
		{
			$relation = $this->getRelation($relationIdentifier);
			$query    = $this->database->createQuery();

			if ($relation instanceof OneToMany) {
				$query->whereEqual($relation->getRelatedTable() . '.' . $relation->getKey(), $id);

			} else if ($relation instanceof ManyToMany) {
				$query->addField($relation->getRelationalTable() . '.*')
					->leftJoinEqual(
						$relation->getRelationalTable(),
						$relation->getRelationalTable() . '.' .$relation->getRelatedKey(),
						$relation->getRelatedTable() . '.' . $relation->getRelatedKey()
					)
					->whereEqual($relation->getRelationalTable() . '.' . $relation->getKey(), $id);

			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}

			$query->composeWith($inputQuery);

			return $relation->getRelatedTableObject()->getRows($query);
		}
837801
protected function checkPatient($patientNr, $orgId)
    {
        if (! ($patientNr && $orgId)) {
            return false;
        }

        $select = $this->db->select();
        $select->from('gems__respondent2org', array('gr2o_id_user'))
            ->where('gr2o_patient_nr = ?', $patientNr)
            ->where('gr2o_id_organization = ?', $orgId);

        return $this->db->fetchOne($select);
    }
1246535
public function getOrganization($organizationId = null)
    {
        static $organizations = array();

        if (null === $organizationId) {
            $user = $this->getCurrentUser();

            if (! $user->isActive()) {
                // Check url only when not logged im
                $organizationId = $this->getOrganizationIdByUrl();
            }

            if (! $organizationId) {
                $organizationId = intval($user->getCurrentOrganizationId());
            }
        }

        if (! isset($organizations[$organizationId])) {
            $organizations[$organizationId] = $this->_loadClass(
                    'Organization',
                    true,
                    array($organizationId, $this->getAvailableStaffDefinitions())
                    );
        }

        return $organizations[$organizationId];
    }
1057476
public function findRelation($entity, $relationName, $orderColumn = null, $orderType = null) {
        $this->load();
        $mapper = MapperBuilder::buildFromClassName($this->mapping, get_class($entity));
        $relation = $mapper->getRelation($relationName);
        $relationMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());

        $selectQuery = "SELECT tmain.* FROM `" . $relationMapper->getTable() . "` tmain ";
        $joinQuery = QueryBuilder::buildJoinRelationQuery($relation, "tmain", "j1");
        $whereQuery = "WHERE j1." . $relation->getLocalColumn() . " = '" . $entity->getId() . "'";

        $orderQuery = "";
        if (!is_null($orderColumn)) {
            $orderQuery .= "ORDER BY $orderColumn ";
            if (!is_null($orderType)) {
                $orderQuery .= "$orderType";
            } else {
                $orderQuery .= "ASC";
            }
        }

        $query = $selectQuery . $joinQuery . $whereQuery . $orderQuery;
        $queryResult = $this->getDataSource()->query($query);
        if ($queryResult) {
            $collection = new Collection($relationMapper->getClass(), $queryResult, $relationMapper);
        } else {
            $collection = new Collection($relationMapper->getClass(), array(), $relationMapper);
        }

        return $collection;
    }
1295817
public function subsequentByPeriodByNumberAndByOrganization($periodId, $number, $organizationId, $databaseConnectionName = null)
  {
    if(empty($databaseConnectionName))
    {
      $databaseConnectionName = $this->databaseConnectionName;
    }

    return $this->JournalVoucher->setConnection($databaseConnectionName)
      ->where('period_id', '=', $periodId)
      ->where('number', '>', $number)
      ->where('organization_id', '=', $organizationId)
      ->get();
  }
947952
public function getRelatedNodes(AssetInterface $asset)
    {
        $relationMap = [];
        $relationMap[TypeHandling::getTypeForValue($asset)] = [$this->persistenceManager->getIdentifierByObject($asset)];

        if ($asset instanceof Image) {
            foreach ($asset->getVariants() as $variant) {
                $type = TypeHandling::getTypeForValue($variant);
                if (!isset($relationMap[$type])) {
                    $relationMap[$type] = [];
                }
                $relationMap[$type][] = $this->persistenceManager->getIdentifierByObject($variant);
            }
        }

        return $this->nodeDataRepository->findNodesByPathPrefixAndRelatedEntities(SiteService::SITES_ROOT_PATH, $relationMap);
    }
360198
public function getInfoAction($actorId, $id)
    {
        $em = $this->getDoctrine()->getManager();

        /** @var Address $entity */
        $entity = $em->getRepository('EcommerceBundle:Address')->findOneById($id);

        $addressResponse = new stdClass();
        $addressResponse->id = $entity->getId();
        $addressResponse->address = $entity->getAddress();
        $addressResponse->dni = $entity->getDni();
        $addressResponse->city = $entity->getCity();
        $addressResponse->state = $entity->getState()->getId();
        $addressResponse->country = $entity->getCountry()->getId();
        $addressResponse->phone = $entity->getPhone();
        $addressResponse->phone2 = $entity->getPhone2();
        $addressResponse->postalCode = $entity->getPostalCode();
        $addressResponse->preferredSchedule = $entity->getPreferredSchedule();
        
        return new JsonResponse($addressResponse);
    }
691403
function getAssociations(instance, ids, callback) {
  instance.db.find({ _id: { $in: ids } }, function(err, associations) {
    for(var cAssociation = 0; cAssociation < associations.length;
        cAssociation++) {
      associations[cAssociation].deviceId = associations[cAssociation]._id;
    }
    callback(err, associations);
  });
}