use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PROCEDURE in project synthea by synthetichealth.
the class FhirStu3 method encounterClaim.
/**
* Create an entry for the given Claim, associated to an Encounter.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry Entry for the person
* @param bundle The Bundle to add to
* @param encounterEntry The current Encounter
* @param claim the Claim object
* @return the added Entry
*/
private static BundleEntryComponent encounterClaim(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim) {
org.hl7.fhir.dstu3.model.Claim claimResource = new org.hl7.fhir.dstu3.model.Claim();
org.hl7.fhir.dstu3.model.Encounter encounterResource = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
claimResource.setStatus(ClaimStatus.ACTIVE);
claimResource.setUse(org.hl7.fhir.dstu3.model.Claim.Use.COMPLETE);
// duration of encounter
claimResource.setBillablePeriod(encounterResource.getPeriod());
claimResource.setPatient(new Reference(personEntry.getFullUrl()));
claimResource.setOrganization(encounterResource.getServiceProvider());
// add item for encounter
claimResource.addItem(new ItemComponent(new PositiveIntType(1)).addEncounter(new Reference(encounterEntry.getFullUrl())));
int itemSequence = 2;
int conditionSequence = 1;
int procedureSequence = 1;
int informationSequence = 1;
for (Claim.ClaimEntry claimEntry : claim.items) {
HealthRecord.Entry item = claimEntry.entry;
if (Costs.hasCost(item)) {
// update claimItems list
ItemComponent claimItem = new ItemComponent(new PositiveIntType(itemSequence));
Code primaryCode = item.codes.get(0);
String system = ExportHelper.getSystemURI(primaryCode.system);
CodeableConcept serviceProvided = new CodeableConcept().addCoding(new Coding().setCode(primaryCode.code).setVersion("v1").setSystem(system));
claimItem.setService(serviceProvided);
// calculate the cost of the procedure
Money moneyResource = new Money();
moneyResource.setCode("USD");
moneyResource.setSystem("urn:iso:std:iso:4217");
moneyResource.setValue(item.getCost());
claimItem.setNet(moneyResource);
if (item instanceof HealthRecord.Procedure) {
Type procedureReference = new Reference(item.fullUrl);
ProcedureComponent claimProcedure = new ProcedureComponent(new PositiveIntType(procedureSequence), procedureReference);
claimResource.addProcedure(claimProcedure);
claimItem.addProcedureLinkId(procedureSequence);
procedureSequence++;
} else {
Reference informationReference = new Reference(item.fullUrl);
SpecialConditionComponent informationComponent = new SpecialConditionComponent();
informationComponent.setSequence(informationSequence);
informationComponent.setValue(informationReference);
CodeableConcept category = new CodeableConcept();
category.getCodingFirstRep().setSystem("http://hl7.org/fhir/claiminformationcategory").setCode("info");
informationComponent.setCategory(category);
claimResource.addInformation(informationComponent);
claimItem.addInformationLinkId(informationSequence);
claimItem.setService(claimResource.getType());
informationSequence++;
}
claimResource.addItem(claimItem);
} else {
// assume it's a Condition, we don't have a Condition class specifically
// add diagnosisComponent to claim
Reference diagnosisReference = new Reference(item.fullUrl);
org.hl7.fhir.dstu3.model.Claim.DiagnosisComponent diagnosisComponent = new org.hl7.fhir.dstu3.model.Claim.DiagnosisComponent(new PositiveIntType(conditionSequence), diagnosisReference);
claimResource.addDiagnosis(diagnosisComponent);
// update claimItems with diagnosis
ItemComponent diagnosisItem = new ItemComponent(new PositiveIntType(itemSequence));
diagnosisItem.addDiagnosisLinkId(conditionSequence);
claimResource.addItem(diagnosisItem);
conditionSequence++;
}
itemSequence++;
}
Money moneyResource = new Money();
moneyResource.setCode("USD");
moneyResource.setSystem("urn:iso:std:iso:4217");
moneyResource.setValue(claim.getTotalClaimCost());
claimResource.setTotal(moneyResource);
return newEntry(rand, bundle, claimResource);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PROCEDURE in project synthea by synthetichealth.
the class FhirR4 method encounterClaim.
/**
* Create an entry for the given Claim, associated to an Encounter.
*
* @param person The patient having the encounter.
* @param personEntry Entry for the person
* @param bundle The Bundle to add to
* @param encounterEntry The current Encounter
* @param claim the Claim object
* @return the added Entry
*/
private static BundleEntryComponent encounterClaim(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Claim claim) {
org.hl7.fhir.r4.model.Claim claimResource = new org.hl7.fhir.r4.model.Claim();
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
claimResource.setStatus(ClaimStatus.ACTIVE);
CodeableConcept type = new CodeableConcept();
type.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claim-type").setCode("institutional");
claimResource.setType(type);
claimResource.setUse(org.hl7.fhir.r4.model.Claim.Use.CLAIM);
InsuranceComponent insuranceComponent = new InsuranceComponent();
insuranceComponent.setSequence(1);
insuranceComponent.setFocal(true);
insuranceComponent.setCoverage(new Reference().setDisplay(claim.payer.getName()));
claimResource.addInsurance(insuranceComponent);
// duration of encounter
claimResource.setBillablePeriod(encounterResource.getPeriod());
claimResource.setCreated(encounterResource.getPeriod().getEnd());
claimResource.setPatient(new Reference().setReference(personEntry.getFullUrl()).setDisplay((String) person.attributes.get(Person.NAME)));
claimResource.setProvider(encounterResource.getServiceProvider());
if (USE_US_CORE_IG) {
claimResource.setFacility(encounterResource.getLocationFirstRep().getLocation());
}
// set the required priority
CodeableConcept priority = new CodeableConcept();
priority.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/processpriority").setCode("normal");
claimResource.setPriority(priority);
// add item for encounter
claimResource.addItem(new ItemComponent(new PositiveIntType(1), encounterResource.getTypeFirstRep()).addEncounter(new Reference(encounterEntry.getFullUrl())));
int itemSequence = 2;
int conditionSequence = 1;
int procedureSequence = 1;
int informationSequence = 1;
for (Claim.ClaimEntry claimEntry : claim.items) {
HealthRecord.Entry item = claimEntry.entry;
if (Costs.hasCost(item)) {
// update claimItems list
Code primaryCode = item.codes.get(0);
String system = ExportHelper.getSystemURI(primaryCode.system);
ItemComponent claimItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(primaryCode, system));
// calculate the cost of the procedure
Money moneyResource = new Money();
moneyResource.setCurrency("USD");
moneyResource.setValue(item.getCost());
claimItem.setNet(moneyResource);
claimResource.addItem(claimItem);
if (item instanceof Procedure) {
Type procedureReference = new Reference(item.fullUrl);
ProcedureComponent claimProcedure = new ProcedureComponent(new PositiveIntType(procedureSequence), procedureReference);
claimResource.addProcedure(claimProcedure);
claimItem.addProcedureSequence(procedureSequence);
procedureSequence++;
} else {
Reference informationReference = new Reference(item.fullUrl);
SupportingInformationComponent informationComponent = new SupportingInformationComponent();
informationComponent.setSequence(informationSequence);
informationComponent.setValue(informationReference);
CodeableConcept category = new CodeableConcept();
category.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/claiminformationcategory").setCode("info");
informationComponent.setCategory(category);
claimResource.addSupportingInfo(informationComponent);
claimItem.addInformationSequence(informationSequence);
informationSequence++;
}
} else {
// assume it's a Condition, we don't have a Condition class specifically
// add diagnosisComponent to claim
Reference diagnosisReference = new Reference(item.fullUrl);
DiagnosisComponent diagnosisComponent = new DiagnosisComponent(new PositiveIntType(conditionSequence), diagnosisReference);
claimResource.addDiagnosis(diagnosisComponent);
// update claimItems with diagnosis
ItemComponent diagnosisItem = new ItemComponent(new PositiveIntType(itemSequence), mapCodeToCodeableConcept(item.codes.get(0), SNOMED_URI));
diagnosisItem.addDiagnosisSequence(conditionSequence);
claimResource.addItem(diagnosisItem);
conditionSequence++;
}
itemSequence++;
}
Money moneyResource = new Money();
moneyResource.setCurrency("USD");
moneyResource.setValue(claim.getTotalClaimCost());
claimResource.setTotal(moneyResource);
return newEntry(person, bundle, claimResource);
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PROCEDURE in project synthea by synthetichealth.
the class FhirR4 method procedure.
/**
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry
* @param bundle Bundle to add to
* @param encounterEntry The current Encounter entry
* @param procedure The Procedure
* @return The added Entry
*/
private static BundleEntryComponent procedure(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Procedure procedure) {
org.hl7.fhir.r4.model.Procedure procedureResource = new org.hl7.fhir.r4.model.Procedure();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-procedure");
procedureResource.setMeta(meta);
}
procedureResource.setStatus(ProcedureStatus.COMPLETED);
procedureResource.setSubject(new Reference(personEntry.getFullUrl()));
procedureResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
if (USE_US_CORE_IG) {
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
procedureResource.setLocation(encounterResource.getLocationFirstRep().getLocation());
}
Code code = procedure.codes.get(0);
CodeableConcept procCode = mapCodeToCodeableConcept(code, SNOMED_URI);
procedureResource.setCode(procCode);
if (procedure.stop != 0L) {
Date startDate = new Date(procedure.start);
Date endDate = new Date(procedure.stop);
procedureResource.setPerformed(new Period().setStart(startDate).setEnd(endDate));
} else {
procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
}
if (!procedure.reasons.isEmpty()) {
// Only one element in list
Code reason = procedure.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
procedureResource.addReasonReference().setReference(entry.getFullUrl()).setDisplay(reason.display);
}
}
}
}
if (USE_SHR_EXTENSIONS) {
procedureResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-procedure-ProcedurePerformed"));
// required fields for this profile are action-PerformedContext-extension,
// status, code, subject, performed[x]
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
procedureResource.addExtension(performedContext);
}
BundleEntryComponent procedureEntry = newEntry(rand, bundle, procedureResource);
procedure.fullUrl = procedureEntry.getFullUrl();
return procedureEntry;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PROCEDURE in project synthea by synthetichealth.
the class FhirStu3 method procedure.
/**
* Map the given Procedure into a FHIR Procedure resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry
* @param bundle Bundle to add to
* @param encounterEntry The current Encounter entry
* @param procedure The Procedure
* @return The added Entry
*/
private static BundleEntryComponent procedure(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Procedure procedure) {
org.hl7.fhir.dstu3.model.Procedure procedureResource = new org.hl7.fhir.dstu3.model.Procedure();
procedureResource.setStatus(ProcedureStatus.COMPLETED);
procedureResource.setSubject(new Reference(personEntry.getFullUrl()));
procedureResource.setContext(new Reference(encounterEntry.getFullUrl()));
Code code = procedure.codes.get(0);
CodeableConcept procCode = mapCodeToCodeableConcept(code, SNOMED_URI);
procedureResource.setCode(procCode);
if (procedure.stop != 0L) {
Date startDate = new Date(procedure.start);
Date endDate = new Date(procedure.stop);
procedureResource.setPerformed(new Period().setStart(startDate).setEnd(endDate));
} else {
procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
}
if (!procedure.reasons.isEmpty()) {
// Only one element in list
Code reason = procedure.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
procedureResource.addReasonReference().setReference(entry.getFullUrl()).setDisplay(reason.display);
}
}
}
}
if (USE_SHR_EXTENSIONS) {
procedureResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-procedure-ProcedurePerformed"));
// required fields for this profile are action-PerformedContext-extension,
// status, code, subject, performed[x]
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
procedureResource.addExtension(performedContext);
}
BundleEntryComponent procedureEntry = newEntry(rand, bundle, procedureResource);
procedure.fullUrl = procedureEntry.getFullUrl();
return procedureEntry;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.PROCEDURE in project synthea by synthetichealth.
the class FhirStu3 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle, containing the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR from
* @param stopTime Time the simulation ended
* @return FHIR Bundle containing the Person's health record.
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Entry allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in stu3 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (Medication medication : encounter.medications) {
medication(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
careplan(person, personEntry, bundle, encounterEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
// one claim per encounter
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
return bundle;
}
Aggregations