https://imgur.com/a/nJ4mFbs
I am new to using API's. The only thing I can currently do is search for a diagnostic report via ID by using the code:
DiagnosticReport dR = client.read().resource(DiagnosticReport.class).withId("3281").execute();
But how can I search to see if a subject with reference: "Patient/3250" exists, and if it exists, how can I return the string "Encounter/3267" from:
"context": { "reference": "Encounter/3267"
You can try this with JSON :-
JSONObject jsonObject = new JSONObject(JSON);
JSONObject getFirst = jsonObject.getJSONObject("Context");
Object level2 = getFirst.get("reference");
if(level2.equals("Patient/3250")){
System.out.println("True");
}
else{
System.out.println("False");
}
you can do the first part with a query. I'm not sure about the HAPI syntax for it, so I'll show it in a URL. Your query is
GET [base]/DiagnosticReport/3281
The query you want for searching to see if a subject with reference "Patient/3250" exists would be
GET [base]/DiagnosticReport?subject:Patient.id=3250
The docs for cognito user pools can be found here:
http://docs.aws.amazon.com/cognito/latest/developerguide/how-to-manage-user-accounts.html
In this they do not say whether you can query users by the automatically generated sub attribute, which is a uuid. It explicitly says you can't search for users by custom attributes, but sub/uuid is not a custom attribute. Weirdly though, in the list of searchable attributes sub/uuid is not one of them. Surely though you can look up users by their UUID, how would this be done though??
You know, I have used COgnito but never needed to look up via sub (or other params other than the username). I looked into it because surely you can, but it is not very clear (like a lot of their documentation). Here is what I saw that you could try... hope it helps man.
// the imported ListUsersResult is...
import com.amazonaws.services.cognitoidp.model.ListUsersRequest;
import com.amazonaws.services.cognitoidp.model.ListUsersResult;
// class var
protected final AWSCognitoIdentityProviderClient identityUserPoolProviderClient;
// omitted stuff...
// initialize the Cognito Provider client. This is used to talk to the user pool
identityUserPoolProviderClient = new AWSCognitoIdentityProviderClient(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)); // creds are loaded via variables that are supplied to my program dynamically
identityUserPoolProviderClient.setRegion(RegionUtils.getRegion(USER_POOL_REGION)); // var loaded
// ...some code omitted
ListUsersRequest listUsersRequest = new ListUsersRequest();
listUsersRequest.withUserPoolId(USER_POOL_ID); // id of the userpool, look this up in Cognito console
listUsersRequest.withFilter("sub=xyz"); // i THINK this is how the Filter works... the documentation is terribad
// get the results
ListUsersResult result = identityUserPoolProviderClient.listUsers(listUsersRequest);
List<UserType> userTypeList = result.getUsers();
// loop through them
for (UserType userType : userTypeList) {
List<AttributeType> attributeList = userType.getAttributes();
for (AttributeType attribute : attributeList) {
String attName = attribute.getName();
String attValue = attribute.getValue();
System.out.println(attName + ": " + attValue);
}
}
If you have the username you could get the user like this
// build the request
AdminGetUserRequest idRequest = new AdminGetUserRequest();
idRequest.withUserPoolId(USER_POOL_ID);
idRequest.withUsername(username);
// call cognito for the result
AdminGetUserResult result = identityUserPoolProviderClient.adminGetUser(idRequest);
// loop through results
Good day,
I am using Parse Push Notification, and below are my difficulties:
In brief, I would like to "merge" these two conditions:
query.whereEqualTo("Gender", userLookingGender);
pushQuery.whereEqualTo("the gender column of the ParseQuery", the user gender of the ParseQuery column);
In other words, I would like to send out a message to the user that falls within that gender. The gender column along with the genders are found in the parse query called "User".
Update:
userLookingGender is the following:
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
If you need any clarification let me know.
Update 2:
I use one condition, gender, to make easier to understand. Now Imagine if I had multiple condition, and is trying to send a push message only the recipient who fulfill all of the below criteria, and where upon button click it would take them to particular activity page.
ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
.getObjectId());
// users with Gender = currentUser.Looking_Gender
query.whereEqualTo("Gender", userLookingGender);
// users with Looking_Gender = currentUser.Gender
query.whereEqualTo("Looking_Gender", userGender);
query.setLimit(1) ;
ParseGeoPoint point = ParseUser.getCurrentUser().getParseGeoPoint("location");
query.whereWithinKilometers("location", point, mMax_Distance.doubleValue());
query.whereEqualTo("ActivityName", activityName);
query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
query.whereLessThanOrEqualTo("UserAge", maximumAge);
Update 3:
Android Code
ParseCloud.callFunctionInBackground("sendPushToNearbyAndMatching", new HashMap<String, Object>(), new FunctionCallback<String>() {
public void done(String result, ParseException e) {
if (e == null) {
// success
}
}
});
Parse Cloud JavaScript code (found in cloud/main.js)
The owner column in this case is users
// Use Parse.Cloud.define to define as many cloud functions as you want.
// For example:
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
Parse.Cloud.define("sendPushToNearbyAndMatching", function(request, response) {
Parse.Cloud.useMasterKey();
// the authenticated user on the device calling this function
var user = request.user;
// the complex query matching users
var query = new Parse.Query(Parse.User);
query.whereNotEqualTo("objectId", user.id);
// users with Gender = currentUser.Looking_Gender
query.equalTo("Gender", user.get("Gender"));
// users with Looking_Gender = currentUser.Gender
query.equalTo("Looking_Gender", user.get("Looking_Gender"));
query.equalTo("ActivityName", user.get("ActivityName"));
query.greaterThanOrEqualTo("UserAge", user.get("Minimum_Age"));
query.lessThanOrEqualTo("UserAge", user.get("Maximum_Age"));
query.limit(1);
query.each(function(user) {
// sendPushNotification is added in next code section
return sendPushNotification(user);
}).then(function() {
response.success("success!");
}, function(err) {
response.error(err);
});
});
var sendPushNotification = function(user) {
var query = new Parse.Query(Parse.Installation);
query.equalTo('users', user);
return Parse.Push.send({
where : query, // send to installations matching query
expiration_interval : 600, // optional - expires after 10 minutes
data : {
alert: "App says hello!",
}
})
}
Now that I have a bit more insight I think I'm ready with an answer:
I do Push from Cloud Code, and there the query matches against Installation objects, which is why having the values there as well would be useful.
It looks like you are sending directly from the app, so I would suggest creating a channel for each gender: https://parse.com/docs/push_guide#sending-channels/Android
Then you just need to:
String userLookingGender = ParseUser.getCurrentUser().getString(
"Looking_Gender");
ParsePush push = new ParsePush();
push.setChannel(userLookingGender);
push.setMessage("Your message");
push.sendInBackground();
Update:
Ok. the multiple queries indeed make matters more complicated.
I think you would have to move on to Cloud Code to perform such an advanced query push (which is by the way recommended for security reasons).
Cloud Code guide: https://parse.com/docs/cloud_code_guide
Embrasing the fact that users can have multiple devices, you need to be able to fetch all the installations associated with a user. To do this I would suggest saving a pointer to User on each installation. You can do this as part of the first login of your app.
Assuming you have a, say, owner column in your installation pointing to the respective User owning the device, then you can do something like this in Cloud Code:
Parse.Cloud.define("sendPushToNearbyAndMatching", function(request, response) {
Parse.Cloud.useMasterKey();
// the authenticated user on the device calling this function
var user = request.user;
// the complex query matching users
var query = new Parse.Query(Parse.User);
query.whereNotEqualTo("objectId", user.id);
// users with Gender = currentUser.Looking_Gender
query.equalTo("Gender", user.get("Gender"));
// users with Looking_Gender = currentUser.Gender
query.equalTo("Looking_Gender", user.get("Looking_Gender"));
query.limit(1);
... etc
// execute the query
// i am using each just to show an convenient way to iterate the results
// instead of setting limit(1) consider executing the query using first() instead
// android SDK has a getFirstInBackground() as well
query.each(function(user) {
// sendPushNotification is added in next code section
return sendPushNotification(user);
}).then(function() {
response.success("success!");
}, function(err) {
response.error(err);
});
});
About querying User in javascript: https://parse.com/docs/js_guide#users-querying
How to call this Cloud function from Android: https://parse.com/docs/android_guide#cloudfunctions
Now it is time to send out the notifications to the devices owned by the user:
var sendPushNotification = function(user) {
var promise = new Parse.Promise();
var query = new Parse.Query(Parse.Installation);
query.equalTo('owner', user);
query.count().then(function(count) {
console.log("sending push to " + count + " devices");
Parse.Push.send({
where : query, // send to installations matching query
expiration_interval : 600, // optional - expires after 10 minutes
data : {
alert: "App says hello!",
}
}).then(function() {
// success
console.log("push success");
promise.resolve();
}, function(error) {
console.error(error.message);
promise.reject(error);
});
});
return promise;
}
For more advanced pushes (if you for instance want to receive a broadcast to handle some data) see: https://parse.com/docs/push_guide#sending-queries/JavaScript
Also, if you decide to fiddle with Cloud Code and thereby javascript, I would highly recommend having a look at how promises work. This makes your life so much easier when handling asynchronous calls, for instance when issuing queries: https://parse.com/docs/js_guide#promises
This is all a lot of information and probably a lot to take in all at once if it is new to you, but I think it will be all worth it, I know it was for me.
Can any body tell me how i can create a google contact under the group like i have one group by name family under this i want to add the contact. Now i am able to create contact but its going under others following code i am using
ContactEntry contact = new ContactEntry();
contact.setTitle(new PlainTextConstruct("chetan"));
contact.setContent(new PlainTextConstruct("sharma"));
Email primaryMail = new Email();
primaryMail.setAddress("newcontact#gmail.com");
primaryMail.setRel("http://schemas.google.com/g/2005#home");
primaryMail.setPrimary(true);
contact.addEmailAddress(primaryMail);
ExtendedProperty favouriteFlower = new ExtendedProperty();
favouriteFlower.setName("favourite flower");
favouriteFlower.setValue("daisy");
contact.addExtendedProperty(favouriteFlower);
//URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/defaults/full");
contact = service.insert(feedUrl, contact);
GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/defaults/base/39eb8f59897bac4d");
//groupMembershipInfo
contact.addGroupMembershipInfo(groupMembershipInfo);
I see that you are inserting the contact before adding the groupMembershipInfo. If you want to add the group membership details to the contact, move this line "contact = service.insert(feedUrl, contact);" as a last line of the code.
You can refer to this page for more details.
Hope that helps!
You can execute below method and get Atom id for different groups in your account like My Contacts, Family etc.
public static void printAllGroups(ContactsService myService)
throws ServiceException, IOException {
// Request the feed
URL feedUrl = new URL("https://www.google.com/m8/feeds/groups/ankit.ab2502#gmail.com/full");
ContactGroupFeed resultFeed = myService.getFeed(feedUrl, ContactGroupFeed.class);
for (ContactGroupEntry groupEntry : resultFeed.getEntries()) {
System.out.println("Atom Id: " + groupEntry.getId());
System.out.println("Group Name: " + groupEntry.getTitle().getPlainText());
}
}
Output of this method for Family group will be like:
Atom Id: http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e
Use this url to add contact to a Family group
GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo(false, "http://www.google.com/m8/feeds/groups/UR_EMAIL_ID/base/e");
contact.addGroupMembershipInfo(groupMembershipInfo);
i need to connect to a rest service to get the user id by using a token.
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
client = WebClient.create(properties.getProperty(URL), providers);
client = client.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE);
client.path(PATH + token);
Response response = client.get();
The entity of response have this format:
{"message":"Token is valid","userId":1}
To get the userId, i have:
response.readEntity(AuthResponse.class).userId;
It is possible to take only the userId without creating an class with that format ? (without AuthResponse.class)
You can try to read your JSON as Map, for example: response.readEntity(Map.class).get("userId")
Please refer to this page for more information.