public ARCHETYPE VisitArchetype(ARCHETYPE archetype) { ARCHETYPE result = new ARCHETYPE(); result.adl_version = archetype.adl_version; result.archetype_id = archetype.archetype_id; result.concept = archetype.concept; result.definition = VisitComplexObjectConstraint(archetype.definition); result.invariants = archetype.invariants; if (archetype.is_controlledSpecified) { result.is_controlled = archetype.is_controlled; result.is_controlledSpecified = true; } result.ontology = VisitOntology(archetype.ontology); result.original_language = archetype.original_language; result.parent_archetype_id = archetype.parent_archetype_id; result.revision_history = archetype.revision_history; result.translations = VisitTranslations(archetype.translations); result.uid = archetype.uid; return result; }
public Ontology(ARCHETYPE an_archetype) { _archetype = an_archetype; if (languageCode == null || !AvailableLanguages().Contains(languageCode)) languageCode = an_archetype.original_language.code_string; }
public static string ArchetypeDigest(ARCHETYPE archetype) { var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true, Indent = false }; //#if DEBUG // using (var writer = XmlWriter.Create(@".\CanonicalArchetype2.xml", new XmlWriterSettings { Indent = true })) // AmSerializer.Serialize(writer, archetype); //#endif byte[] data; using (MemoryStream stream = AmSerializer.Serialize(settings, archetype)) { #if XMLParser AmSerializer.ValidateArchetype(stream); #endif data = stream.ToArray(); } // Remove UTF-8 BOM int offset = 0; if (data.Length < 1) throw new ApplicationException("Canonical archetype model must have length greater than 0"); if (data[0] == 239) // UTF-8 BOM: EF BB BF (239 187 191) { offset = 3; if (data.Length <= offset) throw new ApplicationException("Canonical archetype model must have length greater than the BOM offset"); } if (data[offset] != 60) // XML root element (<) throw new ApplicationException("Unexpected start character of canonical archetype model"); MD5 md5 = new MD5CryptoServiceProvider(); SoapHexBinary hexEncoder = new SoapHexBinary(md5.ComputeHash(data, offset, data.Length - offset)); return hexEncoder.ToString(); }
protected virtual ARCHETYPE CloneArchetypeDetails(openehr.openehr.am.archetype.ARCHETYPE archetype) { ARCHETYPE result = new ARCHETYPE(); if (archetype.uid() != null) { HIER_OBJECT_ID uid = new HIER_OBJECT_ID(); uid.value = archetype.uid().value().ToString(); result.uid = uid; } if (archetype.archetype_id() != null) { ARCHETYPE_ID archetypeId = new ARCHETYPE_ID(); archetypeId.value = archetype.archetype_id().value().ToString(); result.archetype_id = archetypeId; } if (archetype.version() != null) result.adl_version = archetype.adl_version().ToString(); if (archetype.concept() != null) result.concept = archetype.concept().ToString(); result.original_language = CloneCodePhrase(archetype.original_language()); result.is_controlled = archetype.is_controlled(); if (archetype.parent_archetype_id() != null) { ARCHETYPE_ID parentId = new ARCHETYPE_ID(); parentId.value = archetype.parent_archetype_id().value().ToString(); result.parent_archetype_id = parentId; } result.description = CloneDescription(archetype.description()); result.ontology = CloneOntology(archetype.ontology()); // 0..1 revision_history REVISION_HISTORY (does not occur in NHS archetypes, do later) //if (archetype.revision_history() != null) // result.revision_history = CloneAuthoredResource(archetype.revision_history()); if (archetype.translations() != null && archetype.translations().count() >= 0) { TRANSLATION_DETAILS[] translations = new TRANSLATION_DETAILS[archetype.translations().count()]; archetype.translations().start(); for (int i = 1; i <= archetype.translations().count(); i++) { TRANSLATION_DETAILS translation = new TRANSLATION_DETAILS(); openehr.openehr.rm.common.resource.TRANSLATION_DETAILS td = archetype.translations().item_for_iteration() as openehr.openehr.rm.common.resource.TRANSLATION_DETAILS; if (td.accreditation() != null) translation.accreditation = td.accreditation().ToString(); translation.author = CloneHashTableAny(td.author()); translation.language = CloneCodePhrase(td.language()); translation.other_details = CloneHashTableAny(td.other_details()); translations[i - 1] = translation; archetype.translations().forth(); } result.translations = translations; } result.invariants = CloneAssertion(archetype.invariants()); return result; }
public static bool ValidateArchetype(ARCHETYPE archetype) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.UTF8; settings.OmitXmlDeclaration = true; settings.Indent = false; MemoryStream stream = Serialize(settings, archetype); AmSerializer.ValidateArchetype(stream); return true; }
public static MemoryStream Serialize(XmlWriterSettings settings, ARCHETYPE archetype) { MemoryStream result = new MemoryStream(); if (settings != null) ArchetypeSerialiser.Serialize(XmlWriter.Create(result, settings), archetype); else ArchetypeSerialiser.Serialize(result, archetype); return result; }
public static void Serialize(XmlWriter writer, ARCHETYPE archetype) { ArchetypeSerialiser.Serialize(writer, archetype); }
public static ARCHETYPE CanonicalArchetype(ARCHETYPE archetype) { return new CanonicalAmVisitor().VisitArchetype(archetype); }
public void OpenFile(string a_file_name) { _open_file_error = false; _status = ""; _archetype = null; _ontology = null; try { XmlReader xml_reader = XmlReader.Create(a_file_name); XmlSerializer xmlSerialiser = new XmlSerializer(typeof(ARCHETYPE)); ARCHETYPE new_archetype = xmlSerialiser.Deserialize(xml_reader) as ARCHETYPE; xml_reader.Close(); _archetype = new_archetype; _ontology = null; } catch (Exception e) { _open_file_error = true; _status = "Open file error: " + e; System.Diagnostics.Debug.Assert(false, e.ToString()); } }
public void NewArchetype(string an_archetypeID, string a_languageCode, string defaultLanguageCodeSet) { _archetype = new ARCHETYPE(); _ontology = null; ARCHETYPE_ID archetypeId = new ARCHETYPE_ID(); archetypeId.value = an_archetypeID; _archetype.archetype_id = archetypeId; _archetype.description = new RESOURCE_DESCRIPTION(); _archetype.original_language = new CODE_PHRASE(); _archetype.original_language.code_string = a_languageCode; if (defaultLanguageCodeSet != "") { TERMINOLOGY_ID terminologyId = new TERMINOLOGY_ID(); terminologyId.value = defaultLanguageCodeSet; _archetype.original_language.terminology_id = terminologyId; } _archetype.description.lifecycle_state = "AuthorDraft"; _archetype.concept = "at0000"; _archetype.definition = new C_COMPLEX_OBJECT(); _archetype.definition.node_id = _archetype.concept; string[] y = an_archetypeID.Split(".-".ToCharArray()); _archetype.definition.rm_type_name = y[2]; _archetype.ontology = new ARCHETYPE_ONTOLOGY(); _archetype.ontology.term_definitions = Array.CreateInstance(typeof(CodeDefinitionSet), 1) as CodeDefinitionSet[]; _archetype.ontology.term_definitions[0] = new CodeDefinitionSet(); _archetype.ontology.term_definitions[0].language = a_languageCode; _archetype.ontology.term_definitions[0].items = Array.CreateInstance(typeof(ARCHETYPE_TERM), 1) as ARCHETYPE_TERM[]; _archetype.ontology.term_definitions[0].items[0] = new ARCHETYPE_TERM(); _archetype.ontology.term_definitions[0].items[0].code = "at0000"; _archetype.ontology.term_definitions[0].items[0].items = Array.CreateInstance(typeof(StringDictionaryItem), 2) as StringDictionaryItem[]; _archetype.ontology.term_definitions[0].items[0].items[0] = new StringDictionaryItem(); _archetype.ontology.term_definitions[0].items[0].items[0].id = "text"; _archetype.ontology.term_definitions[0].items[0].items[0].Value = "?"; _archetype.ontology.term_definitions[0].items[0].items[1] = new StringDictionaryItem(); _archetype.ontology.term_definitions[0].items[0].items[1].id = "description"; _archetype.ontology.term_definitions[0].items[0].items[1].Value = "*"; AddDescriptionItem(_archetype.original_language); }