private static OperationVm EavToOperationVm(EavEntity entity) => new OperationVm { OperationId = entity.Id, OperationName = entity.AttributeValues.Single(av => av.AttributeType == AttributeType.OperationName) .Value, };
private static PatientVm EavToPatientVm(EavEntity entity) => new PatientVm { PatientId = entity.Id, Name = entity.AttributeValues.Single(av => av.AttributeType == AttributeType.PatientName).Value, Age = ushort.Parse( entity.AttributeValues.Single(av => av.AttributeType == AttributeType.PatientAge).Value ) };
public async Task AddOperationAsync(CreateOperationVm operationDto) { var entity = new EavEntity { Id = Guid.NewGuid(), EntityType = EntityType.Operation, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { AttributeType = AttributeType.PatientId, Value = operationDto.PatientId.ToString() }, new AttributeValueEntity { AttributeType = AttributeType.OperationName, Value = operationDto.OperationName } } }; _dbContext.Entities.Add(entity); await _dbContext.SaveChangesAsync(); }
public Task AddPatientAsync(CreatePatientVm patientDto) { var patient = new EavEntity { Id = Guid.NewGuid(), EntityType = EntityType.Patient, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { AttributeType = AttributeType.PatientName, Value = patientDto.Name }, new AttributeValueEntity { AttributeType = AttributeType.PatientAge, Value = patientDto.Age.ToString() }, } }; _dbContext.Entities.Add(patient); return(_dbContext.SaveChangesAsync()); }
public async Task CanGetPatient() { //Arrange var dbContext = GetDbContext(nameof(CanAddPatient)); var patientId = Guid.NewGuid(); const string patientName = "Jon Snow"; const string patientAge = "24"; var patientEntity = new EavEntity { Id = patientId, EntityType = EntityType.Patient, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientName, Value = patientName }, new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientAge, Value = patientAge } } }; var operationId = Guid.NewGuid(); const string operationName = "Lymphadenectomy"; var operationEntity = new EavEntity { Id = operationId, EntityType = EntityType.Operation, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.OperationName, Value = operationName }, new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientId, Value = patientId.ToString() } } }; dbContext.Entities.AddRange(patientEntity, operationEntity); await dbContext.SaveChangesAsync(); var sut = new ClinicService(dbContext); //Action var patient = await sut.GetPatientAsync(patientId, default); //Assert patient.Should().NotBeNull(); patient.Name.Should().Be(patientName); patient.Age.Should().Be(ushort.Parse(patientAge)); patient.Operations.Should().NotBeNullOrEmpty(); var operation = patient.Operations.Single(); operation.Should().NotBeNull(); operation.OperationId.Should().Be(operationId); operation.OperationName.Should().Be(operationName); }
public async Task CanGetAllPatients() { //Arrange var dbContext = GetDbContext(nameof(CanAddPatient)); var patientId = Guid.NewGuid(); const string patientName = "Jon Snow"; const string patientAge = "24"; var patientEntities = new[] { new EavEntity { Id = patientId, EntityType = EntityType.Patient, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientName, Value = patientName }, new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientAge, Value = patientAge } } }, new EavEntity { Id = Guid.NewGuid(), EntityType = EntityType.Patient, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientName, Value = "123123" }, new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientAge, Value = "12" } } } }; var operationId = Guid.NewGuid(); const string operationName = "Lymphadenectomy"; var operationEntity = new EavEntity { Id = operationId, EntityType = EntityType.Operation, AttributeValues = new List <AttributeValueEntity> { new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.OperationName, Value = operationName }, new AttributeValueEntity { Id = Guid.NewGuid(), AttributeType = AttributeType.PatientId, Value = patientId.ToString() } } }; dbContext.Entities.AddRange(patientEntities); dbContext.Entities.Add(operationEntity); await dbContext.SaveChangesAsync(); var sut = new ClinicService(dbContext); //Action var patients = await sut.GetAllPatientsAsync(default);