private Trifolia.DB.CodeSystem FindOrAddCodeSystem(IObjectRepository tdb, string codeSystemOid, string codeSystemName) { Trifolia.DB.CodeSystem foundCodeSystem = addedCodeSystems.SingleOrDefault(y => y.Oid == codeSystemOid); // If we haven't added the code system as part of this save, search the database for the code system if (foundCodeSystem == null) { foundCodeSystem = tdb.CodeSystems.FirstOrDefault(y => y.Oid == codeSystemOid); } // If no code system was found that we added recently, and it was not found in the database, create a new one if (foundCodeSystem == null) { foundCodeSystem = new CodeSystem() { Oid = codeSystemOid, Name = codeSystemName, LastUpdate = DateTime.Now }; tdb.CodeSystems.Add(foundCodeSystem); addedCodeSystems.Add(foundCodeSystem); } return(foundCodeSystem); }
private void SetProperties(CodeSystem codeSystem) { }
public ValueSet Convert(FhirValueSet fhirValueSet, ValueSet valueSet = null) { string fhirDescription = fhirValueSet.Description != null ? fhirValueSet.Description.Value : null; if (valueSet == null) { valueSet = new ValueSet(); } if (valueSet.Name != fhirValueSet.Name) { valueSet.Name = fhirValueSet.Name; } if (valueSet.Description != fhirDescription) { valueSet.Description = fhirDescription; } if (fhirValueSet.Identifier == null) { throw new Exception("ValueSet.identifier.value is required"); } this.PopulateIdentifier(valueSet, fhirValueSet); if (fhirValueSet.Expansion != null) { foreach (var expContains in fhirValueSet.Expansion.Contains) { // Skip members that don't have a code or a code system if (string.IsNullOrEmpty(expContains.Code) || string.IsNullOrEmpty(expContains.System)) { continue; } CodeSystem codeSystem = this.tdb.CodeSystems.SingleOrDefault(y => y.Oid == expContains.System); if (codeSystem == null) { codeSystem = new CodeSystem() { Oid = expContains.System, Name = expContains.System }; this.tdb.CodeSystems.Add(codeSystem); } ValueSetMember newMember = valueSet.Members.SingleOrDefault(y => y.CodeSystem == codeSystem && y.Code == expContains.Code); if (newMember == null) { newMember = new ValueSetMember() { CodeSystem = codeSystem, Code = expContains.Code } } ; if (newMember.DisplayName != expContains.Display) { newMember.DisplayName = expContains.Display; } DateTime versionDateVal = DateTime.MinValue; if (!DateTime.TryParse(fhirValueSet.Version, out versionDateVal)) { DateTime.TryParse(fhirValueSet.Date, out versionDateVal); } DateTime?versionDate = versionDateVal != DateTime.MinValue ? (DateTime?)versionDateVal : null; if (newMember.StatusDate != versionDate) { newMember.StatusDate = versionDate; } if (newMember.StatusDate != null && newMember.Status != "active") { newMember.Status = "active"; } valueSet.Members.Add(newMember); } } return(valueSet); } }