I am working on an system and am trying to utilize ddd with node.js. Here is the an example for the system, from a high-level:
database tables(mongoldb):
user
username: String
firstName: String
middleName: String
lastName: String
department
title: String
members: [{
user: {type: this.mongoose.Schema.ObjectId, ref: 'user’},
permissions: String
}]
patient
user: {type: this.mongoose.Schema.ObjectId, ref: 'user’},
department: [{type: this.mongoose.Schema.ObjectId, ref: ‘department’}]
lab: [{
patient: {type: this.mongoose.Schema.ObjectId, ref: ‘patient’}
doctor: {type: this.mongoose.Schema.ObjectId, ref: 'user’},
type: String,
results: {there is a lot going on here, }
}]
medication: [{
patient: {type: this.mongoose.Schema.ObjectId, ref: ‘patient’}
doctor: {type: this.mongoose.Schema.ObjectId, ref: 'user’},
name: String,
dosage: Number,
etc.
}]
The business logic states that only the patient or a doctor that is a member of one of the departments in the patients, department list can review his medical information. I initially thought it should be in a separate domain Service as it appears to span entities, but the downside is that would require other services to call a permission service and I thought services should not call other services. If I placed in the lab and medication entities then I am duplication code and violating dry. If I add to the departments domain Service then I am making a service call another service. From a ddd perspective, where does logic like this belong?