def test3(): """Franchised, Series, Seasoned, with 1 OTO""" p = Producer(name='BBC Productions') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = SeriesEpisode(name="Scandal in Belgravia") ep1.save() se = Season(name="Season 2", ordinal="2") se.save() s = Series(name='Sherlock') s.orgs = [p, d] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = ep1 sa.season = se sa.save() # get the previous f = session.query(Franchise).filter(Franchise.name=="Masterpiece").all()[0] f.serieses.append(s) f.save()
def test4(): """Franchised series with 1 oto""" p = Producer(name='Ken Burns') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = SeriesEpisode(name="The Scripture of Nature (1851-1890)") ep1.save() se = Season(name='Season 2009', ordinal=2009) se.save() s = Series(name='The National Parks') s.orgs = [p, d] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = ep1 sa.season = se sa.save() f = Franchise(name='Ken Burns') f.serieses = [s] f.save()
def test_tag(): p = Producer(name='BBC Productions') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = SeriesEpisode(name="Wolf Hall Ep 1") ep1.save() se = Season(name="1", ordinal="1") se.save() s = Series(name='Wolf Hall') s.orgs = [p, d] s.save() s2 = Series(name='Wolf Hall Subseries') s2.orgs = [p, d] s2.save() #sept = SeriesEpisodeTag(series=s, episode=s2, tag='subseries') #sept.save() sept = SeriesRelationTag(parent=s, child=s2, tag='subseries') sept.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = ep1 sa.season = se sa.save()
def test1(): """Franchised, Series, 1 Season, 1 Ep""" p = Producer(name='BBC Productions') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = SeriesEpisode(name="Wolf Hall Ep 1") ep1.save() se = Season(name="1", ordinal="1") se.save() s = Series(name='Wolf Hall') s.orgs = [p, d] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = ep1 sa.season = se sa.save() f = Franchise(name='Masterpiece') f.serieses.append(s) f.save()
def test1112(): """Series with 1 ep (in a season) and 1 OTO (seasonless)""" p = Producer(name='Universal') p.save() d = Distributor(name='PBS Distribution') d.save() se = Season(name='3', ordinal=3) se.save() e1 = SeriesEpisode(name="Go West Young Monkey") e1.seasons = [se,] e1.save() e2 = OneTimeOnlyEpisode(name="Curious George XMAS") e2.save() s = Series(name="Curious George") s.onetimeonlys = [e2,] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = e1 sa.save()
def test7(): """Series with Subseries and 1 Ep""" p = Producer(name='WGBH Productions') p.save() d = Distributor(name='PBS Distribution') d.save() se = Season(name='17', ordinal=17) se.save() e1 = SeriesEpisode(name="Antiques Roadshow Seattle, Ep1") e1.seasons = [se,] e1.save() sss = Season(name='1', ordinal=1) sss.save() ss1 = SubSeries(name="Antiques Roadshow in Seattle") ss1.save() s = Series(name="Antiques Roadshow") s.subseries = [ss1] s.seasons = [se,] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = e1 sa.save() sa2 = SeasonAssociation(season=sss) sa2.series = ss1 sa2.episode = e1 sa2.save()
def test6(): """Series with OTO""" p = Producer(name='WGBH Productions') p.save() d = Distributor(name='PBS Distribution') d.save() se = Season(name='38', ordinal=38) se.save() e1 = OneTimeOnlyEpisode(name="Surviving Ebola") e1.seasons = [se,] e1.save() # get the previous s = session.query(Series).filter(Series.name=="NOVA").all()[0] s.seasons = [se,] s.episodes = [e1,] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = e1 sa.save()
def add_producer(): data = request.get_json() try: producer = Producer(name=data["name"]) db.session.add(producer) db.session.commit() return jsonify(producer.to_dict()) except KeyError: response = jsonify({"error": "Bad request", "missing field": "name"}) response.status_code = 400 return response
def test10(): """Series with OTO""" p = Producer(name='CAPC') p.save() d = Distributor(name='PBS Distribution') d.save() e1 = OneTimeOnlyEpisode(name="A Capitol Fourth 2014") e1.save() s = Series(name="A Capitol Fourth") s.onetimeonlys = [e1,] s.save()
def test2(): """Franchised, Series, NO Season, 1 OTO""" p = Producer(name='BBC Productions') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = OneTimeOnlyEpisode(name="Downton Abbey 2014 X-mas Special") ep1.save() s = Series(name='Downton Abbey') s.onetimeonlys = [ep1] s.orgs = [p, d] s.save() # get the previous f = session.query(Franchise).filter(Franchise.name=="Masterpiece").all()[0] f.serieses.append(s) f.save()
def test8(): """Series with EP""" p = Producer(name='WETA') p.save() d = Distributor(name='PBS Distribution') d.save() ep1 = SeriesEpisode(name="Monday, July 15th, 2014") ep1.save() s = Series(name='PBS NewsHour') s.orgs = [p, d] s.save() se = Season(name='29', ordinal=29) se.save() sa2 = SeasonAssociation(season=se) sa2.series = s sa2.episode = ep1 sa2.save()
def test9(): """WEIRD ONE: Series and Subseries of different seasons sharing the same Ep""" p = Producer(name='WETA Productions') p.save() d = Distributor(name='PBS Distribution') d.save() se = Season(name='41', ordinal=41) se.save() se2 = Season(name='2012', ordinal=2012) se2.save() e1 = SeriesEpisode(name="Democratic National Convention September 5, 2015 Part 1") e1.save() ss1 = SubSeries(name="Elections") #ss1.episodes = [e1,] ss1.seasons = [se2] ss1.save() s = session.query(Series).filter(Series.name=="PBS NewsHour").all()[0] #s = Series(name="PBS NewsHour") s.subseries = [ss1] s.seasons = [se,] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = e1 sa.save() sa2 = SeasonAssociation(season=se2) sa2.series = ss1 sa2.episode = e1 sa2.save()
def test5(): """Series with Ep in one season AND Subseries with Ep in a different season""" p = Producer(name='WGBH Productions') p.save() d = Distributor(name='PBS Distribution') d.save() se = Season(name='38', ordinal=38) se.save() se1 = Season(name='1', ordinal=1) se1.save() e1 = SeriesEpisode(name="Making Stuff Similar Episode") e1.save() e2 = SeriesEpisode(name="Making Stuff Similar Episode2") e2.save() ss1 = SubSeries(name="Making Stuff") ss1.save() s = Series(name="NOVA") s.subseries = [ss1] s.save() sa = SeasonAssociation(season=se) sa.series = s sa.episode = e1 sa.save() sa2 = SeasonAssociation(season=se1) sa2.series = ss1 sa2.episode = e2 sa2.save()
def create_contract(): try: treatment_start = parser.parse(request.json['treatment_start']).date() # Find or create insurer insurer_name = request.json['insurer'] match = db.session.query(Insurer) \ .filter(Insurer.name == insurer_name) \ .first() if match: insurer = match else: insurer = Insurer(name=insurer_name) # Find or create manufacturer manufacturer_name = request.json['manufacturer'] match = db.session.query(Producer) \ .filter(Producer.name == manufacturer_name) \ .first() if match: manufacturer = match else: manufacturer = Producer(name=manufacturer_name) # Find or create patient patient_surname = request.json['patient_surname'] patient_name = request.json['patient_name'] patient_birthday = parser.parse( request.json['patient_birthday']).date() patient_cancer_stage = CancerStage( request.json['patient_cancer_stage']) # Check if patient is young enough for enrollment patient_age = get_age(patient_birthday) if patient_age >= 55: return Response( f"{{'Error':'Patient does not fullfill enrollment criteria: Age {patient_age} >= 55'}}", status=400, mimetype='application/json') match = db.session.query(Patient) \ .filter(Patient.name == patient_name) \ .filter(Patient.surname == patient_surname) \ .filter(Patient.birthday == patient_birthday) \ .first() if match: patient = match else: patient = Patient(name=patient_name, surname=patient_surname, birthday=patient_birthday, cancer_stage=patient_cancer_stage) # Find or create product configuration product_brand = request.json['product_brand'] product_name = request.json['product_name'] product_units = request.json['product_units'] product_baseprice = request.json['product_baseprice'] match = db.session.query(Product) \ .filter(Product.brand == product_brand) \ .filter(Product.product == product_name) \ .filter(Product.units == product_units) \ .filter(Product.baseprice == product_baseprice) \ .first() if match: product = match else: product = Product(brand=product_brand, product=product_name, units=product_units, baseprice=product_baseprice) # Find or create payable amounts configuration os = request.json['os'] no_os = request.json['no_os'] pfs = request.json['pfs'] no_pfs = request.json['no_pfs'] match = db.session.query(PayableAmount) \ .filter(PayableAmount.os_after_12_months == os) \ .filter(PayableAmount.no_os_after_12_months == no_os) \ .filter(PayableAmount.pfs_after_9_months == pfs) \ .filter(PayableAmount.no_pfs_after_9_months == no_pfs) \ .first() if match: payable_amounts = match else: payable_amounts = PayableAmount(os_after_12_months=os, no_os_after_12_months=no_os, pfs_after_9_months=pfs, no_pfs_after_9_months=no_pfs) new_contract = Contract(insurer=insurer, producer=manufacturer, product=product, patient=patient, status='ongoing', treatment_start=treatment_start, payable_amounts=payable_amounts) # Check if contract is already finished -> simulation purposes payable = check_contract_status(new_contract.to_dict(), []) if not payable == -1: # No events could have been generated at contract creation -> bill for 9 months PFS new_contract.amount = 9 * (product_baseprice * payable) new_contract.status = 'finished' db.session.add(new_contract) db.session.commit() return Response('{"status": "ok"}', status=200) except: return Response('{"status": "error"}', status=500)
def fill_db(): # Add example products product_conf_1 = Product(brand="ABC", product="vial 10mg/ml", units=10, baseprice=1000) product_conf_2 = Product(brand="ABC", product="vial 10mg/ml", units=20, baseprice=1800) product_conf_3 = Product(brand="ABC", product="vial 10mg/ml", units=30, baseprice=2500) product_conf_4 = Product(brand="ABC", product="vial 20mg/ml", units=10, baseprice=1000) product_conf_5 = Product(brand="ABC", product="vial 20mg/ml", units=20, baseprice=2700) product_conf_6 = Product(brand="ABC", product="vial 20mg/ml", units=30, baseprice=4100) products = [ product_conf_1, product_conf_2, product_conf_3, product_conf_4, product_conf_5, product_conf_6 ] for product in products: db.session.add(product) # Add patient event types patient_event_type_1 = PatientEventType(event_name="progressed") patient_event_type_2 = PatientEventType(event_name="dead") db.session.add(patient_event_type_1) db.session.add(patient_event_type_2) # Add default payable amount configuration payable_amount_conf = PayableAmount(os_after_12_months=0.75, no_os_after_12_months=0.35, pfs_after_9_months=0.85, no_pfs_after_9_months=0.40) db.session.add(payable_amount_conf) # Add manufacturers manufacturer_1 = Producer(name="Roche") manufacturer_2 = Producer(name="Novartis") manufacturer_3 = Producer(name="Orion") db.session.add(manufacturer_1) db.session.add(manufacturer_2) db.session.add(manufacturer_3) # Add insurers insurer_1 = Insurer(name="Helsana") insurer_2 = Insurer(name="Swica") insurer_3 = Insurer(name="OEKK") db.session.add(insurer_1) db.session.add(insurer_2) db.session.add(insurer_3) # Add patients patient_1 = Patient(surname="Muster", name="Max", birthday=parser.parse('1990-01-01'), cancer_stage=CancerStage.two) patient_2 = Patient(surname="Muller", name="Jan", birthday=parser.parse('1998-01-01'), cancer_stage=CancerStage.zero) patient_3 = Patient(surname="Zindel", name="Alice", birthday=parser.parse('1985-06-01'), cancer_stage=CancerStage.three) # Add example contracts contract_1 = Contract(producer=manufacturer_1, insurer=insurer_1, product=product_conf_1, payable_amounts=payable_amount_conf, patient=patient_1, treatment_start=parser.parse('2020-08-01'), status="ongoing") contract_2 = Contract(producer=manufacturer_2, insurer=insurer_2, product=product_conf_1, payable_amounts=payable_amount_conf, patient=patient_2, treatment_start=parser.parse('2020-04-30'), status="ongoing") contract_3 = Contract(producer=manufacturer_1, insurer=insurer_1, product=product_conf_1, payable_amounts=payable_amount_conf, patient=patient_3, treatment_start=parser.parse('2020-11-30'), status="ongoing") db.session.add(contract_1) db.session.add(contract_2) db.session.add(contract_3) db.session.commit()