Skip to content

Instantly share code, notes, and snippets.

@nyyshaa
Last active July 4, 2018 09:51
Show Gist options
  • Save nyyshaa/6b1c71c1f21b5ccbef5c682ab07b126b to your computer and use it in GitHub Desktop.
Save nyyshaa/6b1c71c1f21b5ccbef5c682ab07b126b to your computer and use it in GitHub Desktop.
Service Provider Portal
site apiNotebookVersion title
1.2.87
Service Provider Portal

Create Service Provider Portal client. This client will be used to explore the API

API.createClient("spPortal", "https://hiis-staging.allied.mv/docs/api.raml", {
  proxy: false
});

AUTHORIZATION

Authorization is done using the OAUTH2 standards

Client Credentials for this tutorial:

  • client_id: 0kkUNy2ZP1SBBkyN0osmv4UiKnREOsUOlG2bZff9
  • client_secret: ZCZjSBRffAfU5DOAGGDOmqJPbNtQrAOsY16nECf6

Since authentication is done using client credentials AlliedInsureUsername header needs to be passed with every request. This header contains the logged in user's username.

API.authenticate(spPortal, 'oauth_2_0');

FRONT DESK

API Call 1: Get beneficiary details using the Allied Health card number.

$beneficiary = spPortal.portal.beneficiary.cardNumber('AH000003').get(null, { headers: { "AlliedInsureUsername": "sp_adk_user_1" } });
$policyId = $beneficiary.body.data.policy.id;
$beneficiaryId = $beneficiary.body.data.id;
$ipCoinsurance = $beneficiary.body.data.coinsurances[2].inpatient_coinsurance;
$opCoinsurance = $beneficiary.body.data.coinsurances[2].outpatient_coinsurance;

Create a new case for the beneficiary. For this mock run we will assume that the cover_type is outpatient

  1. Get the cover type's corresponding plan_limit_id using $beneficiary
  2. Make the call to create case using the plan_limit_id as cover_type.
$plan_limit_id = $beneficiary.body.data.planLimits[1].plan_limit_id;

API Call 2: Create case

$case = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.post({
  "cover_type": $plan_limit_id },
  {headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json"}}
);                                                                   

To get the the beneficiary's case details:

$caseId = $case.body.data.id;

API Call 3: Get case details by caseId

spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId).get(
  null, {
    headers: { "AlliedInsureUsername": "sp_adk_user_1" }
    }
 );

API Call 4: Get all existing cases by beneficiary

spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.get(
  null, {
    headers: { "AlliedInsureUsername": "sp_adk_user_1" } 
    }
 	);

API Call 5: Get all available services for the service provider.

spPortal.portal['service-provider'].serviceProviderId(1).service.get(
  null, {
    headers: { "AlliedInsureUsername": "sp_adk_user_1" } 
    }
 );

Add transaction to a case. First transaction would typically be added by the front desk personnel while creating a memo under the case.

API Call 6: Insert Transaction

$transaction = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').
		case.caseId($caseId).transaction.post(
       { "type": "cashless",
         "memo_number": "ADK-2",
       }, 
       { headers:
         { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json" }
       }
    );
$transactionId = $transaction.body.data.id;

Add breakdowns to the created transaction

API Call 7: Insert Breakdown

$bill_amount = 100;
$payable_amount = (parseFloat($opCoinsurance) / 100) * $bill_amount;
$claim_amount = $bill_amount - $payable_amount;
// $breakdown = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId).
// 		transaction.transactionId($transactionId).breakdown.post(
//       { "bill_amount": 100,
//         "quantity": "1",
//         "limit_id": $plan_limit_id,
//         "order_id": 1,
//         "order_type": "service",
//         "exchange_rate" : 1
//       },
//       {
//         	headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json"}
//       }
//     );

API Call 8: Bulk insert breakdowns

Instead of calling the API for each breakdown seperately (as demonstrated in API Call 7), we can send the breakdowns in an array.

$breakdowns = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId).
			transaction.transactionId($transactionId).breakdown.bulk.post(
  	{"breakdowns": [
      { "bill_amount" : 100,
        "claim_amount" : 100 - ((parseFloat($opCoinsurance) / 100) * $bill_amount),
        "foreign_currency_id" : 1,
        "exchange_rate" : 15.48,
        "quantity" : 1,
        "order_id" : 1,
       	"order_type" : "service" },
      { "bill_amount" : 150,
        "claim_amount" : 150 - ((parseFloat($opCoinsurance) / 100) * $bill_amount),
        "foreign_currency_id" : 1,
        "exchange_rate" : 15.48,
        "quantity" : 1,
        "order_id" : 1369,
       	"order_type" : "service" }
      ]
    }, 
    {
        headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json"}
    }
  );

In the above post request, order_id is the id of the required service and order_type would be 'service' as the breakdown is being added for a service.

At this point; a new case is created with a transaction which inturn has a single breakdown.

DOCTOR

When the patient/beneficiary visits the doctor use;

  • 'API Call 1' to fetch the beneficiary details by card number, and
  • 'API Call 3' to get the case details.

The doctor would then proceed to add a prescription under the retrieved case.

API Call 9: Add prescription to case

$prescription = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').
	case.caseId($caseId).prescription.post(
    { "code": "ADK-PRES-111",
      "findings": "NA",
      "co": "Some text here",
      "oe": "blah blah",
      "followup": "After one week",
      "referred": "NA",
      "vs_temperature": "37",
      "vs_pr": "95",
      "vs_rr": "77",
      "vs_bp": "137/85",
      "vs_weight": "85",
      "vs_height": "165"
    },
    {headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json" }}
  );
$prescriptionId = $prescription.body.data.id;

API Call 10: To get all icd codes

spPortal.portal['icd-code'].get(null, {headers: { "AlliedInsureUsername": "sp_adk_user_1" }});

API Call 11: Add diagnosis to prescription

spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId)
	.prescription.prescriptionId($prescriptionId)['icd-code'].icdCodeId(1).put(
    { "type": "provisional",
      "remarks": "some remark here" 
    },
    {headers: { "AlliedInsureUsername": "sp_adk_user_1" }}
  );

API Call 12: Get all medicine

spPortal.portal.medicine.get(null, {headers: { "AlliedInsureUsername": "sp_adk_user_1" }});

API Call 13: Add medicines to prescriptions

spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId).
	prescription.prescriptionId($prescriptionId).medicine.medicineId(1).put(
    { "instructions": "1-1-1" },
    {headers: { "AlliedInsureUsername": "sp_adk_user_1" }}
  ); 

API Call 14: Get all services

spPortal.portal.service.get(null, {headers: { "AlliedInsureUsername": "sp_adk_user_1" }});

API Call 15: Attach investigations (Services) to prescription

spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003').case.caseId($caseId)
	.prescription.prescriptionId($prescriptionId).investigation.serviceId(1).put(
  	null, 
  	{headers: { "AlliedInsureUsername": "sp_adk_user_1" }}
 );

Once the doctor consultation is over, the beneficiary would then proceed to the pharmacy.

PHARMACY

$presNumber = $prescription.body.data.number;

API Call 16: Fetch prescription by prescription number.

$medPrescription = spPortal.portal.prescription.prescriptionNumber(encodeURIComponent($presNumber)).
	get(null, {headers: { "AlliedInsureUsername": "sp_adk_user_1" }});

Note: if the medicine specified in the prescription is unavailable at the service provider or if its not in the service provider's available medicine list, the service provider would not be able to add a transaction breakdown for that medicine.

'available_medicine' property of the medicine object specifies whether the medicine is avaible or not. i.e: if available_medicine : true then the medicine is available if available_medicine : false then the medicine is not available and cannot be transactioned.

$caseId = $medPrescription.body.data.case_id;

If the medicine brand name is not specified by the doctor, the service provider can get a list of all medicines which fall under the prescribed generic medicine. Example: If the doctor has prescribed 'paracetemol' and not specified which brand of paracetemol, than a list of all medicines which has parametemol would be returned.

The same route will also be used to fetch the price of the prescribed medicine.

API Call 17: Get service provider's available medicines list. This list contains the price as stored in the Allied database.

$medicines = spPortal.portal.prescription.prescriptionNumber(encodeURIComponent($presNumber))
	.medicine.medicineId(1)['available-medicines'].get(null, {headers: { "AlliedInsureUsername": "sp_adk_user_1" }});
$price = $medicines.body.data[0].pivot.unit_price;

To add transacctions and breakdowns we use API Call 6, API Call 7, and API Call 8.

Note that while adding a medicine as a breakdown order_id would be medicine->id and order_type would be "medicine"

$transaction = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003')
	.case.caseId($caseId).transaction.post(
   { "type": "cashless",
      "memo_number": "ADK-111",
      "service_provider_id": "1"
    }, 
    {headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json" }}
  );
$transactionId = $transaction.body.data.id;
$breakdown = spPortal.portal.policy.policyId($policyId).beneficiary.cardNumber('AH000003')
	.case.caseId($caseId).transaction.transactionId($transactionId).breakdown.post( 
    { "bill_amount": $price,
      "foreign_amount": $price,
      "exchange_rate": "1",
      "quantity": "1",
      "foreign_currency_id": "1",
      "limit_id": $plan_limit_id,
      "order_id": 1,
      "order_type": "medicine"
    },
    {headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json" }}
  );

ADMIN

This function highlights the API calls used to fetch a list of transaction ids and send them to Allied Claims Department for processing.

API Call 18: Fetch a list of uninvoiced transaction ids based on cover_type (Inpatient/ Outpatient)

  • Inpatient transactions are grouped by Allied Health card number.
  • Outpatient transactions are grouped based on service provider's invoice frequency and invoice limits.
$tids = spPortal.portal['service-provider'].serviceProviderId(1).transaction.group
	.coverType("inpatient").get(null, { headers: { "AlliedInsureUsername": "sp_adk_user_1" }});

API Call 19: Send Invoice to Allied Claims Department

spPortal.portal['service-provider'].serviceProviderId(1).invoice.post(
  { "inv_start_date" : $tids.body[0].first_date,
   	"inv_end_date" : $tids.body[0].last_date,
    "inv_amount" : 1666,
   	"number" : "XYZ1235",
    "tid" : $tids.body[0].transactions
  },
  {headers: { "AlliedInsureUsername": "sp_adk_user_1", "Content-Type": "application/json" }}
  );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment