Search in sources :

Example 1 with StringValue

use of org.hl7.fhir.utilities.graphql.StringValue in project elexis-server by elexis.

the class ObservationTest method laboratoryObservations.

@Test
public void laboratoryObservations() throws FHIRException {
    // search by patient and category
    Bundle results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Condition.CATEGORY.exactly().code("laboratory")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    assertFalse(results.getEntry().isEmpty());
    @SuppressWarnings("unchecked") List<Observation> observations = (List<Observation>) ((List<?>) results.getEntry().parallelStream().map(be -> be.getResource()).collect(Collectors.toList()));
    for (Observation observation : observations) {
        assertTrue(observation.hasEffectiveDateTimeType());
        assertTrue(observation.hasValue());
        assertNotNull(observation.getCode());
        List<Coding> coding = observation.getCode().getCoding();
        assertFalse(coding.isEmpty());
        for (Coding code : coding) {
            if (code.getCode().contains("NUMERIC")) {
                if (observation.hasValueQuantity()) {
                    Quantity quantityValue = observation.getValueQuantity();
                    assertNotNull(quantityValue);
                } else if (observation.hasValueStringType()) {
                    StringType stringValue = observation.getValueStringType();
                    assertNotNull(stringValue);
                    assertTrue(Character.isDigit(stringValue.toString().charAt(0)));
                } else {
                    fail("Unexpected vaue type" + observation.getValue());
                }
                List<ObservationReferenceRangeComponent> refs = observation.getReferenceRange();
                assertFalse(refs.isEmpty());
            } else if (code.getCode().contains("TEXT")) {
                StringType stringValue = observation.getValueStringType();
                assertNotNull(stringValue);
            }
        }
    }
}
Also used : TransientCoding(ch.elexis.core.findings.util.model.TransientCoding) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) Quantity(org.hl7.fhir.r4.model.Quantity) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 2 with StringValue

use of org.hl7.fhir.utilities.graphql.StringValue in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method parseParams.

private void parseParams(List<Argument> params, String value, Resource res) {
    boolean refed = false;
    Map<String, List<String>> p = splitQuery(value);
    for (String n : p.keySet()) {
        for (String v : p.get(n)) {
            if (v.equals("{ref}")) {
                refed = true;
                v = res.fhirType() + '/' + res.getId();
            }
            params.add(new Argument(n, new StringValue(v)));
        }
    }
    check(refed, "no use of {ref} found");
}
Also used : Argument(org.hl7.fhir.utilities.graphql.Argument) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) StringValue(org.hl7.fhir.utilities.graphql.StringValue)

Example 3 with StringValue

use of org.hl7.fhir.utilities.graphql.StringValue in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processReverseReferenceList.

private void processReverseReferenceList(Resource source, Field field, ObjectValue target, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    if (services == null)
        throw new EGraphQLException("Resource Referencing services not provided");
    List<IBaseResource> list = new ArrayList<>();
    List<Argument> params = new ArrayList<>();
    Argument parg = null;
    for (Argument a : field.getArguments()) if (!(a.getName().equals("_reference")))
        params.add(a);
    else if ((parg == null))
        parg = a;
    else
        throw new EGraphQLException("Duplicate parameter _reference");
    if (parg == null)
        throw new EGraphQLException("Missing parameter _reference");
    Argument arg = new Argument();
    params.add(arg);
    arg.setName(getSingleValue(parg));
    arg.addValue(new StringValue(source.fhirType() + "/" + source.getIdPart()));
    services.listResources(appInfo, field.getName().substring(0, field.getName().length() - 4), params, list);
    arg = null;
    ObjectValue obj = null;
    List<Resource> vl = filterResources(field.argument("fhirpath"), list);
    if (!vl.isEmpty()) {
        arg = target.addField(field.getAlias() + suffix, listStatus(field, true));
        for (Resource v : vl) {
            obj = new ObjectValue();
            arg.addValue(obj);
            processObject(v, v, obj, field.getSelectionSet(), inheritedList, suffix);
        }
    }
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) StringValue(org.hl7.fhir.utilities.graphql.StringValue) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 4 with StringValue

use of org.hl7.fhir.utilities.graphql.StringValue in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processValues.

private void processValues(Resource context, Selection sel, Property prop, ObjectValue target, List<Base> values, boolean extensionMode, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException {
    boolean il = false;
    Argument arg = null;
    ExpressionNode expression = null;
    if (sel.getField().hasDirective("slice")) {
        Directive dir = sel.getField().directive("slice");
        String s = ((StringValue) dir.getArguments().get(0).getValues().get(0)).getValue();
        if (s.equals("$index"))
            expression = magicExpression;
        else
            expression = fpe.parse(s);
    }
    if (// special: instruction to drop this node...
    sel.getField().hasDirective("flatten"))
        il = prop.isList() && !sel.getField().hasDirective("first");
    else if (sel.getField().hasDirective("first")) {
        if (expression != null)
            throw new FHIRException("You cannot mix @slice and @first");
        arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), inheritedList));
    } else if (expression == null)
        arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
    int index = 0;
    for (Base value : values) {
        String ss = "";
        if (expression != null) {
            if (expression == magicExpression)
                ss = suffix + '.' + Integer.toString(index);
            else
                ss = suffix + '.' + fpe.evaluateToString(null, null, null, value, expression);
            if (!sel.getField().hasDirective("flatten"))
                arg = target.addField(sel.getField().getAlias() + suffix, listStatus(sel.getField(), prop.isList() || inheritedList));
        }
        if (value.isPrimitive() && !extensionMode) {
            if (!sel.getField().getSelectionSet().isEmpty())
                throw new EGraphQLException("Encountered a selection set on a scalar field type");
            processPrimitive(arg, value);
        } else {
            if (sel.getField().getSelectionSet().isEmpty())
                throw new EGraphQLException("No Fields selected on a complex object");
            if (arg == null)
                processObject(context, value, target, sel.getField().getSelectionSet(), il, ss);
            else {
                ObjectValue n = new ObjectValue();
                arg.addValue(n);
                processObject(context, value, n, sel.getField().getSelectionSet(), il, ss);
            }
        }
        if (sel.getField().hasDirective("first"))
            return;
        index++;
    }
}
Also used : ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) Argument(org.hl7.fhir.utilities.graphql.Argument) StringValue(org.hl7.fhir.utilities.graphql.StringValue) Directive(org.hl7.fhir.utilities.graphql.Directive) FHIRException(org.hl7.fhir.exceptions.FHIRException) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 5 with StringValue

use of org.hl7.fhir.utilities.graphql.StringValue in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method processPrimitive.

private void processPrimitive(Argument arg, Base value) {
    String s = value.fhirType();
    if (s.equals("integer") || s.equals("decimal") || s.equals("unsignedInt") || s.equals("positiveInt"))
        arg.addValue(new NumberValue(value.primitiveValue()));
    else if (s.equals("boolean"))
        arg.addValue(new NameValue(value.primitiveValue()));
    else
        arg.addValue(new StringValue(value.primitiveValue()));
}
Also used : NameValue(org.hl7.fhir.utilities.graphql.NameValue) NumberValue(org.hl7.fhir.utilities.graphql.NumberValue) StringValue(org.hl7.fhir.utilities.graphql.StringValue)

Aggregations

StringValue (org.hl7.fhir.utilities.graphql.StringValue)12 Argument (org.hl7.fhir.utilities.graphql.Argument)10 ArrayList (java.util.ArrayList)8 EGraphQLException (org.hl7.fhir.utilities.graphql.EGraphQLException)8 ObjectValue (org.hl7.fhir.utilities.graphql.ObjectValue)8 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)4 List (java.util.List)3 LinkedList (java.util.LinkedList)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 Base (org.hl7.fhir.r4b.model.Base)2 Bundle (org.hl7.fhir.r4b.model.Bundle)2 Directive (org.hl7.fhir.utilities.graphql.Directive)2 NameValue (org.hl7.fhir.utilities.graphql.NameValue)2 NumberValue (org.hl7.fhir.utilities.graphql.NumberValue)2 CodeInfo (au.csiro.redmatch.terminology.CodeInfo)1 IObservation (ch.elexis.core.findings.IObservation)1 TransientCoding (ch.elexis.core.findings.util.model.TransientCoding)1 JsonElement (com.google.gson.JsonElement)1 Field (java.lang.reflect.Field)1 Matcher (java.util.regex.Matcher)1