Hello,
I've just started learning Neo4j to do a POC for my current project. I want to have a final value for one of the node called Employee
, say certified or not certified based on the direct relation with the Credential
node or via the the group certificate when multiple Employee
nodes can be grouped for certificates for group activities. Every certificate/credential will have an expiry date, and if any of the certificate gets expired then the employee will be called non-compliant and has to do the certification again. This is how the data model looks like:
I was able to get the list of all employees for a company and their associated certificates(direct/ via group) and mapped them with each employee.
MATCH (c:Company { id: 1000})
WITH c {
.id,
.name,
employees: [(e:Employee)-[:WORKS_AT]->(c) | e {
.empId,
.name,
credentials: [(e)<-[:ATTACHED_TO]-(cr:Credential) | cr {
.credentialId,
.credentialType,
.expiration,
status: CASE WHEN duration.inDays(date(), cr.expiration).days > 0 then 'Compliant' ELSE 'Expired' END
}],
egCredentials: [(e)-[:PART_OF]->(:EmployeeGroup)<-[:ATTACHED_TO]-(cr:Credential) | cr {
.credentialId,
.credentialType,
.expiration,
status: CASE WHEN duration.inDays(date(), cr.expiration).days > 0 then 'Compliant' ELSE 'Expired' END
}]
}]
}
RETURN
c;
This would give me data like
---
c
---
{
"id": XXX,
"name": "XYX Company",
"employees": [
// this employee should be marked as non-compliant
// as one the certificate is expired
{
"empId": XXXXX,
"name": "ABC",
"credentials": [
{
"credentialType": "AWS Training",
"credentialId": XXXYYX,
"expiration": "2024-06-03",
"status": "Compliant"
},
{
"credentialType": "Java Traing",
"credentialId": XXHAVFDS,
"expiration": "2022-08-19",
"status": "Expired"
},
// ....
],
"egCredentials": [
// similar values like above credentials key
]
},
// ....
]
But what ultimately I wanted was to have a single value based on both the properties (credentials[]
& egCredentials[]
) of each Employee
node in the list.
I have 2 use cases here, one for single employee's compliance check and one for projecting the forecast for current date till the next 11 months where I should get the number of compliant/non-compliant employees by the month.
-
Use case 1, single employee compliance check
return the employee node with thestatus
ascompliant
ornon-compliant
based the validity of all the credentials which are attached to theEmployee
directly or viaEmployeeGroup
. If any of the credential from both the relation is expired then the whole status should benon-compliant
{
"empId": XXXX,
"name": "ABC",
"status": "compliant", // or "non-compliant"
"credentials": [] // should be a merged list if possible from both direct and via EmployeeGroup relation to Credential node
}
- Use case 2, forecast of compliant employees for the whole year
The first item should be today's date, next items will be from next month's start or end date does not matter as we'll count for whole month and not for any individual date. Meaning, if the credential is expiring on 1st of the month or last of the month; for future forecast we can show that it will be non-compliant in that month.
[
{
"month": current-month,
"compliantEmployeeCount": X,
"nonCompliantEmployeeCount": X
},
{
"month": current-month + 1,
"compliantEmployeeCount": X,
"nonCompliantEmployeeCount": X
},
{
"month": current-month + 2,
"compliantEmployeeCount": X,
"nonCompliantEmployeeCount": X
}
// till.. current-month + 11
]
We have it in the SQL query we did earlier for our MySQL DB. But that query is pretty much crazy nesting of sub-queries.
Can someone help me here with the cypher query and explain the parts so that I can understand it and explain further to my team? Or if you have some tutorials/videos for reference that would be really helpful.
Thank you,
Hiren