Search in sources :

Example 16 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.

the class Regenerator method generateInner.

public void generateInner(ResourceDefn r) throws FileNotFoundException, IOException {
    String root = Utilities.path(srcFolder, r.getName());
    generateSearchParams(root, r);
    generateExamples(root, r);
    generateOperations(r, root);
    generatePacks(r, root);
    // private List<Profile> conformancePackages = new ArrayList<Profile>();
    // private Profile conformancePack;
    StructureDefinition sd = r.getProfile().copy();
    sd.setSnapshot(null);
    sd.setText(null);
    if (r.getEnteredInErrorStatus() != null) {
        sd.addExtension(BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS, new CodeType(r.getEnteredInErrorStatus()));
    }
    if (r.getProposedOrder() != null) {
        sd.addExtension(BuildExtensions.EXT_PROPOSED_ORDER, new StringType(r.getProposedOrder()));
    }
    if (r.getTemplate() != null) {
        sd.addExtension(BuildExtensions.EXT_TEMPLATE, new StringType(r.getTemplate().getName()));
    }
    // now, walk through the elements.
    generateElement(root, r.getName(), sd.getDifferential(), r, r.getRoot());
    File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-" + sd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File)

Example 17 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.

the class Regenerator method generateExamples.

private void generateExamples(String root, ResourceDefn r) throws FileNotFoundException, IOException {
    ListResource list = new ListResource();
    list.setId(r.getName() + "-examples");
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.WORKING);
    for (Example ex : r.getExamples()) {
        ListResourceEntryComponent li = list.addEntry();
        li.getItem().setReference(ex.getResourceName() + "/" + ex.getId());
        li.getItem().setDisplay(ex.getName());
        if (ex.getDescription() != null) {
            li.addExtension(BuildExtensions.EXT_DESCRIPTION, new StringType(ex.getDescription()));
        }
        if (ex.getTitle() != null) {
            li.addExtension(BuildExtensions.EXT_TITLE, new StringType(ex.getTitle()));
        }
        switch(ex.getType()) {
            case Container:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container", null);
                break;
            case CsvFile:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv", null);
                break;
            case Tool:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool", null);
                break;
            default:
                break;
        }
        if (!ex.isRegistered()) {
            li.addExtension(BuildExtensions.EXT_NOT_REGISTERED, new BooleanType(!ex.isRegistered()));
        }
        if (ex.getIg() != null) {
            li.addExtension(BuildExtensions.EXT_IG, new CodeType(ex.getIg()));
        }
        if (ex.getExampleFor() != null) {
            li.addExtension(BuildExtensions.EXT_EXAMPLE_FOR, new StringType(ex.getExampleFor()));
        }
    }
    File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StringType(org.hl7.fhir.r5.model.StringType) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) CodeType(org.hl7.fhir.r5.model.CodeType) ListResource(org.hl7.fhir.r5.model.ListResource) File(java.io.File)

Example 18 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project kindling by HL7.

the class ProfileGenerator method makeSearchParam.

public SearchParameter makeSearchParam(StructureDefinition p, String id, String rn, SearchParameterDefn spd, ResourceDefn rd) throws Exception {
    boolean shared;
    boolean created = true;
    SearchParameter sp;
    if (definitions.getCommonSearchParameters().containsKey(rn + "::" + spd.getCode())) {
        shared = true;
        CommonSearchParameter csp = definitions.getCommonSearchParameters().get(rn + "::" + spd.getCode());
        if (csp.getDefinition() == null) {
            sp = new SearchParameter();
            csp.setDefinition(sp);
            sp.setId(csp.getId());
        } else {
            created = false;
            sp = csp.getDefinition();
        }
    } else {
        shared = false;
        sp = new SearchParameter();
        sp.setId(id.replace("[", "").replace("]", ""));
    }
    spd.setCommonId(sp.getId());
    if (created) {
        sp.setUrl("http://hl7.org/fhir/SearchParameter/" + sp.getId());
        sp.setVersion(version.toCode());
        if (context.getSearchParameter(sp.getUrl()) != null)
            throw new Exception("Duplicated Search Parameter " + sp.getUrl());
        context.cacheResource(sp);
        spd.setResource(sp);
        definitions.addNs(sp.getUrl(), "Search Parameter: " + sp.getName(), rn.toLowerCase() + ".html#search");
        sp.setStatus(spd.getStandardsStatus() == StandardsStatus.NORMATIVE ? PublicationStatus.fromCode("active") : PublicationStatus.fromCode("draft"));
        StandardsStatus sst = ToolingExtensions.getStandardsStatus(sp);
        if (sst == null || (spd.getStandardsStatus() == null && spd.getStandardsStatus().isLowerThan(sst)))
            ToolingExtensions.setStandardsStatus(sp, spd.getStandardsStatus(), spd.getNormativeVersion());
        sp.setExperimental(p.getExperimental());
        sp.setName(spd.getCode());
        sp.setCode(spd.getCode());
        sp.setDate(genDate.getTime());
        sp.setPublisher(p.getPublisher());
        for (ContactDetail tc : p.getContact()) {
            ContactDetail t = sp.addContact();
            if (tc.hasNameElement())
                t.setNameElement(tc.getNameElement().copy());
            for (ContactPoint ts : tc.getTelecom()) t.getTelecom().add(ts.copy());
        }
        if (!definitions.hasResource(p.getType()) && !p.getType().equals("Resource") && !p.getType().equals("DomainResource"))
            throw new Exception("unknown resource type " + p.getType());
        sp.setType(getSearchParamType(spd.getType()));
        if (sp.getType() == SearchParamType.REFERENCE && spd.isHierarchy()) {
            sp.addModifier(SearchParameter.SearchModifierCode.BELOW);
            sp.addModifier(SearchParameter.SearchModifierCode.ABOVE);
        }
        if (shared) {
            sp.setDescription("Multiple Resources: \r\n\r\n* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        } else
            sp.setDescription(preProcessMarkdown(spd.getDescription(), "Search Description"));
        if (!Utilities.noString(spd.getExpression()))
            sp.setExpression(spd.getExpression());
        // addModifiers(sp);
        addComparators(sp);
        String xpath = Utilities.noString(spd.getXPath()) ? new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn) : spd.getXPath();
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            sp.setXpath(xpath);
            sp.setXpathUsage(spd.getxPathUsage());
        }
        if (sp.getType() == SearchParamType.COMPOSITE) {
            for (CompositeDefinition cs : spd.getComposites()) {
                SearchParameterDefn cspd = findSearchParameter(rd, cs.getDefinition());
                if (cspd != null)
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition(cspd.getUrl());
                else
                    sp.addComponent().setExpression(cs.getExpression()).setDefinition("http://hl7.org/fhir/SearchParameter/" + rn + "-" + cs.getDefinition());
            }
            sp.setMultipleOr(false);
        }
        sp.addBase(p.getType());
    } else {
        if (sp.getType() != getSearchParamType(spd.getType()))
            throw new FHIRException("Type mismatch on common parameter: expected " + sp.getType().toCode() + " but found " + getSearchParamType(spd.getType()).toCode());
        if (!sp.getDescription().contains("[" + rn + "](" + rn.toLowerCase() + ".html)"))
            sp.setDescription(sp.getDescription() + "* [" + rn + "](" + rn.toLowerCase() + ".html): " + spd.getDescription() + "\r\n");
        // ext.addExtension("description", new MarkdownType(spd.getDescription()));
        if (!Utilities.noString(spd.getExpression()) && !sp.getExpression().contains(spd.getExpression()))
            sp.setExpression(sp.getExpression() + " | " + spd.getExpression());
        String xpath = new XPathQueryGenerator(this.definitions, null, null).generateXpath(spd.getPaths(), rn);
        if (xpath != null) {
            if (xpath.contains("[x]"))
                xpath = convertToXpath(xpath);
            if (sp.getXpath() != null && !sp.getXpath().contains(xpath))
                sp.setXpath(sp.getXpath() + " | " + xpath);
            if (sp.getXpathUsage() != spd.getxPathUsage())
                throw new FHIRException("Usage mismatch on common parameter: expected " + sp.getXpathUsage().toCode() + " but found " + spd.getxPathUsage().toCode());
        }
        boolean found = false;
        for (CodeType ct : sp.getBase()) found = found || p.getType().equals(ct.asStringValue());
        if (!found)
            sp.addBase(p.getType());
    }
    spd.setUrl(sp.getUrl());
    for (String target : spd.getWorkingTargets()) {
        if ("Any".equals(target) == true) {
            for (String resourceName : definitions.sortedResourceNames()) {
                boolean found = false;
                for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(resourceName);
                if (!found)
                    sp.addTarget(resourceName);
            }
        } else {
            boolean found = false;
            for (CodeType st : sp.getTarget()) found = found || st.asStringValue().equals(target);
            if (!found)
                sp.addTarget(target);
        }
    }
    return sp;
}
Also used : SearchParameterDefn(org.hl7.fhir.definitions.model.SearchParameterDefn) FHIRException(org.hl7.fhir.exceptions.FHIRException) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) CompositeDefinition(org.hl7.fhir.definitions.model.SearchParameterDefn.CompositeDefinition) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) CodeType(org.hl7.fhir.r5.model.CodeType) CommonSearchParameter(org.hl7.fhir.definitions.model.CommonSearchParameter) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) StandardsStatus(org.hl7.fhir.utilities.StandardsStatus)

Example 19 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProvider method lookup.

/**
 * This is a small patch to the OSS implementation to use named-parameter lookup on
 * the operation response instead of just assuming a positional location.
 */
@Override
public Code lookup(Code code, CodeSystemInfo codeSystem) throws ResourceNotFoundException {
    Parameters respParam = fhirClient.operation().onType(CodeSystem.class).named("lookup").withParameter(Parameters.class, "code", new CodeType(code.getCode())).andParameter("system", new UriType(codeSystem.getId())).execute();
    StringType display = (StringType) respParam.getParameter("display");
    if (display != null) {
        code.withDisplay(display.getValue());
    }
    return code.withSystem(codeSystem.getId());
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) CodeType(org.hl7.fhir.r4.model.CodeType) UriType(org.hl7.fhir.r4.model.UriType)

Example 20 with CodeType

use of org.hl7.fhir.r4.model.CodeType in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetUtilTest method testCorrectValidation.

@Test
public void testCorrectValidation() {
    ValueSetArtifact artifact = new ValueSetArtifact();
    artifact.setUrl("fakeUrl");
    ValueSet fakeValueSet = new ValueSet();
    fakeValueSet.setId("fakeId");
    fakeValueSet.setVersion("fakeVersion");
    ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
    ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
    component.setConcept(Collections.singletonList(new ValueSet.ConceptReferenceComponent(new CodeType("fakeCode"))));
    compose.setInclude(Collections.singletonList(component));
    fakeValueSet.setCompose(compose);
    artifact.setFhirResource(fakeValueSet);
    ValueSetUtil.validateArtifact(artifact);
}
Also used : CodeType(org.hl7.fhir.r4.model.CodeType) ValueSet(org.hl7.fhir.r4.model.ValueSet) Test(org.junit.Test)

Aggregations

CodeType (org.hl7.fhir.r5.model.CodeType)52 ArrayList (java.util.ArrayList)31 CodeType (org.hl7.fhir.r4.model.CodeType)28 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 CodeType (org.hl7.fhir.r4b.model.CodeType)17 Date (java.util.Date)15 CodeType (org.hl7.fhir.dstu3.model.CodeType)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 File (java.io.File)11 Extension (org.hl7.fhir.dstu3.model.Extension)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)10 StringType (org.hl7.fhir.r5.model.StringType)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 Coding (org.hl7.fhir.r4.model.Coding)9 Coding (org.hl7.fhir.dstu3.model.Coding)8 FileOutputStream (java.io.FileOutputStream)7 List (java.util.List)7 Parameters (org.hl7.fhir.r4.model.Parameters)7 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)7