I'm fairly new to Neo4j but already appreciate the potentials it may have posses. And I've made quite a bit of progress in a short month or so playing around with it after installing the Desktop version. The use case I'm trying to work with is like a member data table where members are referred to become members. One may only be referred or recognized as a member by referral from another member.
So I have created the node Member and imported the data into it. I have also created relationship REFERS_DL that references itself. That means a memberId is referred by another member who is indicated in the referralId, except the top node or first person who does not have a referralId. The sample member data and node visualization and relationship are shown below:
The business logic requires that lineage data/nodes be generated for each members' organization using the data in the member node. Along with this lineage, the Type Level be derived as well. The business logic for the Type Level stipulates that the level starts with 1 (if memberType = A) or 0 (if memberType = C) for the origin node of the organization/lineage being processed, and the level only increments by 1 for each leg when it encounters a downline member in the lineage that is of member type 'A', otherwise, it inherits whatever member level was assigned to its predecessor.
Below shows the lineage for organization with origin node Ini(meberId = 100) and the lineage data with the expected MeberLevel:
So the challenge I have is how the generate the MemberLevel. I am using the Cypher query below to generate the lineage:
WHERE m1.memberId = '100'
WITH m1.memberId AS OriginId,m1.name AS OriginNode,m2.memberId AS MemberId,m2.name AS Member,m2.referralId AS ReferralId,m2.name AS ReferredBy, m2.memberType AS MemberType
Is it possible to incorporate a logic in the query that can generate MemberLevel and what would that logic be? Or does that need to be handled differently?
Really looking forward to your suggestions and assistance in this.
Thanks in anticipation.