Skip to content

Commit

Permalink
Additional unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jawalonoski authored and hadleynet committed May 24, 2024
1 parent b249772 commit 77398b2
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/mitre/synthea/world/agents/Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ public static List<Provider> getProviderList() {
return new ArrayList<Provider>(providerByUuid.values());
}

private void merge(Provider other) {
void merge(Provider other) {
if (this.uuid == null) {
this.uuid = other.uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class PayerAdjustmentFixed implements IPayerAdjustment, Serializable {
private static final long serialVersionUID = -1515831606680338099L;

/** Fixed adjustment rate. */
private double rate;
double rate;

/**
* Create a new fixed payer adjustment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PayerAdjustmentRandom implements IPayerAdjustment, Serializable {
private static final long serialVersionUID = -5292509643177122361L;

/** Maximum adjustment rate. */
private double rate;
double rate;

/**
* Create a new random payer adjustment.
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/mitre/synthea/world/agents/ProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,19 @@ public void testAllFiles() throws Exception {
public void testNPICreation() {
Assert.assertEquals("1234567893", Provider.toNPI(123_456_789L));
}

@Test
public void testProviderMerge() {
Provider.loadProviders(city, providerRandom);
Person person = new Person(0L);
city.assignPoint(person, city.randomCityName(person));
Provider provider = Provider.findService(person, EncounterType.OUTPATIENT, 0);
Assert.assertNotNull(provider);
Provider blank = new Provider();
blank.uuid = null;
blank.merge(provider);
Assert.assertEquals(provider.uuid, blank.uuid);
Assert.assertEquals(provider.name, blank.name);
Assert.assertEquals(provider.servicesProvided, blank.servicesProvided);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.junit.AfterClass;
Expand All @@ -23,11 +24,16 @@
import org.mitre.synthea.world.agents.behaviors.planfinder.PlanFinderBestRates;
import org.mitre.synthea.world.agents.behaviors.planfinder.PlanFinderPriority;
import org.mitre.synthea.world.agents.behaviors.planfinder.PlanFinderRandom;
import org.mitre.synthea.world.concepts.HealthRecord;
import org.mitre.synthea.world.concepts.HealthRecord.Code;
import org.mitre.synthea.world.concepts.HealthRecord.Encounter;
import org.mitre.synthea.world.concepts.HealthRecord.EncounterType;
import org.mitre.synthea.world.concepts.healthinsurance.InsurancePlan;
import org.mitre.synthea.world.geography.Location;

public class PlanFinderTest {

private static final Code code = new Code("system", "code", "display");
private Person person;
private Location location;

Expand Down Expand Up @@ -126,6 +132,30 @@ public void onePayerBestRate() {
assertFalse(payer.isNoInsurance());
}

@Test
public void onePayerBestRateMultipleRecordsAndEncounters() {
person.hasMultipleRecords = true;
person.records = new ConcurrentHashMap<String, HealthRecord>();
person.records.put("provider", person.record);
person.coverage.setPlanToNoInsurance(0L);
for (long time = 0L; time <= 3000L; time += 1000L) {
Encounter encounter = person.record.encounterStart(time, EncounterType.EMERGENCY);
encounter.codes.add(code);
person.record.encounterEnd((time + 500L), EncounterType.EMERGENCY);
}

Config.set("generate.payers.selection_behavior", "best_rate");
PayerManager.clear();
PayerManager.loadPayers(location);
PlanFinderBestRates finder = new PlanFinderBestRates();
List<Payer> privatePayers = PayerManager.getAllPayers().stream().filter(payer -> payer
.getOwnership().equals(PayerManager.PRIVATE_OWNERSHIP)).collect(Collectors.toList());
Payer payer = finder.find(PayerManager.getActivePlans(privatePayers, 0L),
person, null, 0L).getPayer();
assertNotNull(payer);
assertFalse(payer.isNoInsurance());
}

@Test
public void planFinderPriority() {
long time = Utilities.convertCalendarYearsToTime(2023);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.mitre.synthea.world.agents.behaviors.payeradjustment;

import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;

import org.junit.Test;
import org.mitre.synthea.world.agents.PayerManager;
import org.mitre.synthea.world.agents.Person;
import org.mitre.synthea.world.concepts.Claim;
import org.mitre.synthea.world.concepts.HealthRecord.Code;
import org.mitre.synthea.world.concepts.HealthRecord.Encounter;
import org.mitre.synthea.world.concepts.HealthRecord.EncounterType;
import org.mockito.Mockito;

public class PayerAdjustmentTest {

private static final Code code = new Code("system", "code", "display");

@Test
public void testPayerAdjustmentNone() {
PayerManager.loadNoInsurance();
Person person = new Person(0L);
person.attributes.put(Person.BIRTHDATE, 0L);
person.coverage.setPlanToNoInsurance(0L);
Encounter encounter = person.record.encounterStart(0L, EncounterType.EMERGENCY);
encounter.codes.add(code);
Claim claim = new Claim(encounter, person);
claim.assignCosts();

IPayerAdjustment adjustment = new PayerAdjustmentNone();
BigDecimal result = adjustment.adjustClaim(claim.mainEntry, person);
assertTrue("Adjustment should be zero.", result.equals(Claim.ZERO_CENTS));
}

@Test
public void testPayerAdjustmentFixed() {
PayerManager.loadNoInsurance();
Person person = new Person(0L);
person.attributes.put(Person.BIRTHDATE, 0L);
person.coverage.setPlanToNoInsurance(0L);
Encounter encounter = person.record.encounterStart(0L, EncounterType.EMERGENCY);
encounter.codes.add(code);
Claim claim = new Claim(encounter, person);
claim.assignCosts();

IPayerAdjustment adjustment = new PayerAdjustmentFixed(0.5);
BigDecimal result = adjustment.adjustClaim(claim.mainEntry, person);
assertTrue("Adjustment should be non-zero", result.compareTo(claim.mainEntry.cost) < 0);

adjustment = new PayerAdjustmentFixed(1.0);
result = adjustment.adjustClaim(claim.mainEntry, person);
assertTrue("Adjustment should be total", result.equals(claim.mainEntry.cost));

adjustment = new PayerAdjustmentFixed(0.0);
result = adjustment.adjustClaim(claim.mainEntry, person);
assertTrue("Adjustment should be zero", result.equals(Claim.ZERO_CENTS));
}

@Test
public void testPayerAdjustmentRandom() {
PayerManager.loadNoInsurance();
Person person = new Person(0L);
person.attributes.put(Person.BIRTHDATE, 0L);
person.coverage.setPlanToNoInsurance(0L);
Encounter encounter = person.record.encounterStart(0L, EncounterType.EMERGENCY);
encounter.codes.add(code);
Claim claim = new Claim(encounter, person);
claim.assignCosts();

Person shadow = Mockito.mock(Person.class);
Mockito.when(shadow.rand(0.0, 0.5)).thenReturn(0.5);
Mockito.when(shadow.randBoolean()).thenReturn(true);

IPayerAdjustment adjustment = new PayerAdjustmentRandom(0.5);
BigDecimal result = adjustment.adjustClaim(claim.mainEntry, shadow);
assertTrue("Adjustment should be non-zero", result.compareTo(claim.mainEntry.cost) < 0);

Mockito.when(shadow.randBoolean()).thenReturn(false);
result = adjustment.adjustClaim(claim.mainEntry, shadow);
assertTrue("Adjustment should be zero", result.equals(Claim.ZERO_CENTS));
}

@Test
public void testRateBounds() {
// Below zero
PayerAdjustmentFixed adjustment = new PayerAdjustmentFixed(-1);
assertTrue("Below zero rate should be zero.", (adjustment.rate == 0));

// Above one
adjustment = new PayerAdjustmentFixed(2);
assertTrue("Rates above one should be one.", (adjustment.rate == 1));

// Below zero
PayerAdjustmentRandom randomAdjustment = new PayerAdjustmentRandom(-1);
assertTrue("Below zero rate should be zero.", (randomAdjustment.rate == 0));

// Above one
randomAdjustment = new PayerAdjustmentRandom(2);
assertTrue("Rates above one should be one.", (randomAdjustment.rate == 1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.mitre.synthea.world.concepts;

import org.junit.Assert;
import org.junit.Test;

public class ClinicianSpecialtyTest {

@Test
public void testSpecialtiesMap() {
String[] specialties = ClinicianSpecialty.getSpecialties();
Assert.assertNotNull("Clinician Specialties should not be null.", specialties);
Assert.assertTrue("Clinician Specialities should not be empty.", specialties.length > 0);

for (String specialty : specialties) {
String code = ClinicianSpecialty.getCMSProviderSpecialtyCode(specialty);
Assert.assertNotNull("CMS Specialty code should not be null.", code);
String msg = specialty + " => " + code;
Assert.assertTrue("CMS Speciality code should be length 2: " + msg, code.length() == 2);
}
}
}

0 comments on commit 77398b2

Please sign in to comment.