Skip to content

Instantly share code, notes, and snippets.

@machty
Last active January 16, 2018 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machty/67ca047db9daa51c720a634cc8dee86e to your computer and use it in GitHub Desktop.
Save machty/67ca047db9daa51c720a634cc8dee86e to your computer and use it in GitHub Desktop.
Insurance
import Ember from 'ember';
const { computed } = Ember;
function f(v) {
return parseFloat(v.toString());
}
export default Ember.Component.extend({
tagName: 'tr',
bd: computed('p.premium', 'p.deductible', 'p.negotiatedRate',
'p.myRate', 'sessionsPerYear',
'p.copay', 'p.coinsurance', 'p.oop',
function() {
let premium = this.fget('p.premium');
let annualPremium = premium * 12;
// compute how much until deductible met.
// so in this period
let ded = this.fget('p.deductible');
let negRate = this.fget('p.negotiatedRate');
let myRate = this.fget('p.myRate');
// what happens when i have $5 left
// on deductible and I have another session.
// for now, assume that you pay full amount,
// and THEN next session it kicks in.
let sessionsPerYear = this.fget('sessionsPerYear');
let numDedSess = Math.min(Math.ceil(ded / negRate), sessionsPerYear);
let dedMet = numDedSess * negRate;
let numCoSess = sessionsPerYear - numDedSess;
let remainingPms = Math.max(0, sessionsPerYear - numDedSess);
let copay = this.fget('p.copay');
let coins = this.fget('p.coinsurance');
let copayTotal = copay * remainingPms;
let coinsTotal = coins * negRate * remainingPms;
let coTotal = copayTotal + coinsTotal;
let oop = dedMet + coTotal;
let oopm = this.fget('p.oop');
let overshoot = dedMet + coTotal - oopm;
let uncoveredRate = myRate - negRate;
let uncTotal = uncoveredRate * sessionsPerYear; // remainingPms * uncoveredRate;
let addls = Math.min(oopm, dedMet + coTotal);
let minMedExp = annualPremium + addls + uncTotal;
let maxMedExp = annualPremium + oopm + uncTotal;
let annTotal;
if (minMedExp == maxMedExp) {
annTotal = minMedExp.toFixed(0);
} else {
annTotal = `${minMedExp.toFixed(0)}-${maxMedExp.toFixed(0)}`;
}
return {
coTotal,
dedMet,
numDedSess,
numCoSess,
oop,
uncTotal,
overshoot,
annualPremium,
annTotal
};
// return f(this.get('p.premium'))*12;
}),
fget(key) {
return f(this.get(key));
},
});
import Ember from 'ember';
let negotiatedRate = 175;
let myRate = 175;
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
sessionsPerYear: 95,
plans: [
{
name: 'bronze',
premium: 729.59,
deductible: 5500,
oop: 6550,
coinsurance: 0.5,
copay: 0,
negotiatedRate,
myRate,
},
{
name: 'silver',
premium: 882.73,
deductible: 2000,
oop: 6750,
coinsurance: 0,
copay: 50,
negotiatedRate,
myRate,
},
{
name: 'gold',
premium: 1057.86,
deductible: 600,
oop: 4000,
coinsurance: 0,
copay: 40,
negotiatedRate,
myRate,
},
{
name: 'platinum',
premium: 1262.04,
deductible: 0,
oop: 2000,
coinsurance: 0,
copay: 35,
negotiatedRate,
myRate,
},
],
actions: {
dup(plan) {
let newPlan = Object.assign({}, plan);
this.get('plans').pushObject(newPlan);
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
input {
width: 30px;
}
<h1>Insurance is fun</h1>
<p>
TODO: add more columns
to progress towards something
more useful and calculate
final price.
Months til deductible met
is a good one.
</p>
<br>
Sessions/yr:
{{input value=sessionsPerYear}}
<br>
<table style="width: 100%">
<thead>
<tr>
<td>
Actions
</td>
<td>
Name
</td>
<td>
Premium
</td>
<td>
Ann. Prem
</td>
<td>
Ded.
</td>
<td>
CoIns
</td>
<td>
CoPay
</td>
<td>
HisRate
</td>
<td>
I Pay
</td>
<td>
#ded
</td>
<td>
#co
</td>
<td>
DedMet
</td>
<td>
CoTot
</td>
<td>
OOP
</td>
<td>
OOPM
</td>
<td>
UncTotal
</td>
<td>
Over
</td>
<td>
AnnTotal
</td>
</tr>
</thead>
<tbody>
{{#each plans as |p|}}
{{x-plan p=p
dup=(action 'dup' p)
sessionsPerYear=sessionsPerYear}}
{{/each}}
</tbody>
</table>
<td>
<button onclick={{dup}}>
Dup
</button>
</td>
<td>
{{p.name}}
</td>
<td>
{{p.premium}}
</td>
<td>
{{bd.annualPremium}}
</td>
<td>
{{p.deductible}}
</td>
<td>
{{p.coinsurance}}
</td>
<td>
{{p.copay}}
</td>
<td>
{{input value=p.negotiatedRate}}
</td>
<td>
{{input value=p.myRate}}
</td>
<td>
{{bd.numDedSess}}
</td>
<td>
{{bd.numCoSess}}
</td>
<td>
{{bd.dedMet}}
</td>
<td>
{{bd.coTotal}}
</td>
<td>
{{bd.oop}}
</td>
<td>
{{p.oop}}
</td>
<td>
{{bd.uncTotal}}
</td>
<td>
{{bd.overshoot}}
</td>
<td>
{{bd.annTotal}}
</td>
{
"version": "0.13.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment