Search in sources :

Example 26 with IndexOf

use of org.hl7.elm.r1.IndexOf in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionsServiceTest method testFindActionDetail.

@Test
public void testFindActionDetail() throws Exception {
    ActionDetail actionDetail = fieldActionsService.findActionDetail(new Prepend(), FieldType.STRING);
    assertNotNull(actionDetail);
    System.out.println(new ObjectMapper().writeValueAsString(actionDetail.getActionSchema()));
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.STRING);
    assertNotNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new Action() {
    }, FieldType.STRING);
    assertNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), null);
    assertNotNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.STRING);
    assertNotNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.ANY);
    assertNotNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.NONE);
    assertNotNull(actionDetail);
    actionDetail = fieldActionsService.findActionDetail(new IndexOf(), FieldType.BOOLEAN);
    assertNotNull(actionDetail);
}
Also used : Prepend(io.atlasmap.v2.Prepend) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) IndexOf(io.atlasmap.v2.IndexOf) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 27 with IndexOf

use of org.hl7.elm.r1.IndexOf in project atlasmap by atlasmap.

the class StringComplexFieldActionsTest method testIndexOf.

@Test
public void testIndexOf() {
    IndexOf action = new IndexOf();
    action.setString("");
    assertEquals(-1, StringComplexFieldActions.indexOf(action, null));
    assertEquals(0, StringComplexFieldActions.indexOf(action, ""));
    assertEquals(0, StringComplexFieldActions.indexOf(action, "foo"));
    action.setString("bar");
    assertEquals(-1, StringComplexFieldActions.indexOf(action, null));
    assertEquals(-1, StringComplexFieldActions.indexOf(action, ""));
    assertEquals(-1, StringComplexFieldActions.indexOf(action, "foo"));
    assertEquals(3, StringComplexFieldActions.indexOf(action, "foobar"));
    assertEquals(3, StringComplexFieldActions.indexOf(action, "foobarbar"));
}
Also used : IndexOf(io.atlasmap.v2.IndexOf) LastIndexOf(io.atlasmap.v2.LastIndexOf) Test(org.junit.jupiter.api.Test)

Example 28 with IndexOf

use of org.hl7.elm.r1.IndexOf in project kindling by HL7.

the class SpreadSheetReloader method parseStatus.

private void parseStatus(Element ed, String value) {
    ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
    ed.removeExtension(BuildExtensions.EXT_STANDARDS_STATUS);
    ed.removeExtension(BuildExtensions.EXT_NORMATIVE_VERSION);
    if (!Utilities.noString(value) && value.contains("/")) {
        String[] p = value.split("\\/");
        if (Utilities.noString(p[0].trim())) {
            ed.removeExtension(BuildExtensions.EXT_FMM_LEVEL);
        } else {
            ed.addExtension(BuildExtensions.EXT_FMM_LEVEL, new IntegerType(p[0]));
        }
        if (p[1].contains(";")) {
            ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1].substring(0, p[1].indexOf(";"))));
            ed.addExtension(BuildExtensions.EXT_NORMATIVE_VERSION, new CodeType(p[1].substring(p[1].indexOf("from=") + 5)));
        } else {
            ed.addExtension(BuildExtensions.EXT_STANDARDS_STATUS, new CodeType(p[1]));
        }
    }
    sortExtensions(ed);
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) CodeType(org.hl7.fhir.r5.model.CodeType)

Example 29 with IndexOf

use of org.hl7.elm.r1.IndexOf in project kindling by HL7.

the class ValueSetFinder method checkSearchParams.

private static void checkSearchParams(File f) throws Exception {
    String folder = Utilities.getDirectoryForFile(f.getAbsolutePath());
    System.out.println(f.getName());
    try {
        Set<String> s = new HashSet<>();
        for (File fsp : new File(folder).listFiles()) {
            if (fsp.getName().startsWith("searchparameter-")) {
                SearchParameter sp = (SearchParameter) new XmlParser().parseAndClose(new FileInputStream(fsp));
                s.add(sp.getId());
            }
        }
        for (File fig : new File(folder).listFiles()) {
            if (fig.getName().startsWith("implementationguide-")) {
                ImplementationGuide ig = (ImplementationGuide) new XmlParser().parseAndClose(new FileInputStream(fig));
                ig.getDefinition().getResource().removeIf(res -> res.getReference().getReference().startsWith("SearchParameter/") && !s.contains(res.getReference().getReference().substring(res.getReference().getReference().indexOf("/") + 1)));
                if (ig.getDefinition().getResource().isEmpty()) {
                    fig.delete();
                } else {
                    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fig), ig);
                }
            }
        }
    } catch (Exception e) {
        System.out.println("  " + e.getMessage());
    }
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) XLSXmlParser(org.hl7.fhir.utilities.xls.XLSXmlParser) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) FileOutputStream(java.io.FileOutputStream) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) File(java.io.File) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException) HashSet(java.util.HashSet)

Example 30 with IndexOf

use of org.hl7.elm.r1.IndexOf in project kindling by HL7.

the class PageProcessor method checkFormat.

private void checkFormat(String filename, String res, ResourceDefn r) throws FHIRException {
    XhtmlNode doc;
    try {
        doc = new XhtmlParser().parse("<div>" + res + "</div>", null).getFirstElement();
        if (doc.getFirstElement() == null || !doc.getFirstElement().getName().equals("div"))
            log("file \"" + filename + "\": root element should be 'div'", LogMessageType.Error);
        else if (doc.getFirstElement() == null) {
            log("file \"" + filename + "\": there is no 'Scope and Usage'", LogMessageType.Error);
        } else {
            XhtmlNode scope = null;
            XhtmlNode context = null;
            for (XhtmlNode x : doc.getChildNodes()) {
                if (x.getNodeType() == NodeType.Element) {
                    if (!x.getName().equals("div")) {
                        log("file \"" + filename + "\": all child elements of the root div should be 'div's too (found '" + x.getName() + "')", LogMessageType.Error);
                        return;
                    } else if (x.getChildNodes().isEmpty()) {
                        log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "] must have at least an h2", LogMessageType.Error);
                        return;
                    } else if (!isFirstChildElementH2(x)) {
                        log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "] must start with an h2", LogMessageType.Error);
                        return;
                    } else {
                        XhtmlNode fn = getH2Element(x);
                        String s = fn.allText();
                        if (!((s.equals("Scope and Usage")) || (s.equals("Boundaries and Relationships")) || (s.equals("Background and Context")))) {
                            log("file \"" + filename + "\": div/div[" + Integer.toString(doc.getChildNodes().indexOf(x)) + "]/h2 must be either 'Scope and Usage', 'Boundaries and Relationships', or 'Background and Context'", LogMessageType.Error);
                            return;
                        } else {
                            if (scope == null) {
                                if (s.equals("Scope and Usage")) {
                                    scope = x;
                                    if (r != null)
                                        r.setRequirements(new XhtmlComposer(XhtmlComposer.HTML).composePlainText(x));
                                } else {
                                    log("file \"" + filename + "\": 'Scope and Usage' must come first", LogMessageType.Error);
                                    return;
                                }
                                if (s.equals("Boundaries and Relationships")) {
                                    if (context != null) {
                                        log("file \"" + filename + "\": 'Boundaries and Relationships' must come first before 'Background and Context'", LogMessageType.Error);
                                        return;
                                    }
                                }
                                if (s.equals("Background and Context"))
                                    context = x;
                            }
                        }
                        boolean found = false;
                        for (XhtmlNode n : x.getChildNodes()) {
                            if (!found)
                                found = n == fn;
                            else {
                                if ("h1".equals(n.getName()) || "h2".equals(n.getName())) {
                                    log("file \"" + filename + "\": content of a <div> inner section cannot contain h1 or h2 headings", LogMessageType.Error);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
        List<String> allowed = Arrays.asList("div", "h2", "h3", "h4", "h5", "i", "b", "code", "pre", "blockquote", "p", "a", "img", "table", "thead", "tbody", "tr", "th", "td", "ol", "ul", "li", "br", "span", "em", "strong");
        iterateAllChildNodes(doc, allowed);
    } catch (Exception e) {
        throw new FHIRException("Error processing " + filename + ": " + e.getMessage(), e);
    }
}
Also used : XhtmlParser(org.hl7.fhir.utilities.xhtml.XhtmlParser) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) FHIRException(org.hl7.fhir.exceptions.FHIRException) UcumException(org.fhir.ucum.UcumException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FileNotFoundException(java.io.FileNotFoundException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 ArrayList (java.util.ArrayList)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 List (java.util.List)5 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)5 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)5 File (java.io.File)4 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 IndexOf (io.atlasmap.v2.IndexOf)2