public void TestSingleValueBinding() { // Setup data for the test var cs = this.tdb.FindOrCreateCodeSystem("Test Code System", "http://test.com/codesystem"); var template1 = this.tdb.GenerateTemplate("http://test.com/composition", "Composition", "Test Composition", this.ig, "Composition", "Composition"); var template2 = this.tdb.GenerateTemplate("http://test.com/section", "List", "Test Section", this.ig, "List", "List"); var sectionConstraint = this.tdb.GenerateConstraint(template1, null, null, "section", "SHALL", "1..1", isBranch: true); this.tdb.GenerateConstraint(template1, sectionConstraint, null, "code", "SHALL", "1..1", null, null, "1234-x", "Test Code", null, cs, isBranchIdentifier: true); this.tdb.GenerateConstraint(template1, sectionConstraint, template2, "content", "SHALL", "1..1"); // Export the templates string export = FHIRExporter.GenerateExport(this.tdb, this.tdb.Templates.ToList(), new IGSettingsManager(this.tdb, this.ig.Id)); XmlDocument doc = new XmlDocument(); doc.LoadXml(export); XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable); nsManager.AddNamespace("fhir", "http://hl7.org/fhir"); nsManager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); var profile = doc.SelectSingleNode("//atom:entry/atom:content/fhir:Profile[fhir:identifier/@value = 'http://test.com/composition']", nsManager); var section = profile.SelectSingleNode("fhir:structure/fhir:element[fhir:path/@value = 'Composition.section']", nsManager); var sectionCode = profile.SelectSingleNode("fhir:structure/fhir:element[fhir:path/@value = 'Composition.section.code']", nsManager); AssertXML.XPathExists(section, nsManager, "fhir:name[@value]"); AssertXML.XPathExists(section, nsManager, "fhir:slicing[fhir:discriminator/@value='code'][fhir:ordered/@value='false'][fhir:rules/@value='open']"); Assert.IsNotNull(sectionCode); AssertXML.XPathExists(sectionCode, nsManager, "fhir:definition/fhir:valueCodeableConcept/fhir:coding[fhir:system/@value = 'http://test.com/codesystem'][fhir:code/@value = '1234-x'][fhir:display/@value = 'Test Code']"); }
public string Export(DB.IObjectRepository tdb, SimpleSchema schema, ExportFormats format, IGSettingsManager igSettings, List <string> categories, List <DB.Template> templates, bool includeVocabulary, bool returnJson = true) { switch (format) { case ExportFormats.FHIR: string export = FHIRExporter.GenerateExport(tdb, templates, igSettings, categories, includeVocabulary); if (returnJson) { fhir_dstu1.Hl7.Fhir.Model.Bundle bundle = fhir_dstu1.Hl7.Fhir.Serialization.FhirParser.ParseBundleFromXml(export); export = fhir_dstu1.Hl7.Fhir.Serialization.FhirSerializer.SerializeBundleToJson(bundle); } return(export); case ExportFormats.Proprietary: NativeExporter proprietaryExporter = new NativeExporter(tdb, templates, igSettings, true, categories); return(proprietaryExporter.GenerateXMLExport()); case ExportFormats.TemplatesDSTU: DecorExporter decorExporter = new DecorExporter(templates, tdb, igSettings.ImplementationGuideId); return(decorExporter.GenerateXML()); case ExportFormats.Snapshot: default: throw new Exception("Invalid export format for the specified implementation guide type"); } }
public HttpResponseMessage GetProfile(string templateOid, string _format = "") { string fhirTemplatesExportString = string.Empty; ImplementationGuideType igType = GetFHIRIGType(); User currentUser = CheckPoint.Instance.GetUser(); int templateId = 0; Int32.TryParse(templateOid, out templateId); var fhirTemplatesQuery = this.tdb.Templates.Where(y => (y.Id == templateId || y.Oid == templateOid) && y.ImplementationGuideTypeId == igType.Id); List <Template> fhirTemplates; if (!CheckPoint.Instance.IsDataAdmin) { fhirTemplates = (from vtp in this.tdb.ViewTemplatePermissions join t in fhirTemplatesQuery on vtp.TemplateId equals t.Id where vtp.UserId == currentUser.Id select t) .ToList(); } else { fhirTemplates = fhirTemplatesQuery.ToList(); } if (fhirTemplates.Count == 0) { throw new Exception("Could not find specified FHIR profile/template."); } try { fhirTemplatesExportString = FHIRExporter.GenerateExport(this.tdb, fhirTemplates, new IGSettingsManager(this.tdb)); } catch (Exception ex) { throw new Exception("Failed to generate bundle export of FHIR templates: " + ex.Message, ex); } try { Bundle fhirTemplatesBundle = FhirParser.ParseBundleFromXml(fhirTemplatesExportString); return(GetResponseMessage(_format, fhirTemplatesBundle)); } catch (Exception ex) { throw new Exception("Failed to parse exported bundle for return: " + ex.Message, ex); } }
public void ExportFHIRComposition() { MockObjectRepository tdb = new MockObjectRepository(); tdb.InitializeFHIRRepository(); ImplementationGuide ig = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_DSTU1_IG_TYPE_NAME, "Test FHIR IG"); Template t = tdb.GenerateTemplate("FHIR_1.2.3.4", "Composition", "Test FHIR Composition", ig, "Composition", "Composition"); var tc1 = tdb.GenerateConstraint(t, null, null, "subject", "SHALL", "1..1"); var tc2 = tdb.GenerateConstraint(t, null, null, "author", "SHALL", "1..1"); List <Template> templates = new List <Template>(); templates.Add(t); string export = FHIRExporter.GenerateExport(tdb, templates, new Trifolia.Shared.IGSettingsManager(tdb)); Assert.IsNotNull(export, "Expected generated export not to be null"); Assert.AreNotEqual(0, export.Length, "Expected generated export not to be empty"); }
public static void Setup(TestContext context) { FHIRDSTU1ExportTest.tdb = new MockObjectRepository(); TrifoliaImporter importer = new TrifoliaImporter(FHIRDSTU1ExportTest.tdb); FHIRDSTU1ExportTest.tdb.InitializeFHIRRepository(); FHIRDSTU1ExportTest.tdb.InitializeLCGAndLogin(); string importContent = Helper.GetSampleContents(IMPORT_XML); var importModel = ImportModel.Deserialize(importContent); var importStatus = importer.Import(importModel); Assert.IsTrue(importStatus.Success, "Expected import to succeed"); Assert.AreNotEqual(importStatus.ImplementationGuides.Count, 0, "Expected import to include implementation guides"); IGSettingsManager igManager = new IGSettingsManager(tdb, importStatus.ImplementationGuides.First().InternalId); TemplateImporter templateImporter = new TemplateImporter(tdb, shouldUpdate: true); FHIRDSTU1ExportTest.exportedXml = FHIRExporter.GenerateExport(tdb, templateImporter.Import(importModel.Template), igManager); Assert.IsNotNull(FHIRDSTU1ExportTest.exportedXml); }