Search in sources :

Example 61 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) 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)

Example 62 with Account

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

the class RdfParser method composeEpisodeOfCare.

protected void composeEpisodeOfCare(Complex parent, String parentType, String name, EpisodeOfCare element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "EpisodeOfCare", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "EpisodeOfCare", "identifier", element.getIdentifier().get(i), i);
    if (element.hasStatusElement())
        composeEnum(t, "EpisodeOfCare", "status", element.getStatusElement(), -1);
    for (int i = 0; i < element.getStatusHistory().size(); i++) composeEpisodeOfCareEpisodeOfCareStatusHistoryComponent(t, "EpisodeOfCare", "statusHistory", element.getStatusHistory().get(i), i);
    for (int i = 0; i < element.getType().size(); i++) composeCodeableConcept(t, "EpisodeOfCare", "type", element.getType().get(i), i);
    for (int i = 0; i < element.getDiagnosis().size(); i++) composeEpisodeOfCareDiagnosisComponent(t, "EpisodeOfCare", "diagnosis", element.getDiagnosis().get(i), i);
    if (element.hasPatient())
        composeReference(t, "EpisodeOfCare", "patient", element.getPatient(), -1);
    if (element.hasManagingOrganization())
        composeReference(t, "EpisodeOfCare", "managingOrganization", element.getManagingOrganization(), -1);
    if (element.hasPeriod())
        composePeriod(t, "EpisodeOfCare", "period", element.getPeriod(), -1);
    for (int i = 0; i < element.getReferralRequest().size(); i++) composeReference(t, "EpisodeOfCare", "referralRequest", element.getReferralRequest().get(i), i);
    if (element.hasCareManager())
        composeReference(t, "EpisodeOfCare", "careManager", element.getCareManager(), -1);
    for (int i = 0; i < element.getTeam().size(); i++) composeReference(t, "EpisodeOfCare", "team", element.getTeam().get(i), i);
    for (int i = 0; i < element.getAccount().size(); i++) composeReference(t, "EpisodeOfCare", "account", element.getAccount().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 63 with Account

use of org.hl7.fhir.dstu3.model.Account in project googleads-adsense-examples by googleads.

the class GetAccountTree method run.

/**
 * Runs this sample.
 *
 * @param adsense AdSense service object on which to run the requests.
 * @param accountId the ID for the account to be used.
 * @throws Exception
 */
public static void run(Adsense adsense, String accountId) throws Exception {
    System.out.println("=================================================================");
    System.out.printf("Displaying AdSense account tree for %s\n", accountId);
    System.out.println("=================================================================");
    // Retrieve account.
    Account account = adsense.accounts().get(accountId).execute();
    displayTree(adsense, account, 0);
    System.out.println();
}
Also used : Account(com.google.api.services.adsense.v2.model.Account)

Example 64 with Account

use of org.hl7.fhir.dstu3.model.Account in project googleads-adsense-examples by googleads.

the class GetAccountTree method displayTree.

/**
 * Auxiliary method to recursively fetch child accounts, displaying them in a tree.
 * @param parentAccount the account to be print a sub-tree for.
 * @param level the depth at which the top account exists in the tree.
 */
private static void displayTree(Adsense adsense, Account parentAccount, int level) throws Exception {
    for (int i = 0; i < level; i++) {
        System.out.print("  ");
    }
    System.out.printf("Account with ID \"%s\" and name \"%s\" was found.\n", parentAccount.getName(), parentAccount.getDisplayName());
    ListChildAccountsResponse response = adsense.accounts().listChildAccounts(parentAccount.getName()).execute();
    List<Account> subAccounts = response.getAccounts();
    if (subAccounts != null && !subAccounts.isEmpty()) {
        for (Account subAccount : subAccounts) {
            displayTree(adsense, subAccount, level + 1);
        }
    }
}
Also used : Account(com.google.api.services.adsense.v2.model.Account) ListChildAccountsResponse(com.google.api.services.adsense.v2.model.ListChildAccountsResponse)

Example 65 with Account

use of org.hl7.fhir.dstu3.model.Account in project googleads-adsense-examples by googleads.

the class AdSenseSample method chooseAccount.

/**
 * Lists all AdSense accounts the user has access to, and prompts them to choose one.
 *
 * @param accounts the list of accounts to choose from.
 * @return the ID of the chosen account.
 */
public static String chooseAccount(List<Account> accounts) {
    String accountId = null;
    if (accounts == null && !accounts.isEmpty()) {
        System.out.println("No AdSense accounts found. Exiting.");
        System.exit(-1);
    } else if (accounts.size() == 1) {
        accountId = accounts.get(0).getName();
        System.out.printf("Only one account found (%s), using it.\n", accountId);
    } else {
        System.out.println("Please choose one of the following accounts:");
        for (int i = 0; i < accounts.size(); i++) {
            Account account = accounts.get(i);
            System.out.printf("%d. %s (%s)\n", i + 1, account.getDisplayName(), account.getName());
        }
        System.out.printf("> ");
        Scanner scan = new Scanner(System.in);
        accountId = accounts.get(scan.nextInt() - 1).getName();
        System.out.printf("Account %s chosen, resuming.\n", accountId);
    }
    System.out.println();
    return accountId;
}
Also used : Account(com.google.api.services.adsense.v2.model.Account) Scanner(java.util.Scanner)

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