public XElement generate(ValueSet vs) { var result = new XElement(XmlNs.XHTMLNS + "div"); if (vs.Expansion != null) { if (vs.Define == null && vs.Compose == null) { throw new NotImplementedException("Expansion HTML generation not yet supported"); //generateExpansion(x, vs); } else throw new Exception("Error: should not encounter value set expansion at this point"); } bool hasExtensions = false; if (vs.Define != null) hasExtensions = generateDefinition(result, vs); if (vs.Compose != null) hasExtensions = generateComposition(result, vs) || hasExtensions; //inject(vs, result, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED); return result; }
public ValueSet HarvestValueSet(Hl7.Fhir.Model.ValueSet source) { ValueSet valueset = new ValueSet(); // todo: This now only works with "defines". if (source.Define != null) { foreach (var concept in source.Define.Concept) { valueset.codes.Add(concept.Code); } } return(valueset); }
private bool generateDefinition(XElement x, ValueSet vs) { bool hasExtensions = false; var mymaps = new Dictionary<ConceptMap, String>(); //TODO: Add ConceptMap infrastructure //for (AtomEntry<ConceptMap> a : context.getMaps().values()) //{ // if (((Reference) a.getResource().getSource()).getReference().equals(vs.getIdentifier())) // { // String url = ""; // if (context.getValueSets().containsKey(((Reference) a.getResource().getTarget()).getReference())) // url = context.getValueSets().get(((Reference) a.getResource().getTarget()).getReference()).getLinks().get("path"); // mymaps.put(a.getResource(), url); // } //} var langs = new List<String>(); x.Add(new XElement(XmlNs.XHTMLNS + "h2"), new XText("Value Set for codes in " + vs.Name)); var p = new XElement(XmlNs.XHTMLNS + "p"); smartAddText(p, vs.Description); x.Add(p); if (vs.Copyright != null) generateCopyright(x, vs); x.Add(new XElement(XmlNs.XHTMLNS + "p", "This value set defines its own terms in the system " + vs.Define.System)); var t = new XElement(XmlNs.XHTMLNS + "table", new XAttribute("class", "codes")); x.Add(t); bool commentS = false; bool deprecated = false; if (vs.Define.Concept != null) { // foreach (var c in vs.Define.Concept) // { // commentS = commentS || conceptsHaveComments(c); // deprecated = deprecated || conceptsHaveDeprecated(c); // scanLangs(c, langs); // } //addMapHeaders(addTableHeaderRowStandard(t, commentS, deprecated), mymaps); replaced by next line: addTableHeaderRowStandard(t, commentS, deprecated); foreach (var c in vs.Define.Concept) hasExtensions = addDefineRowToTable(t, c, 0, commentS, deprecated, mymaps) || hasExtensions; } //TODO: Add language infrastructure //if (langs.size() > 0) //{ // Collections.sort(langs); // x.addTag("p").addTag("b").addText("Additional Language Displays"); // t = x.addTag("table").setAttribute("class", "codes"); // XhtmlNode tr = t.addTag("tr"); // tr.addTag("td").addTag("b").addText("Code"); // for (String lang : langs) // tr.addTag("td").addTag("b").addText(lang); // for (ConceptDefinitionComponent c : vs.getDefine().getConcept()) // { // addLanguageRow(c, t, langs); // } //} return hasExtensions; }
private String describe(ValueSet.FilterOperator opSimple) { switch (opSimple) { case ValueSet.FilterOperator.Equal: return " = "; case ValueSet.FilterOperator.IsA: return " is-a "; case ValueSet.FilterOperator.IsNotA: return " is-not-a "; case ValueSet.FilterOperator.Regex: return " matches (by regex) "; case ValueSet.FilterOperator.In: return " in "; case ValueSet.FilterOperator.NotIn: return " not in "; } return null; }
private void generateCopyright(XElement x, ValueSet vs) { var p = new XElement(XmlNs.XHTMLNS + "p", new XElement(XmlNs.XHTMLNS + "b", new XText("Copyright Statement:"))); smartAddText(p, " " + vs.Copyright); x.Add(p); }
private bool inConcept(String code, ValueSet.ValueSetDefineConceptComponent c) { if (c.Code == code) return true; foreach (var g in c.Concept) { if (inConcept(code, g)) return true; } return false; }
private bool codeExistsInValueSet(ValueSet vs, String code) { if (vs.Define == null || vs.Define.Concept == null) return false; foreach (var c in vs.Define.Concept) { if (inConcept(code, c)) return true; } return false; }
/// <summary> /// Parse ValueSet /// </summary> public static Hl7.Fhir.Model.ValueSet ParseValueSet(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.ValueSet existingInstance = null) { Hl7.Fhir.Model.ValueSet result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.ValueSet(); string currentElementName = reader.CurrentElementName; reader.EnterElement(); while (reader.HasMoreElements()) { var atName = reader.CurrentElementName; // Parse element extension if (atName == "extension") { result.Extension = new List <Hl7.Fhir.Model.Extension>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "extension")) { result.Extension.Add(ExtensionParser.ParseExtension(reader, errors)); } reader.LeaveArray(); } // Parse element language else if (atName == "language") { result.LanguageElement = CodeParser.ParseCode(reader, errors); } // Parse element text else if (atName == "text") { result.Text = NarrativeParser.ParseNarrative(reader, errors); } // Parse element contained else if (atName == "contained") { result.Contained = new List <Hl7.Fhir.Model.Resource>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "contained")) { result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors)); } reader.LeaveArray(); } // Parse element _id else if (atName == "_id") { result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id))); } // Parse element identifier else if (atName == "identifier") { result.IdentifierElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element version else if (atName == "version") { result.VersionElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element name else if (atName == "name") { result.NameElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element publisher else if (atName == "publisher") { result.PublisherElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element telecom else if (atName == "telecom") { result.Telecom = new List <Hl7.Fhir.Model.Contact>(); reader.EnterArray(); while (ParserUtils.IsAtArrayElement(reader, "telecom")) { result.Telecom.Add(ContactParser.ParseContact(reader, errors)); } reader.LeaveArray(); } // Parse element description else if (atName == "description") { result.DescriptionElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element copyright else if (atName == "copyright") { result.CopyrightElement = FhirStringParser.ParseFhirString(reader, errors); } // Parse element status else if (atName == "status") { result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.ValueSet.ValueSetStatus>(reader, errors); } // Parse element experimental else if (atName == "experimental") { result.ExperimentalElement = FhirBooleanParser.ParseFhirBoolean(reader, errors); } // Parse element date else if (atName == "date") { result.DateElement = FhirDateTimeParser.ParseFhirDateTime(reader, errors); } // Parse element define else if (atName == "define") { result.Define = ValueSetParser.ParseValueSetDefineComponent(reader, errors); } // Parse element compose else if (atName == "compose") { result.Compose = ValueSetParser.ParseValueSetComposeComponent(reader, errors); } // Parse element expansion else if (atName == "expansion") { result.Expansion = ValueSetParser.ParseValueSetExpansionComponent(reader, errors); } else { errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader); reader.SkipSubElementsFor(currentElementName); result = null; } } reader.LeaveElement(); return(result); }
private ValueSet.ValueSetDefineConceptComponent getConceptForCode(ValueSet vs, String code, String system) { if (vs == null) { //TODO: include additional terminology services //if (context.getTerminologyServices() != null) // return context.getTerminologyServices().getCodeDefinition(system, code); //else return null; } if (vs.Define == null) return null; foreach (var c in vs.Define.Concept) { var v = getConceptForCode(c, code); if (v != null) return v; } return null; }
private void addCsRef(ValueSet.ConceptSetComponent inc, XElement li, ValueSet cs) { String reference = null; if (cs != null) { reference = inc.System; } if (cs != null && reference != null) { if (!String.IsNullOrEmpty(prefix) && reference.StartsWith("http://hl7.org/fhir/")) reference = reference.Substring(20)+"/index.html"; XElement a =new XElement(XmlNs.XHTMLNS+"a"); li.Add(a); a.Add(new XAttribute("href", prefix+reference.Replace("\\", "/"))); a.Add(new XText(inc.System)); } else li.Add(new XText(inc.System)); }
private bool genInclude(XElement ul, ValueSet.ConceptSetComponent inc, String type) { bool hasExtensions = false; var li = new XElement(XmlNs.XHTMLNS + "li"); ul.Add(li); var e = _pkp.GetValueSetForSystem(inc.System); // AtomEntry<? extends Resource> e = context.getCodeSystems().get(inc.getSystem()); if ( (inc.Code == null || !inc.Code.Any()) && (inc.Filter == null || !inc.Filter.Any())) { li.Add(new XText(type+" all codes defined in ")); addCsRef(inc, li, e); } else { if (inc.CodeElement != null && inc.CodeElement.Any()) { li.Add(new XText(type+" these codes as defined in ")); addCsRef(inc, li, e); var t = new XElement(XmlNs.XHTMLNS+"table"); li.Add(t); bool hasComments = false; foreach (var c in inc.CodeElement) { hasComments = hasComments || c.GetExtension(ToolingExtensions.EXT_COMMENT) != null; } if (hasComments) hasExtensions = true; addTableHeaderRowStandard(t, hasComments, false); foreach(var c in inc.CodeElement) { var tr = new XElement(XmlNs.XHTMLNS + "tr"); t.Add(tr); tr.Add(new XElement(XmlNs.XHTMLNS+"td", new XText(c.Value))); ValueSet.ValueSetDefineConceptComponent cc = getConceptForCode(e, c.Value, inc.System); XElement td = new XElement(XmlNs.XHTMLNS+"td"); tr.Add(td); if (cc != null && !String.IsNullOrEmpty(cc.Display)) td.Add(new XText(cc.Display)); //if (!Utilities.noString(c.getDisplay())) DSTU2 // td.addText(c.getDisplay()); //else if (cc != null && !Utilities.noString(cc.getDisplay())) // td.addText(cc.getDisplay()); td = new XElement(XmlNs.XHTMLNS+"td"); tr.Add(td); if (c.GetExtension(ToolingExtensions.EXT_DEFINITION) != null) smartAddText(td, ToolingExtensions.ReadStringExtension(c, ToolingExtensions.EXT_DEFINITION)); else if (cc != null && !String.IsNullOrEmpty(cc.Definition)) smartAddText(td, cc.Definition); else ; // No else in the java code!! if (c.GetExtension(ToolingExtensions.EXT_COMMENT) != null) { var tdn = new XElement(XmlNs.XHTMLNS+"td"); tr.Add(td); smartAddText(tdn, "Note: "+ ToolingExtensions.ReadStringExtension(c, ToolingExtensions.EXT_COMMENT)); } } } if (inc.Filter != null) { foreach (var f in inc.Filter) { li.Add(new XText(type + " codes from ")); addCsRef(inc, li, e); // TODO: Java code does not allow for f.Op to be null, but it is optional li.Add(new XText(" where " + f.Property + " " + describe(f.Op.GetValueOrDefault()) + " ")); if (e != null && codeExistsInValueSet(e, f.Value)) { li.Add(new XElement(XmlNs.XHTMLNS + "a", new XText(f.Value), new XAttribute("href", prefix + getCsRef(inc.System) + "#" + ProfileKnowledgeProvider.TokenizeName(f.Value)))); } else li.Add(new XText(f.Value)); String disp = f.getDisplayHint(); if (disp != null) li.Add(new XText(" (" + disp + ")")); } } } return hasExtensions; }
private bool generateComposition(XElement x, ValueSet vs) { bool hasExtensions = false; if (vs.Define == null) { var h = new XElement(XmlNs.XHTMLNS + "h2", new XText("Value Set for codes in " + vs.Name)); var p = new XElement(XmlNs.XHTMLNS + "p"); smartAddText(p, vs.Description); x.Add(h, p); if (vs.Copyright != null) generateCopyright(x, vs); x.Add(new XElement(XmlNs.XHTMLNS + "p", "This value set includes codes defined in other code systems, using the following rules:")); } else { x.Add(new XElement(XmlNs.XHTMLNS + "p", "In addition, this value set includes codes defined in other code systems, using the following rules:")); } var ul = new XElement(XmlNs.XHTMLNS + "ul"); x.Add(ul); XElement li; if (vs.Compose.Import != null) { foreach (var imp in vs.Compose.Import) { li = new XElement(XmlNs.XHTMLNS + "li"); ul.Add(li); li.Add(new XText("Import all the codes that are part of ")); AddVsRef(imp, li); } } if (vs.Compose.Include != null) { foreach (var inc in vs.Compose.Include) hasExtensions = genInclude(ul, inc, "Include") || hasExtensions; } if (vs.Compose.Exclude != null) { foreach (var exc in vs.Compose.Exclude) hasExtensions = genInclude(ul, exc, "Exclude") || hasExtensions; } return hasExtensions; }
private bool addDefineRowToTable(XElement t, ValueSet.ValueSetDefineConceptComponent c, int i, bool comment, bool deprecated, Dictionary<ConceptMap, String> maps) { bool hasExtensions = false; XElement tr = new XElement(XmlNs.XHTMLNS + "tr"); t.Add(tr); XElement td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); var indent = new String('.', i * 2); td.Add(new XText(indent + c.Code)); td.Add(new XElement(XmlNs.XHTMLNS + "a", new XAttribute("name", ProfileKnowledgeProvider.TokenizeName(c.Code)), new XText(" "))); td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); if (c.Display != null) td.Add(new XText(c.Display)); td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); if (c.Definition != null) smartAddText(td, c.Definition); if (deprecated) { td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); var s = c.GetDeprecated(); if (s != null) { smartAddText(td, s); hasExtensions = true; } } if (comment) { td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); var s = c.GetComment(); if (s != null) { smartAddText(td, s); hasExtensions = true; } } //for (ConceptMap m : maps.keySet()) //{ // td = tr.addTag("td"); // List<ConceptMapElementMapComponent> mappings = findMappingsForCode(c.getCode(), m); // boolean first = true; // for (ConceptMapElementMapComponent mapping : mappings) // { // if (!first) // td.addTag("br"); // first = false; // XhtmlNode span = td.addTag("span"); // span.setAttribute("title", mapping.getEquivalence().toString()); // span.addText(getCharForEquivalence(mapping)); // a = td.addTag("a"); // a.setAttribute("href", prefix+maps.get(m)+"#"+mapping.getCode()); // a.addText(mapping.getCode()); // if (!Utilities.noString(mapping.getComments())) // td.addTag("i").addText("("+mapping.getComments()+")"); // } //} foreach (var e in c.GetSubsumes()) { hasExtensions = true; tr = new XElement(XmlNs.XHTMLNS + "tr"); t.Add(tr); td = new XElement(XmlNs.XHTMLNS + "td"); tr.Add(td); indent = new String('.', i * 2); td.Add(new XText(indent)); var a = new XElement(XmlNs.XHTMLNS + "a"); a.Add(new XAttribute("href", "#" + ProfileKnowledgeProvider.TokenizeName(e.Value))); a.Add(new XText(c.Code)); td.Add(a); } foreach (var cc in c.Concept) { hasExtensions = addDefineRowToTable(t, cc, i + 1, comment, deprecated, maps) || hasExtensions; } return hasExtensions; }
public static void SerializeValueSet(Hl7.Fhir.Model.ValueSet value, IFhirWriter writer, bool summary) { writer.WriteStartRootObject("ValueSet"); writer.WriteStartComplexContent(); // Serialize element _id if (value.LocalIdElement != null) { writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute); } // Serialize element extension if (value.Extension != null && !summary && value.Extension.Count > 0) { writer.WriteStartArrayElement("extension"); foreach (var item in value.Extension) { writer.WriteStartArrayMember("extension"); ExtensionSerializer.SerializeExtension(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element language if (value.LanguageElement != null && !summary) { writer.WriteStartElement("language"); CodeSerializer.SerializeCode(value.LanguageElement, writer, summary); writer.WriteEndElement(); } // Serialize element text if (value.Text != null && !summary) { writer.WriteStartElement("text"); NarrativeSerializer.SerializeNarrative(value.Text, writer, summary); writer.WriteEndElement(); } // Serialize element contained if (value.Contained != null && !summary && value.Contained.Count > 0) { writer.WriteStartArrayElement("contained"); foreach (var item in value.Contained) { writer.WriteStartArrayMember("contained"); FhirSerializer.SerializeResource(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element identifier if (value.IdentifierElement != null) { writer.WriteStartElement("identifier"); FhirStringSerializer.SerializeFhirString(value.IdentifierElement, writer, summary); writer.WriteEndElement(); } // Serialize element version if (value.VersionElement != null) { writer.WriteStartElement("version"); FhirStringSerializer.SerializeFhirString(value.VersionElement, writer, summary); writer.WriteEndElement(); } // Serialize element name if (value.NameElement != null) { writer.WriteStartElement("name"); FhirStringSerializer.SerializeFhirString(value.NameElement, writer, summary); writer.WriteEndElement(); } // Serialize element publisher if (value.PublisherElement != null) { writer.WriteStartElement("publisher"); FhirStringSerializer.SerializeFhirString(value.PublisherElement, writer, summary); writer.WriteEndElement(); } // Serialize element telecom if (value.Telecom != null && value.Telecom.Count > 0) { writer.WriteStartArrayElement("telecom"); foreach (var item in value.Telecom) { writer.WriteStartArrayMember("telecom"); ContactSerializer.SerializeContact(item, writer, summary); writer.WriteEndArrayMember(); } writer.WriteEndArrayElement(); } // Serialize element description if (value.DescriptionElement != null) { writer.WriteStartElement("description"); FhirStringSerializer.SerializeFhirString(value.DescriptionElement, writer, summary); writer.WriteEndElement(); } // Serialize element copyright if (value.CopyrightElement != null && !summary) { writer.WriteStartElement("copyright"); FhirStringSerializer.SerializeFhirString(value.CopyrightElement, writer, summary); writer.WriteEndElement(); } // Serialize element status if (value.StatusElement != null) { writer.WriteStartElement("status"); CodeSerializer.SerializeCode <Hl7.Fhir.Model.ValueSet.ValueSetStatus>(value.StatusElement, writer, summary); writer.WriteEndElement(); } // Serialize element experimental if (value.ExperimentalElement != null) { writer.WriteStartElement("experimental"); FhirBooleanSerializer.SerializeFhirBoolean(value.ExperimentalElement, writer, summary); writer.WriteEndElement(); } // Serialize element date if (value.DateElement != null) { writer.WriteStartElement("date"); FhirDateTimeSerializer.SerializeFhirDateTime(value.DateElement, writer, summary); writer.WriteEndElement(); } // Serialize element define if (value.Define != null && !summary) { writer.WriteStartElement("define"); ValueSetSerializer.SerializeValueSetDefineComponent(value.Define, writer, summary); writer.WriteEndElement(); } // Serialize element compose if (value.Compose != null && !summary) { writer.WriteStartElement("compose"); ValueSetSerializer.SerializeValueSetComposeComponent(value.Compose, writer, summary); writer.WriteEndElement(); } // Serialize element expansion if (value.Expansion != null && !summary) { writer.WriteStartElement("expansion"); ValueSetSerializer.SerializeValueSetExpansionComponent(value.Expansion, writer, summary); writer.WriteEndElement(); } writer.WriteEndComplexContent(); writer.WriteEndRootObject(); }
private ValueSet.ValueSetDefineConceptComponent getConceptForCode(ValueSet.ValueSetDefineConceptComponent c, String code) { if (code == c.Code) return c; if (c.Concept == null) return null; foreach (var cc in c.Concept) { var v = getConceptForCode(cc, code); if (v != null) return v; } return null; }
private ValueSet BuildValueSet(Entities.ValueSetVersion valueSetVersionFromRepo, Entities.ValueSet valueSetFromRepo, bool includeConcepts = true) { var valueSet = new Hl7.Fhir.Model.ValueSet(); valueSet.Url = Url.Link( nameof(GetVersionedValueSetById), new { type = "ValueSet", id = valueSetFromRepo.ValueSetCode, vid = valueSetVersionFromRepo.ValueSetVersionNumber.ToString() }); valueSet.Identifier = new List <Identifier>() { new Identifier() { Use = Identifier.IdentifierUse.Official, Value = valueSetVersionFromRepo.ValueSetVersionID.ToString(), System = "urn:ietf:rfc:3986" }, new Identifier() { Use = Identifier.IdentifierUse.Secondary, Value = valueSetVersionFromRepo.ValueSetOID }, new Identifier() { Use = Identifier.IdentifierUse.Secondary, Value = valueSetVersionFromRepo.ValueSetCode } }; valueSet.Name = valueSetFromRepo.ValueSetCode; valueSet.Title = valueSetFromRepo.ValueSetName; valueSet.Description = new Markdown(valueSetFromRepo.DefinitionText); valueSet.Publisher = "PHIN_VADS"; valueSet.DateElement = new FhirDateTime(valueSetVersionFromRepo.StatusDate); valueSet.Version = valueSetVersionFromRepo.ValueSetVersionNumber.ToString(); valueSet.VersionId = valueSetVersionFromRepo.ValueSetVersionID.ToString(); valueSet.Status = PublicationStatus.Active; if (includeConcepts) { valueSet.Expansion = new ValueSet.ExpansionComponent() { Identifier = Guid.NewGuid().ToString(), TimestampElement = new FhirDateTime(DateTimeOffset.Now), Contains = new List <ValueSet.ContainsComponent>() }; var paginationParameters = new ValueSetConceptPaginationParameters() { ValueSetVersionId = valueSetVersionFromRepo.ValueSetVersionID, ValueSetVersionNumber = valueSetVersionFromRepo.ValueSetVersionNumber.ToString(), PageSize = 1000 }; var valueSetConceptEntities = _valueSetConceptRepository.GetValueSetConcepts(paginationParameters); foreach (var conceptFromRepo in valueSetConceptEntities) { var component = new ValueSet.ContainsComponent() { Code = conceptFromRepo.ConceptCode, Display = conceptFromRepo.CDCPreferredDesignation, System = $"urn:oid:{conceptFromRepo.CodeSystemOID}", Extension = new List <Extension>() { new Extension() { Value = new FhirString(conceptFromRepo.HL70396Identifier) } } }; valueSet.Expansion.Contains.Add(component); } valueSet.Expansion.Total = valueSet.Expansion.Contains.Count; valueSet.Expansion.Offset = (paginationParameters.PageNumber - 1) * paginationParameters.PageSize; } return(valueSet); }
public IEnumerable<ConceptMap> GetConceptMapsForSource(ValueSet source) { return GetConceptMapsForSource(source.Url); }