• Alex Lamora
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 0
    Replies
Right now I have a GET API which works, It goes out to our 3rd Party EMR and returns 20 or so records including first name, last name, dob, and Mailing address. Our salesforce system holds the name and DOB and what I am looking to do is take that JSON string and update the address fields of the Opportunities by matching the name and DOB to the correct opporutnity and updating the fields. Im not sure the best way to do this. Does anyone have any examples they can show me, I look all around and cant find exactly what im looking for. Pease help.
Im doing an HTML Post callout, I have an @invokeablemethod that ties to my @future which is where my callout is. Im using the SOQL to give field data in body, serializing json then sending over. It keeps sending over the information of the last opportunity not the current one which ping process builder. How do I select the current opportunity as the only record in the query. 
 
Map < string, object > Postdata =new Map<string, object>();
    Map < string, object > Document =new Map<string, object>();
    Map < String, object > patientdata = new Map<String, object>();    
    Map < string, object > insurancedata1 = new Map <string, Object>();	      
    list<object> insurancesdata = new list<object> {insurancedata1};

        for (Opportunity client: [SELECT id, first_name__c, Last_Name__c, Date_Of_Birth1__c, Client_SSN1__c, Gender__c, Client_Email__c, Client_Phone__c, Other_Pone__c, Mailing_City__c, Mailing_State__c, Mailing_Street__c, Mailing_Zip_Postal_Code__c, Insurance_Company1__c, Insurance_Phone_Number__c, Subscriber_Name__c, Subscriber_DOB__c, INS_ID__c, INS_Group__c, Client_Relationship_to_Primary__c, Primary_Policy_Holder_Employer__c from opportunity where Opportunity.id = :  ]){

        
        insurancedata1.put('subscriber_employer', client.Primary_Policy_Holder_Employer__c);
        insurancedata1.put('subscriber_relationship', client.Client_Relationship_to_Primary__c);
        insurancedata1.put('group_ID', client.INS_Group__c);
        insurancedata1.put('policy_no', client.INS_ID__c);
        insurancedata1.put('subscriber_DOB', client.Subscriber_DOB__c);
        insurancedata1.put('subscriber_last_name', client.Subscriber_Name__c);
        insurancedata1.put('insurance_phone', client.Insurance_Phone_Number__c);
        insurancedata1.put('insurance_company', client.Insurance_Company1__c);
        patientdata.put('insurances_attributes',insurancesdata);
        patientdata.put('address_zip', client.Mailing_Zip_Postal_Code__c);
        patientdata.put('address_street', client.Mailing_Street__c);
        patientdata.put('address_state', client.Mailing_State__c);
        patientdata.put('address_city', client.Mailing_City__c);
        patientdata.put('alternate_phone', client.Other_Pone__c);
        patientdata.put('phone', client.Client_Phone__c);
        patientdata.put('email', client.Client_Email__c);
        patientdata.put('gender', client.Gender__c);
        patientdata.put('ssn', client.Client_SSN1__c);
        patientdata.put('dob', client.Date_Of_Birth1__c);
        patientdata.put('last_name', client.Last_Name__c);
        patientdata.put('first_name', client.first_name__c);
        patientdata.put('sending_app_patient_id', client.Id);
        document.put('data', patientdata);
        document.put('sending_app_name', 'Salesforce');
        document.put('recipient_id', Kipuinstanceid);
        postdata.put('document', Document);
        
    }

 
public class AuthCallout {

    @InvocableMethod
    public static void basicAuthCallout(){
    
    HttpRequest req = new HttpRequest();
    Http http = new Http();
    HTTPResponse res = http.send(req);

     //Endpoint and Method
    req.setEndpoint('https://test.com/api/Patients');
    req.setMethod('POST');
       
    //key and secret to be given by test 
    String accessid = '';
	String secretkey = '';
    string instanceid = '';
    
    //required header values
    req.setheader('Accept','application/vnd.test+json;version=1');
    req.setHeader('Content-Type','application/json'); 
	String getTime = string.valueOf(Datetime.Now());
        
        
        		  
        		  Map<string,object> Postdata =new Map<string,object>();
        		  Map<string,object> Document =new Map<string,object>();
        		  Map<String, object> patientdata = new Map<String, object>();
        		  Map<string,object> insurancedata = new Map<string,Object>();
        for(opportunity client: [SELECT accountid, first_name__c, Last_Name__c, Date_Of_Birth1__c, Client_SSN1__c, Gender__c, Client_Email__c, Client_Phone__c, Other_Pone__c, Mailing_City__c, Mailing_State__c, Mailing_Street__c, Mailing_Zip_Postal_Code__c, Insurance_Company1__c, Insurance_Phone_Number__c, Subscriber_Name__c, Subscriber_DOB__c, INS_ID__c, INS_Group__c, Client_Relationship_to_Primary__c, Primary_Policy_Holder_Employer__c from opportunity]){
              
                  insurancedata.put('insurance_company',client.Insurance_Company1__c);
                  insurancedata.put('insurance_phone',client.Insurance_Phone_Number__c);
                  insurancedata.put('subscriber_last_name',client.Subscriber_Name__c);
                  insurancedata.put('subscriber_DOB',client.Subscriber_DOB__c);
                  insurancedata.put('policy_no',client.INS_ID__c);
                  insurancedata.put('group_ID',client.INS_Group__c);
                  insurancedata.put('subscriber_relationship',client.Client_Relationship_to_Primary__c);
                  insurancedata.put('subscriber_employer',client.Primary_Policy_Holder_Employer__c);
                  patientdata.put('sending_app_patient_id',client.AccountId);
                  patientdata.put('first_name',client.first_name__c);
                  patientdata.put('last_name',client.Last_Name__c);
                  patientdata.put('ssn',client.Client_SSN1__c);
                  patientdata.put('gender',client.Gender__c);
   				  patientdata.put('email',client.Client_Email__c);
                  patientdata.put('phone',client.Client_Phone__c);
                  patientdata.put('alternate_phone',client.Other_Pone__c);
                  patientdata.put('address_city',client.Mailing_City__c);
                  patientdata.put('address_state',client.Mailing_State__c);
                  patientdata.put('address_street',client.Mailing_Street__c);
                  patientdata.put('address_zip',client.Mailing_Zip_Postal_Code__c);
                  patientdata.put('dob',client.Date_Of_Birth1__c);
                  patientdata.put('insurance_attributes',insurancedata);
                  document.put('data',patientdata);
                  document.put('recipient_id',instanceid);
                  document.put('sending_app_name','Salesforce');
                  postdata.put('document', Document);
        }
        
       
                  //seralize json string
                  string postdataser= JSON.serialize(postdata);
   				  req.setBody(postdataser);
                  
        			//encode MD5
        			String requestInput = postdataser;
					Blob requestBlob = Blob.valueOf(requestInput);
					Blob hash = Crypto.generateDigest('MD5', requestBlob);
					String requestSignature = EncodingUtil.convertToHex(hash);
      				req.setHeader('Content-MD5', requestsignature);
        
					//canonical string
       				 string canonicalstring =  'application/json' +'\n'+ requestsignature +'\n'+ '/api/patients' +'\n'+ getTime;
            		 string canonicalsecretkey = canonicalstring + secretkey;
        
            		//encode signature
            		Blob cankeyBlob = Blob.valueOf(canonicalsecretkey);
            		Blob hashSHA1 = Crypto.generateDigest('SHA1',cankeyblob);
        			String hashBase64SHA1 = EncodingUtil.base64encode (hashSHA1);
        
        
        			//authorization header
        			req.setHeader('Authorization', 'APIAUTH' + accessid +':'+ hashBase64SHA1);
        
 	   HTTPResponse res = http.send(req);
                    
                    }
                    }
This error occurs when I change the stage which invokes process builder flow to trigger the POST.

Please advise.
 
I am about to begin working on an API between SFDC(CRM) and KIPU(EMR) 
KIPU's API only allows for POST and GET, so everything I do will need to be within Salesforce.
I want all client information to POST to a new file in KIPU when stage changes to Admit. Thats fine and dandy, but I want to have custom fields/stages in SF update when the client admits and discharges in KIPU.
What would be the best way to go about automating GET from Kipu.
*side note* it could be weeks in between when a client admits and discharges.

Thank You