Search in sources :

Example 56 with Account

use of org.hl7.fhir.dstu3.model.Account in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_account_example.

@Test
public void test_account_example() throws FileNotFoundException, IOException, Exception {
    System.out.println("account-example.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\account-example.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Example 57 with Account

use of org.hl7.fhir.dstu3.model.Account in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeEncounter.

protected void composeEncounter(Complex parent, String parentType, String name, Encounter element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Encounter", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "Encounter", "identifier", element.getIdentifier().get(i), i);
    if (element.hasStatusElement())
        composeEnum(t, "Encounter", "status", element.getStatusElement(), -1);
    for (int i = 0; i < element.getStatusHistory().size(); i++) composeEncounterStatusHistoryComponent(t, "Encounter", "statusHistory", element.getStatusHistory().get(i), i);
    if (element.hasClass_())
        composeCoding(t, "Encounter", "class", element.getClass_(), -1);
    for (int i = 0; i < element.getClassHistory().size(); i++) composeEncounterClassHistoryComponent(t, "Encounter", "classHistory", element.getClassHistory().get(i), i);
    for (int i = 0; i < element.getType().size(); i++) composeCodeableConcept(t, "Encounter", "type", element.getType().get(i), i);
    if (element.hasPriority())
        composeCodeableConcept(t, "Encounter", "priority", element.getPriority(), -1);
    if (element.hasSubject())
        composeReference(t, "Encounter", "subject", element.getSubject(), -1);
    for (int i = 0; i < element.getEpisodeOfCare().size(); i++) composeReference(t, "Encounter", "episodeOfCare", element.getEpisodeOfCare().get(i), i);
    for (int i = 0; i < element.getIncomingReferral().size(); i++) composeReference(t, "Encounter", "incomingReferral", element.getIncomingReferral().get(i), i);
    for (int i = 0; i < element.getParticipant().size(); i++) composeEncounterEncounterParticipantComponent(t, "Encounter", "participant", element.getParticipant().get(i), i);
    if (element.hasAppointment())
        composeReference(t, "Encounter", "appointment", element.getAppointment(), -1);
    if (element.hasPeriod())
        composePeriod(t, "Encounter", "period", element.getPeriod(), -1);
    if (element.hasLength())
        composeDuration(t, "Encounter", "length", element.getLength(), -1);
    for (int i = 0; i < element.getReason().size(); i++) composeCodeableConcept(t, "Encounter", "reason", element.getReason().get(i), i);
    for (int i = 0; i < element.getDiagnosis().size(); i++) composeEncounterDiagnosisComponent(t, "Encounter", "diagnosis", element.getDiagnosis().get(i), i);
    for (int i = 0; i < element.getAccount().size(); i++) composeReference(t, "Encounter", "account", element.getAccount().get(i), i);
    if (element.hasHospitalization())
        composeEncounterEncounterHospitalizationComponent(t, "Encounter", "hospitalization", element.getHospitalization(), -1);
    for (int i = 0; i < element.getLocation().size(); i++) composeEncounterEncounterLocationComponent(t, "Encounter", "location", element.getLocation().get(i), i);
    if (element.hasServiceProvider())
        composeReference(t, "Encounter", "serviceProvider", element.getServiceProvider(), -1);
    if (element.hasPartOf())
        composeReference(t, "Encounter", "partOf", element.getPartOf(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 58 with Account

use of org.hl7.fhir.dstu3.model.Account in project org.hl7.fhir.core by hapifhir.

the class Tester method main.

public static void main(String[] args) throws Exception {
    IWorkerContext context = SimpleWorkerContext.fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
    int t = 0;
    int ok = 0;
    for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
        if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
            // if (f.equals("account-questionnaire.xml")) {
            System.out.print("convert " + f);
            // Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
            // new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
            // String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
            // String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
            Element e = Manager.parse(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
            Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
            Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
            String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
            String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
            t++;
            if (src.equals(tgt)) {
                System.out.println(".. ok");
                ok++;
            } else
                System.out.println(".. fail");
        }
    // }
    }
    System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
Also used : IWorkerContext(org.hl7.fhir.dstu3.context.IWorkerContext) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FileInputStream(java.io.FileInputStream)

Example 59 with Account

use of org.hl7.fhir.dstu3.model.Account in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeEncounter.

protected void composeEncounter(Complex parent, String parentType, String name, Encounter element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "Encounter", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "Encounter", "identifier", element.getIdentifier().get(i), i);
    if (element.hasStatusElement())
        composeEnum(t, "Encounter", "status", element.getStatusElement(), -1);
    for (int i = 0; i < element.getStatusHistory().size(); i++) composeEncounterStatusHistoryComponent(t, "Encounter", "statusHistory", element.getStatusHistory().get(i), i);
    if (element.hasClass_())
        composeCoding(t, "Encounter", "class", element.getClass_(), -1);
    for (int i = 0; i < element.getClassHistory().size(); i++) composeEncounterClassHistoryComponent(t, "Encounter", "classHistory", element.getClassHistory().get(i), i);
    for (int i = 0; i < element.getType().size(); i++) composeCodeableConcept(t, "Encounter", "type", element.getType().get(i), i);
    if (element.hasServiceType())
        composeCodeableConcept(t, "Encounter", "serviceType", element.getServiceType(), -1);
    if (element.hasPriority())
        composeCodeableConcept(t, "Encounter", "priority", element.getPriority(), -1);
    if (element.hasSubject())
        composeReference(t, "Encounter", "subject", element.getSubject(), -1);
    for (int i = 0; i < element.getEpisodeOfCare().size(); i++) composeReference(t, "Encounter", "episodeOfCare", element.getEpisodeOfCare().get(i), i);
    for (int i = 0; i < element.getBasedOn().size(); i++) composeReference(t, "Encounter", "basedOn", element.getBasedOn().get(i), i);
    for (int i = 0; i < element.getParticipant().size(); i++) composeEncounterEncounterParticipantComponent(t, "Encounter", "participant", element.getParticipant().get(i), i);
    for (int i = 0; i < element.getAppointment().size(); i++) composeReference(t, "Encounter", "appointment", element.getAppointment().get(i), i);
    if (element.hasPeriod())
        composePeriod(t, "Encounter", "period", element.getPeriod(), -1);
    if (element.hasLength())
        composeDuration(t, "Encounter", "length", element.getLength(), -1);
    for (int i = 0; i < element.getReasonCode().size(); i++) composeCodeableConcept(t, "Encounter", "reasonCode", element.getReasonCode().get(i), i);
    for (int i = 0; i < element.getReasonReference().size(); i++) composeReference(t, "Encounter", "reasonReference", element.getReasonReference().get(i), i);
    for (int i = 0; i < element.getDiagnosis().size(); i++) composeEncounterDiagnosisComponent(t, "Encounter", "diagnosis", element.getDiagnosis().get(i), i);
    for (int i = 0; i < element.getAccount().size(); i++) composeReference(t, "Encounter", "account", element.getAccount().get(i), i);
    if (element.hasHospitalization())
        composeEncounterEncounterHospitalizationComponent(t, "Encounter", "hospitalization", element.getHospitalization(), -1);
    for (int i = 0; i < element.getLocation().size(); i++) composeEncounterEncounterLocationComponent(t, "Encounter", "location", element.getLocation().get(i), i);
    if (element.hasServiceProvider())
        composeReference(t, "Encounter", "serviceProvider", element.getServiceProvider(), -1);
    if (element.hasPartOf())
        composeReference(t, "Encounter", "partOf", element.getPartOf(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 60 with Account

use of org.hl7.fhir.dstu3.model.Account in project org.hl7.fhir.core by hapifhir.

the class GraphQLEngine method filter.

private List<Base> filter(Resource context, Property prop, String fieldName, List<Argument> arguments, List<Base> values, boolean extensionMode) throws FHIRException, EGraphQLException {
    List<Base> result = new ArrayList<Base>();
    if (values.size() > 0) {
        int count = Integer.MAX_VALUE;
        int offset = 0;
        StringBuilder fp = new StringBuilder();
        for (Argument arg : arguments) {
            List<Value> vl = resolveValues(arg);
            if ((vl.size() != 1))
                throw new EGraphQLException("Incorrect number of arguments");
            if (values.get(0).isPrimitive())
                throw new EGraphQLException("Attempt to use a filter (" + arg.getName() + ") on a primtive type (" + prop.getTypeCode() + ")");
            if ((arg.getName().equals("fhirpath")))
                fp.append(" and " + vl.get(0).toString());
            else if ((arg.getName().equals("_count")))
                count = Integer.valueOf(vl.get(0).toString());
            else if ((arg.getName().equals("_offset")))
                offset = Integer.valueOf(vl.get(0).toString());
            else {
                Property p = values.get(0).getNamedProperty(arg.getName());
                if (p == null)
                    throw new EGraphQLException("Attempt to use an unknown filter (" + arg.getName() + ") on a type (" + prop.getTypeCode() + ")");
                fp.append(" and " + arg.getName() + " = '" + vl.get(0).toString() + "'");
            }
        }
        // Account for situations where the GraphQL expression selected e.g.
        // effectiveDateTime but the field contains effectivePeriod
        String propName = prop.getName();
        List<Base> newValues = new ArrayList<>(values.size());
        for (Base value : values) {
            if (propName.endsWith("[x]")) {
                String propNameShortened = propName.substring(0, propName.length() - 3);
                if (fieldName.startsWith(propNameShortened) && fieldName.length() > propNameShortened.length()) {
                    if (!value.fhirType().equalsIgnoreCase(fieldName.substring(propNameShortened.length()))) {
                        continue;
                    }
                }
            }
            newValues.add(value);
        }
        int i = 0;
        int t = 0;
        if (fp.length() == 0)
            for (Base v : newValues) {
                if ((i >= offset) && passesExtensionMode(v, extensionMode)) {
                    result.add(v);
                    t++;
                    if (t >= count)
                        break;
                }
                i++;
            }
        else {
            ExpressionNode node = fpe.parse(fp.substring(5));
            for (Base v : newValues) {
                if ((i >= offset) && passesExtensionMode(v, extensionMode) && fpe.evaluateToBoolean(null, context, v, node)) {
                    result.add(v);
                    t++;
                    if (t >= count)
                        break;
                }
                i++;
            }
        }
    }
    return result;
}
Also used : Argument(org.hl7.fhir.utilities.graphql.Argument) ExpressionNode(org.hl7.fhir.r4b.model.ExpressionNode) ArrayList(java.util.ArrayList) StringValue(org.hl7.fhir.utilities.graphql.StringValue) ObjectValue(org.hl7.fhir.utilities.graphql.ObjectValue) VariableValue(org.hl7.fhir.utilities.graphql.VariableValue) Value(org.hl7.fhir.utilities.graphql.Value) NameValue(org.hl7.fhir.utilities.graphql.NameValue) NumberValue(org.hl7.fhir.utilities.graphql.NumberValue) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException) Property(org.hl7.fhir.r4b.model.Property) Base(org.hl7.fhir.r4b.model.Base)

Aggregations

Test (org.testng.annotations.Test)17 Patient (org.hl7.fhir.dstu3.model.Patient)10 ArrayList (java.util.ArrayList)8 Appointment (org.hl7.fhir.dstu3.model.Appointment)8 Account (org.sagebionetworks.bridge.models.accounts.Account)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)7 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)7 IOException (java.io.IOException)6 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)6 Account (com.google.api.services.adsense.v2.model.Account)5 JsonElement (com.google.gson.JsonElement)5 ProcedureRequest (org.hl7.fhir.dstu3.model.ProcedureRequest)5 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)5 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)5 Account (Model.Account)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 Account (model.Account)4 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)4