diff --git a/back001/common/src/main/kotlin/com/mosenioring/common/outbox/OutboxService.kt b/back001/common/src/main/kotlin/com/mosenioring/common/outbox/OutboxService.kt index 140a726..ff1efeb 100644 --- a/back001/common/src/main/kotlin/com/mosenioring/common/outbox/OutboxService.kt +++ b/back001/common/src/main/kotlin/com/mosenioring/common/outbox/OutboxService.kt @@ -1,8 +1,6 @@ package com.mosenioring.common.outbox import com.fasterxml.jackson.databind.ObjectMapper -import com.mosenioring.common.security.SecurityUtils -import com.mosenioring.common.tenant.TenantContext import org.springframework.context.annotation.Profile import org.springframework.stereotype.Service import java.util.UUID @@ -14,15 +12,11 @@ class OutboxService( private val objectMapper: ObjectMapper ) { fun enqueue(eventType: String, payload: Any): OutboxEvent { - val tenantId = TenantContext.getTenantId() ?: "unknown" val event = OutboxEvent( id = UUID.randomUUID().toString(), eventType = eventType, payload = objectMapper.writeValueAsString(payload) ) - event.tenantId = tenantId - event.createdBy = SecurityUtils.currentUserId() - event.updatedBy = SecurityUtils.currentUserId() return repository.save(event) } } diff --git a/back001/modules/clinical/src/main/kotlin/com/mosenioring/clinical/service/ClinicalServices.kt b/back001/modules/clinical/src/main/kotlin/com/mosenioring/clinical/service/ClinicalServices.kt index b405c14..b3785fc 100644 --- a/back001/modules/clinical/src/main/kotlin/com/mosenioring/clinical/service/ClinicalServices.kt +++ b/back001/modules/clinical/src/main/kotlin/com/mosenioring/clinical/service/ClinicalServices.kt @@ -8,7 +8,6 @@ import com.mosenioring.clinical.repo.TestOrderRepository import com.mosenioring.common.Events import com.mosenioring.common.outbox.OutboxService import com.mosenioring.common.security.PatientAccess -import com.mosenioring.common.security.SecurityUtils import com.mosenioring.common.tenant.TenantContext import org.springframework.security.access.prepost.PreAuthorize import org.springframework.stereotype.Service @@ -26,9 +25,6 @@ class MedicationPlanService( fun createMedicationPlan(patientId: String, description: String): MedicationPlan { val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") val plan = MedicationPlan(UUID.randomUUID().toString(), patientId, description) - plan.tenantId = tenantId - plan.createdBy = SecurityUtils.currentUserId() - plan.updatedBy = SecurityUtils.currentUserId() val saved = repository.save(plan) outboxService.enqueue( Events.MEDICATION_PLAN_CREATED, @@ -52,11 +48,8 @@ class TestOrderService( @Transactional @PatientAccess fun createTestOrder(patientId: String, testName: String): TestOrder { - val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") + requireNotNull(TenantContext.getTenantId()) { "Missing tenant" } val order = TestOrder(UUID.randomUUID().toString(), patientId, testName, "ORDERED") - order.tenantId = tenantId - order.createdBy = SecurityUtils.currentUserId() - order.updatedBy = SecurityUtils.currentUserId() val saved = repository.save(order) auditService.record("TEST_ORDER_CREATED", "test", saved.id, patientId) return saved diff --git a/back001/modules/identity/src/main/kotlin/com/mosenioring/identity/service/IdentityServices.kt b/back001/modules/identity/src/main/kotlin/com/mosenioring/identity/service/IdentityServices.kt index b970eac..6a60b79 100644 --- a/back001/modules/identity/src/main/kotlin/com/mosenioring/identity/service/IdentityServices.kt +++ b/back001/modules/identity/src/main/kotlin/com/mosenioring/identity/service/IdentityServices.kt @@ -1,7 +1,6 @@ package com.mosenioring.identity.service import com.mosenioring.audit.service.AuditService -import com.mosenioring.common.security.SecurityUtils import com.mosenioring.common.tenant.TenantContext import com.mosenioring.identity.* import com.mosenioring.identity.repo.* @@ -20,8 +19,6 @@ class TenantService( fun createTenant(name: String): Tenant { val tenant = Tenant(UUID.randomUUID().toString(), name) tenant.tenantId = tenant.id - tenant.createdBy = SecurityUtils.currentUserId() - tenant.updatedBy = SecurityUtils.currentUserId() val saved = tenantRepository.save(tenant) auditService.record("TENANT_CREATED", "tenant", saved.id, null) return saved @@ -36,11 +33,8 @@ class UserService( @Transactional @PreAuthorize("hasRole('ADMIN')") fun inviteUser(email: String, role: String): User { - val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") + requireNotNull(TenantContext.getTenantId()) { "Missing tenant" } val user = User(UUID.randomUUID().toString(), email, role, "INVITED") - user.tenantId = tenantId - user.createdBy = SecurityUtils.currentUserId() - user.updatedBy = SecurityUtils.currentUserId() val saved = userRepository.save(user) auditService.record("USER_INVITED", "user", saved.id, null) return saved @@ -57,11 +51,8 @@ class PatientService( @Transactional @PreAuthorize("hasAnyRole('ADMIN','DOCTOR','CAREGIVER')") fun createPatient(fullName: String): Patient { - val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") + requireNotNull(TenantContext.getTenantId()) { "Missing tenant" } val patient = Patient(UUID.randomUUID().toString(), fullName) - patient.tenantId = tenantId - patient.createdBy = SecurityUtils.currentUserId() - patient.updatedBy = SecurityUtils.currentUserId() val saved = patientRepository.save(patient) auditService.record("PATIENT_CREATED", "patient", saved.id, saved.id) return saved @@ -73,9 +64,6 @@ class PatientService( val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") patientRepository.findByIdAndTenantId(patientId, tenantId) ?: throw IllegalArgumentException("Patient not found") val link = PatientCaregiver(UUID.randomUUID().toString(), patientId, userId) - link.tenantId = tenantId - link.createdBy = SecurityUtils.currentUserId() - link.updatedBy = SecurityUtils.currentUserId() val saved = caregiverRepository.save(link) auditService.record("CARE_GIVER_LINKED", "patient_caregiver", saved.id, patientId) return saved @@ -87,9 +75,6 @@ class PatientService( val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") patientRepository.findByIdAndTenantId(patientId, tenantId) ?: throw IllegalArgumentException("Patient not found") val link = PatientDoctor(UUID.randomUUID().toString(), patientId, userId) - link.tenantId = tenantId - link.createdBy = SecurityUtils.currentUserId() - link.updatedBy = SecurityUtils.currentUserId() val saved = doctorRepository.save(link) auditService.record("DOCTOR_LINKED", "patient_doctor", saved.id, patientId) return saved diff --git a/back001/modules/integrations/src/main/kotlin/com/mosenioring/integrations/service/FileService.kt b/back001/modules/integrations/src/main/kotlin/com/mosenioring/integrations/service/FileService.kt index 04f2b19..748e525 100644 --- a/back001/modules/integrations/src/main/kotlin/com/mosenioring/integrations/service/FileService.kt +++ b/back001/modules/integrations/src/main/kotlin/com/mosenioring/integrations/service/FileService.kt @@ -43,9 +43,6 @@ class FileService( val fileId = UUID.randomUUID().toString() val storageKey = "$tenantId/$fileId/$fileName" val metadata = FileMetadata(fileId, patientId, fileName, contentType, storageKey) - metadata.tenantId = tenantId - metadata.createdBy = SecurityUtils.currentUserId() - metadata.updatedBy = SecurityUtils.currentUserId() repository.save(metadata) val request = PutObjectRequest.builder() diff --git a/back001/modules/messaging/src/main/kotlin/com/mosenioring/messaging/service/MessageService.kt b/back001/modules/messaging/src/main/kotlin/com/mosenioring/messaging/service/MessageService.kt index 92bdb12..2dbddf4 100644 --- a/back001/modules/messaging/src/main/kotlin/com/mosenioring/messaging/service/MessageService.kt +++ b/back001/modules/messaging/src/main/kotlin/com/mosenioring/messaging/service/MessageService.kt @@ -18,12 +18,9 @@ class MessageService( @Transactional @PatientAccess fun addMessage(patientId: String, body: String): Message { - val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") + requireNotNull(TenantContext.getTenantId()) { "Missing tenant" } val senderId = SecurityUtils.currentUserId() ?: throw IllegalStateException("Missing user") val message = Message(UUID.randomUUID().toString(), patientId, senderId, body) - message.tenantId = tenantId - message.createdBy = senderId - message.updatedBy = senderId val saved = repository.save(message) auditService.record("MESSAGE_ADDED", "message", saved.id, patientId) return saved