private bool MapProperties(LabSpecimenDto dto, LabSpecimen entity) { var labSpecimenType = _mappingHelper.MapLookupField <LabSpecimenType> (dto.LabSpecimenType); entity.ReviseLabSpecimenType(labSpecimenType); entity.ReviseLabReceivedDate(dto.LabReceivedDate); entity.ReviseCollectedHereIndicator(dto.CollectedHereIndicator); // TODO: This needs to be rethought when the domain for Lab is redone. var labTest = entity.LabTests.FirstOrDefault(lt => lt.LabTestInfo.LabTestName.WellKnownName == dto.LabTestName.WellKnownName); if (labTest == null && entity.LabTests.Count > 0) { //right now there is only every one lab test per lab specimen? entity.RemoveLabTest(entity.LabTests.ElementAt(0)); } var labTestInfo = new LabTestInfoBuilder() .WithLabTestName(_mappingHelper.MapLookupField <LabTestName> (dto.LabTestName)) .WithTestReportDate(dto.LabTestDate) .WithLabTestNote(dto.LabTestNote); if (labTest == null) { labTest = entity.AddLabTest(labTestInfo); } else { labTest.ReviseLabTestInfo(labTestInfo); } var result = new AggregateNodeCollectionMapper <LabResultDto, LabTest, LabResult> (dto.LabResults, labTest, labTest.LabResults) .MapAddedItem( (lrdto, lt) => { CodedConcept labTestResultNameCodedConcept = null; if (lrdto.LabTestResultNameCodedConcept != null) { labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept); } lt.AddLabResult( new LabResultBuilder() .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept) .WithValue(lrdto.Value) .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode)); } ) .MapChangedItem( (lrdto, lt, lr) => { lt.RemoveLabResult(lr); CodedConcept labTestResultNameCodedConcept = null; if (lrdto.LabTestResultNameCodedConcept != null) { labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept); } lt.AddLabResult( new LabResultBuilder() .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept) .WithValue(lrdto.Value) .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode)); }) .MapRemovedItem((lrdto, lt, lr) => lt.RemoveLabResult(lr)) .Map(); return(result); }
private void CreateLabSpecimen(LabSpecimenDto dto, long patientKey, Provenance provenance) { if (dto == null || dto.LabResults == null || dto.LabResults.Count == 0) { return; } var clinicalCase = _clinicalCaseRepository.GetActiveClinicalCaseByPatient(patientKey); var labSpecimen = _labSpecimenFactory.CreateLabSpecimen( clinicalCase, provenance, new DateTimeRange(dto.ActivityStartDateTime, dto.ActivityStartDateTime)); var labSpecimenType = _mappingHelper.MapLookupField <LabSpecimenType> (dto.LabSpecimenType); labSpecimen.ReviseLabSpecimenType(labSpecimenType); labSpecimen.ReviseLabReceivedDate(dto.LabReceivedDate); labSpecimen.ReviseCollectedHereIndicator(dto.CollectedHereIndicator); // TODO: This needs to be rethought when the domain for Lab is redone. var labTest = labSpecimen.LabTests.FirstOrDefault(lt => lt.LabTestInfo.LabTestName.WellKnownName == dto.LabTestName.WellKnownName); if (labTest == null && labSpecimen.LabTests.Count > 0) { //right now there is only every one lab test per lab specimen? labSpecimen.RemoveLabTest(labSpecimen.LabTests.ElementAt(0)); } var labTestInfo = new LabTestInfoBuilder() .WithLabTestName(_mappingHelper.MapLookupField <LabTestName> (dto.LabTestName)) .WithTestReportDate(dto.LabTestDate) .WithLabTestNote(dto.LabTestNote); if (labTest == null) { labTest = labSpecimen.AddLabTest(labTestInfo); } else { labTest.ReviseLabTestInfo(labTestInfo); } var result = new AggregateNodeCollectionMapper <LabResultDto, LabTest, LabResult> (dto.LabResults, labTest, labTest.LabResults) .MapAddedItem( (lrdto, lt) => { CodedConcept labTestResultNameCodedConcept = null; if (lrdto.LabTestResultNameCodedConcept != null) { labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept); } lt.AddLabResult( new LabResultBuilder() .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept) .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode) .WithValue(lrdto.Value)); } ) .MapChangedItem( (lrdto, lt, lr) => { lt.RemoveLabResult(lr); CodedConcept labTestResultNameCodedConcept = null; if (lrdto.LabTestResultNameCodedConcept != null) { labTestResultNameCodedConcept = new CodedConceptBuilder().WithCodedConceptDto(lrdto.LabTestResultNameCodedConcept); } lt.AddLabResult( new LabResultBuilder() .WithLabTestResultNameCodedConcept(labTestResultNameCodedConcept) .WithValue(lrdto.Value) .WithUnitOfMeasureCode(lrdto.UnitOfMeasureCode)); }) .MapRemovedItem((lrdto, lt, lr) => lt.RemoveLabResult(lr)) .Map(); }