use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project synthea by synthetichealth.
the class FhirR4 method explanationOfBenefit.
/**
* Create an explanation of benefit resource for each claim, detailing insurance
* information.
*
* @param personEntry Entry for the person
* @param bundle The Bundle to add to
* @param encounterEntry The current Encounter
* @param claimEntry the Claim object
* @param person the person the health record belongs to
* @param encounter the current Encounter as an object
* @return the added entry
*/
private static BundleEntryComponent explanationOfBenefit(BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Person person, BundleEntryComponent claimEntry, Encounter encounter) {
ExplanationOfBenefit eob = new ExplanationOfBenefit();
eob.setStatus(org.hl7.fhir.r4.model.ExplanationOfBenefit.ExplanationOfBenefitStatus.ACTIVE);
eob.setType(new CodeableConcept().addCoding(new Coding().setSystem("http://terminology.hl7.org/CodeSystem/claim-type").setCode("professional").setDisplay("Professional")));
eob.setUse(Use.CLAIM);
eob.setOutcome(RemittanceOutcome.COMPLETE);
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
// according to CMS guidelines claims have 12 months to be
// billed, so we set the billable period to 1 year after
// services have ended (the encounter ends).
Calendar cal = Calendar.getInstance();
cal.setTime(encounterResource.getPeriod().getEnd());
cal.add(Calendar.YEAR, 1);
Period billablePeriod = new Period().setStart(encounterResource.getPeriod().getEnd()).setEnd(cal.getTime());
eob.setBillablePeriod(billablePeriod);
// cost is hardcoded to be USD in claim so this should be fine as well
Money totalCost = new Money();
totalCost.setCurrency("USD");
totalCost.setValue(encounter.claim.getTotalClaimCost());
TotalComponent total = eob.addTotal();
total.setAmount(totalCost);
Code submitted = new Code("http://terminology.hl7.org/CodeSystem/adjudication", "submitted", "Submitted Amount");
total.setCategory(mapCodeToCodeableConcept(submitted, "http://terminology.hl7.org/CodeSystem/adjudication"));
// Set References
eob.setPatient(new Reference(personEntry.getFullUrl()));
if (USE_US_CORE_IG) {
eob.setFacility(encounterResource.getLocationFirstRep().getLocation());
}
ServiceRequest referral = (ServiceRequest) new ServiceRequest().setStatus(ServiceRequest.ServiceRequestStatus.COMPLETED).setIntent(ServiceRequest.ServiceRequestIntent.ORDER).setSubject(new Reference(personEntry.getFullUrl())).setId("referral");
CodeableConcept primaryCareRole = new CodeableConcept().addCoding(new Coding().setCode("primary").setSystem("http://terminology.hl7.org/CodeSystem/claimcareteamrole").setDisplay("Primary Care Practitioner"));
Reference providerReference = new Reference().setDisplay("Unknown");
if (encounter.clinician != null) {
String practitionerFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirNpiSearchUrl(encounter.clinician) : findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
providerReference = new Reference(practitionerFullUrl);
}
} else if (encounter.provider != null) {
String providerUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Location", encounter.provider.getResourceLocationID()) : findProviderUrl(encounter.provider, bundle);
if (providerUrl != null) {
providerReference = new Reference(providerUrl);
}
}
eob.setProvider(providerReference);
eob.addCareTeam(new ExplanationOfBenefit.CareTeamComponent().setSequence(1).setProvider(providerReference).setRole(primaryCareRole));
referral.setRequester(providerReference);
referral.addPerformer(providerReference);
eob.addContained(referral);
eob.setReferral(new Reference().setReference("#referral"));
// Get the insurance info at the time that the encounter occurred.
Payer payer = encounter.claim.payer;
Coverage coverage = new Coverage();
coverage.setId("coverage");
coverage.setStatus(CoverageStatus.ACTIVE);
coverage.setType(new CodeableConcept().setText(payer.getName()));
coverage.setBeneficiary(new Reference(personEntry.getFullUrl()));
coverage.addPayor(new Reference().setDisplay(payer.getName()));
eob.addContained(coverage);
ExplanationOfBenefit.InsuranceComponent insuranceComponent = new ExplanationOfBenefit.InsuranceComponent();
insuranceComponent.setFocal(true);
insuranceComponent.setCoverage(new Reference("#coverage").setDisplay(payer.getName()));
eob.addInsurance(insuranceComponent);
eob.setInsurer(new Reference().setDisplay(payer.getName()));
org.hl7.fhir.r4.model.Claim claim = (org.hl7.fhir.r4.model.Claim) claimEntry.getResource();
eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/variables/clm_id").setValue(claim.getId());
// Hardcoded group id
eob.addIdentifier().setSystem("https://bluebutton.cms.gov/resources/identifier/claim-group").setValue("99999999999");
eob.setClaim(new Reference().setReference(claimEntry.getFullUrl()));
eob.setCreated(encounterResource.getPeriod().getEnd());
eob.setType(claim.getType());
List<ExplanationOfBenefit.DiagnosisComponent> eobDiag = new ArrayList<>();
for (org.hl7.fhir.r4.model.Claim.DiagnosisComponent claimDiagnosis : claim.getDiagnosis()) {
ExplanationOfBenefit.DiagnosisComponent diagnosisComponent = new ExplanationOfBenefit.DiagnosisComponent();
diagnosisComponent.setDiagnosis(claimDiagnosis.getDiagnosis());
diagnosisComponent.getType().add(new CodeableConcept().addCoding(new Coding().setCode("principal").setSystem("http://terminology.hl7.org/CodeSystem/ex-diagnosistype")));
diagnosisComponent.setSequence(claimDiagnosis.getSequence());
diagnosisComponent.setPackageCode(claimDiagnosis.getPackageCode());
eobDiag.add(diagnosisComponent);
}
eob.setDiagnosis(eobDiag);
List<ExplanationOfBenefit.ProcedureComponent> eobProc = new ArrayList<>();
for (ProcedureComponent proc : claim.getProcedure()) {
ExplanationOfBenefit.ProcedureComponent p = new ExplanationOfBenefit.ProcedureComponent();
p.setDate(proc.getDate());
p.setSequence(proc.getSequence());
p.setProcedure(proc.getProcedure());
}
eob.setProcedure(eobProc);
List<ExplanationOfBenefit.ItemComponent> eobItem = new ArrayList<>();
double totalPayment = 0;
// Get all the items info from the claim
for (ItemComponent item : claim.getItem()) {
ExplanationOfBenefit.ItemComponent itemComponent = new ExplanationOfBenefit.ItemComponent();
itemComponent.setSequence(item.getSequence());
itemComponent.setQuantity(item.getQuantity());
itemComponent.setUnitPrice(item.getUnitPrice());
itemComponent.setCareTeamSequence(item.getCareTeamSequence());
itemComponent.setDiagnosisSequence(item.getDiagnosisSequence());
itemComponent.setInformationSequence(item.getInformationSequence());
itemComponent.setNet(item.getNet());
itemComponent.setEncounter(item.getEncounter());
itemComponent.setServiced(encounterResource.getPeriod());
itemComponent.setCategory(new CodeableConcept().addCoding(new Coding().setSystem("https://bluebutton.cms.gov/resources/variables/line_cms_type_srvc_cd").setCode("1").setDisplay("Medical care")));
itemComponent.setProductOrService(item.getProductOrService());
// Location of service, can use switch statement based on
// encounter type
String code;
String display;
CodeableConcept location = new CodeableConcept();
EncounterType encounterType = EncounterType.fromString(encounter.type);
switch(encounterType) {
case AMBULATORY:
code = "21";
display = "Inpatient Hospital";
break;
case EMERGENCY:
code = "20";
display = "Urgent Care Facility";
break;
case INPATIENT:
code = "21";
display = "Inpatient Hospital";
break;
case URGENTCARE:
code = "20";
display = "Urgent Care Facility";
break;
case WELLNESS:
code = "19";
display = "Off Campus-Outpatient Hospital";
break;
default:
code = "21";
display = "Inpatient Hospital";
}
location.addCoding().setCode(code).setSystem("http://terminology.hl7.org/CodeSystem/ex-serviceplace").setDisplay(display);
itemComponent.setLocation(location);
// Adjudication
if (item.hasNet()) {
// Assume that the patient has already paid deductible and
// has 20/80 coinsurance
ExplanationOfBenefit.AdjudicationComponent coinsuranceAmount = new ExplanationOfBenefit.AdjudicationComponent();
coinsuranceAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_coinsrnc_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Coinsurance Amount"));
coinsuranceAmount.getAmount().setValue(// 20% coinsurance
0.2 * item.getNet().getValue().doubleValue()).setCurrency("USD");
ExplanationOfBenefit.AdjudicationComponent lineProviderAmount = new ExplanationOfBenefit.AdjudicationComponent();
lineProviderAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prvdr_pmt_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Provider Payment Amount"));
lineProviderAmount.getAmount().setValue(0.8 * item.getNet().getValue().doubleValue()).setCurrency("USD");
// assume the allowed and submitted amounts are the same for now
ExplanationOfBenefit.AdjudicationComponent submittedAmount = new ExplanationOfBenefit.AdjudicationComponent();
submittedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_sbmtd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Submitted Charge Amount"));
submittedAmount.getAmount().setValue(item.getNet().getValue()).setCurrency("USD");
ExplanationOfBenefit.AdjudicationComponent allowedAmount = new ExplanationOfBenefit.AdjudicationComponent();
allowedAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_alowd_chrg_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Allowed Charge Amount"));
allowedAmount.getAmount().setValue(item.getNet().getValue()).setCurrency("USD");
ExplanationOfBenefit.AdjudicationComponent indicatorCode = new ExplanationOfBenefit.AdjudicationComponent();
indicatorCode.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_prcsg_ind_cd").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Processing Indicator Code"));
// assume deductible is 0
ExplanationOfBenefit.AdjudicationComponent deductibleAmount = new ExplanationOfBenefit.AdjudicationComponent();
deductibleAmount.getCategory().getCoding().add(new Coding().setCode("https://bluebutton.cms.gov/resources/variables/line_bene_ptb_ddctbl_amt").setSystem("https://bluebutton.cms.gov/resources/codesystem/adjudication").setDisplay("Line Beneficiary Part B Deductible Amount"));
deductibleAmount.getAmount().setValue(0).setCurrency("USD");
List<ExplanationOfBenefit.AdjudicationComponent> adjudicationComponents = new ArrayList<>();
adjudicationComponents.add(coinsuranceAmount);
adjudicationComponents.add(lineProviderAmount);
adjudicationComponents.add(submittedAmount);
adjudicationComponents.add(allowedAmount);
adjudicationComponents.add(deductibleAmount);
adjudicationComponents.add(indicatorCode);
itemComponent.setAdjudication(adjudicationComponents);
// the total payment is what the insurance ends up paying
totalPayment += 0.8 * item.getNet().getValue().doubleValue();
}
eobItem.add(itemComponent);
}
eob.setItem(eobItem);
// This will throw a validation error no matter what. The
// payment section is required, and it requires a value.
// The validator will complain that if there is a value, the payment
// needs a code, but it will also complain if there is a code.
// There is no way to resolve this error.
Money payment = new Money();
payment.setValue(totalPayment).setCurrency("USD");
eob.setPayment(new ExplanationOfBenefit.PaymentComponent().setAmount(payment));
return newEntry(person, bundle, eob);
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project cqf-ruler by DBCG.
the class CareGapsProvider method careGapsReport.
/**
* Implements the <a href=
* "http://build.fhir.org/ig/HL7/davinci-deqm/OperationDefinition-care-gaps.html">$care-gaps</a>
* operation found in the
* <a href="http://build.fhir.org/ig/HL7/davinci-deqm/index.html">Da Vinci DEQM
* FHIR Implementation Guide</a> that overrides the <a href=
* "http://build.fhir.org/operation-measure-care-gaps.html">$care-gaps</a>
* operation found in the
* <a href="http://hl7.org/fhir/R4/clinicalreasoning-module.html">FHIR Clinical
* Reasoning Module</a>.
*
* The operation calculates measures describing gaps in care. For more details,
* reference the <a href=
* "http://build.fhir.org/ig/HL7/davinci-deqm/gaps-in-care-reporting.html">Gaps
* in Care Reporting</a> section of the
* <a href="http://build.fhir.org/ig/HL7/davinci-deqm/index.html">Da Vinci DEQM
* FHIR Implementation Guide</a>.
*
* A Parameters resource that includes zero to many document bundles that
* include Care Gap Measure Reports will be returned.
*
* Usage:
* URL: [base]/Measure/$care-gaps
*
* @param theRequestDetails generally auto-populated by the HAPI server
* framework.
* @param periodStart the start of the gaps through period
* @param periodEnd the end of the gaps through period
* @param topic the category of the measures that is of interest for
* the care gaps report
* @param subject a reference to either a Patient or Group for which
* the gaps in care report(s) will be generated
* @param practitioner a reference to a Practitioner for which the gaps in
* care report(s) will be generated
* @param organization a reference to an Organization for which the gaps in
* care report(s) will be generated
* @param status the status code of gaps in care reports that will be
* included in the result
* @param measureId the id of Measure(s) for which the gaps in care
* report(s) will be calculated
* @param measureIdentifier the identifier of Measure(s) for which the gaps in
* care report(s) will be calculated
* @param measureUrl the canonical URL of Measure(s) for which the gaps
* in care report(s) will be calculated
* @param program the program that a provider (either clinician or
* clinical organization) participates in
* @return Parameters of bundles of Care Gap Measure Reports
*/
// warning for greater than 7 parameters
@SuppressWarnings("squid:S00107")
@Description(shortDefinition = "$care-gaps", value = "Implements the <a href=\"http://build.fhir.org/ig/HL7/davinci-deqm/OperationDefinition-care-gaps.html\">$care-gaps</a> operation found in the <a href=\"http://build.fhir.org/ig/HL7/davinci-deqm/index.html\">Da Vinci DEQM FHIR Implementation Guide</a> which is an extension of the <a href=\"http://build.fhir.org/operation-measure-care-gaps.html\">$care-gaps</a> operation found in the <a href=\"http://hl7.org/fhir/R4/clinicalreasoning-module.html\">FHIR Clinical Reasoning Module</a>.")
@Operation(name = "$care-gaps", idempotent = true, type = Measure.class)
public Parameters careGapsReport(RequestDetails theRequestDetails, @OperationParam(name = "periodStart") String periodStart, @OperationParam(name = "periodEnd") String periodEnd, @OperationParam(name = "topic") List<String> topic, @OperationParam(name = "subject") String subject, @OperationParam(name = "practitioner") String practitioner, @OperationParam(name = "organization") String organization, @OperationParam(name = "status") List<String> status, @OperationParam(name = "measureId") List<String> measureId, @OperationParam(name = "measureIdentifier") List<String> measureIdentifier, @OperationParam(name = "measureUrl") List<CanonicalType> measureUrl, @OperationParam(name = "program") List<String> program) {
validateConfiguration(theRequestDetails);
validateParameters(theRequestDetails);
// TODO: filter by topic.
// TODO: filter by program.
List<Measure> measures = ensureMeasures(getMeasures(measureId, measureIdentifier, measureUrl, theRequestDetails));
List<Patient> patients;
if (!Strings.isNullOrEmpty(subject)) {
patients = getPatientListFromSubject(subject);
} else {
// TODO: implement non subject parameters (practitioner and organization)
throw new NotImplementedException("Non subject parameters have not been implemented.");
}
Parameters result = initializeResult();
(patients).forEach(patient -> {
Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails, periodStart, periodEnd, patient, status, measures, organization);
if (patientParameter != null) {
result.addParameter(patientParameter);
}
});
return result;
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project integration-adaptor-111 by nhsconnect.
the class ConditionMapper method mapCondition.
public Condition mapCondition(POCDMT000002UK01ClinicalDocument1 clinicalDocument, Encounter encounter, List<QuestionnaireResponse> questionnaireResponseList) {
Condition condition = new Condition();
condition.setIdElement(resourceUtil.newRandomUuid());
condition.setClinicalStatus(Condition.ConditionClinicalStatus.ACTIVE).setVerificationStatus(Condition.ConditionVerificationStatus.UNKNOWN).setSubject(encounter.getSubject()).setContext(resourceUtil.createReference(encounter));
if (questionnaireResponseList != null) {
condition.setEvidence(evidenceOf(questionnaireResponseList));
}
addConditionReason(clinicalDocument, condition);
if (clinicalDocument.getComponent().isSetStructuredBody()) {
for (POCDMT000002UK01Component3 component3 : clinicalDocument.getComponent().getStructuredBody().getComponentArray()) {
POCDMT000002UK01Section section = component3.getSection();
for (POCDMT000002UK01Entry entry : section.getEntryArray()) {
if (entry.isSetEncounter()) {
POCDMT000002UK01Encounter itkEncounter = entry.getEncounter();
if (itkEncounter.isSetEffectiveTime()) {
condition.setAssertedDateElement(DateUtil.parse(itkEncounter.getEffectiveTime().getValue()));
}
if (itkEncounter.isSetText()) {
condition.addCategory(new CodeableConcept().setText(nodeUtil.getAllText(itkEncounter.getText().getDomNode())));
}
}
}
for (POCDMT000002UK01Component5 component : section.getComponentArray()) {
if (component.getSection() != null) {
if (component.getSection().isSetLanguageCode()) {
if (component.getSection().getLanguageCode().isSetCode()) {
condition.setLanguage(component.getSection().getLanguageCode().getCode());
}
}
}
}
}
}
return condition;
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project integration-adaptor-111 by nhsconnect.
the class CompositionMapper method addSectionChildren.
private void addSectionChildren(SectionComponent component, POCDMT000002UK01Section section) {
for (POCDMT000002UK01Component5 component5 : section.getComponentArray()) {
POCDMT000002UK01Section innerSection = component5.getSection();
SectionComponent innerCompositionSection = getSectionText(innerSection);
component.addSection(innerCompositionSection);
if (isNotEmpty(innerSection.getComponentArray())) {
addSectionChildren(innerCompositionSection, innerSection);
}
}
}
use of org.hl7.fhir.utilities.xml.SchematronWriter.Section in project integration-adaptor-111 by nhsconnect.
the class ObservationMapperTest method setUp.
@BeforeEach
public void setUp() {
POCDMT000002UK01Component2 component2 = mock(POCDMT000002UK01Component2.class);
when(component2.isSetStructuredBody()).thenReturn(true);
POCDMT000002UK01StructuredBody structuredBody = mock(POCDMT000002UK01StructuredBody.class);
POCDMT000002UK01Component3 component3 = mock(POCDMT000002UK01Component3.class);
POCDMT000002UK01Section section = mock(POCDMT000002UK01Section.class);
POCDMT000002UK01Component5 component5 = mock(POCDMT000002UK01Component5.class);
POCDMT000002UK01Section innerSection = mock(POCDMT000002UK01Section.class);
StrucDocText text = mock(StrucDocText.class);
StrucDocContent contentItem = mock(StrucDocContent.class);
StrucDocContent[] content = new StrucDocContent[] { contentItem };
when(text.getContentArray()).thenReturn(content);
when(innerSection.getText()).thenReturn(text);
ST title = mock(ST.class);
when(nodeUtil.getNodeValueString(title)).thenReturn("Patient's Reported Condition");
when(nodeUtil.getNodeValueString(contentItem)).thenReturn(OBSERVATION_VALUE);
when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
when(resourceUtil.createReference(encounter)).thenReturn(new Reference(encounter));
when(innerSection.getTitle()).thenReturn(title);
when(component5.getSection()).thenReturn(innerSection);
POCDMT000002UK01Component5[] components5 = new POCDMT000002UK01Component5[] { component5 };
when(section.getComponentArray()).thenReturn(components5);
when(component3.getSection()).thenReturn(section);
POCDMT000002UK01Component3[] components3 = new POCDMT000002UK01Component3[] { component3 };
when(structuredBody.getComponentArray()).thenReturn(components3);
when(component2.getStructuredBody()).thenReturn(structuredBody);
when(clinicalDocument.getComponent()).thenReturn(component2);
when(encounter.getSubject()).thenReturn(subject);
}
Aggregations