//Defining base and require base = "https://build.fhir.org/" header = document.querySelector("head") var scr = document.createElement('script'); scr.setAttribute("src", "https://requirejs.org/docs/release/2.3.5/minified/require.js") header.appendChild(scr); //Getting ShEx function getshex(){ //Getting the Name of the Example resource = document.querySelector(".active").querySelector("span").innerText name = resource.slice(0, resource.indexOf(" (")).toLowerCase() shexid = base + name + ".shex" //Get the output of the URL xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET", shexid, false); xmlhttp.send(); var sdata = xmlhttp.responseText; shexfield.value = 'BASE <'+base+'>\n'+sdata } //Validating Schema function validateshex(){ //Preliminary code not working const rootTriple = this.expectOne(N3.store.getQuads(null, P.fhir + 'nodeRole', P.fhir + 'treeRoot'), 'nodeRole treeRoot'); const node = rootTriple.subject;\n const typeTriple = this.expectOne(N3.store.getQuads(node, P.rdf + 'type', null), 'fhir type'); const type = this.expectFhirResource(typeTriple.object); const shape = shexfield.value; const db = ShExUtil.rdfjsDB(N3.store, null); // no query tracker needed const validator = ShExValidator.construct(shexfield.value, db, { regexModule: EvalSimple1err }); //Showing results const res = validator.validate([{node, shape}]); container = document.querySelector('#output-container') shex_r = container.querySelector("#markup-errors") if (shex_r == null) { var shexresults = document.createElement('div'); shexresults.setAttribute("class", "hide alert alert-error") shexresults.setAttribute("id", "markup-errors") shexresults.setAttribute("bis_skin_checked", "1") shexresults.setAttribute("style", "display: block;") shexresults.innerText = res container.appendChild(shexresults); } else { shex_r.innerText = res } } //Adding field and buttons container = document.querySelector('#output-container') var shexfield = document.createElement('textarea'); shexfield.setAttribute("style", "width: 100%; height: 100%;") shexfield.setAttribute("class", "shexarea") container.appendChild(shexfield); var button1 = document.createElement('button'); button1.setAttribute("type", "button"); button1.setAttribute("onclick", "getshex()"); button1.textContent = "Get"; container.appendChild(button1); var button2 = document.createElement('button'); button2.setAttribute("type", "button"); button2.setAttribute("onclick", "validateshex()"); button2.textContent = "Validate"; container.appendChild(button2);