use of ca.uhn.fhir.model.dstu2.resource.Condition in project synthea by synthetichealth.
the class FhirDstu2 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 Entry procedure(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Procedure procedure) {
ca.uhn.fhir.model.dstu2.resource.Procedure procedureResource = new ca.uhn.fhir.model.dstu2.resource.Procedure();
procedureResource.setStatus(ProcedureStatusEnum.COMPLETED);
procedureResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
procedureResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = procedure.codes.get(0);
procedureResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
if (procedure.stop != 0L) {
Date startDate = new Date(procedure.start);
Date endDate = new Date(procedure.stop);
procedureResource.setPerformed(new PeriodDt().setStart(new DateTimeDt(startDate)).setEnd(new DateTimeDt(endDate)));
} else {
procedureResource.setPerformed(convertFhirDateTime(procedure.start, true));
}
if (!procedure.reasons.isEmpty()) {
// Only one element in list
Code reason = procedure.reasons.get(0);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodingDt coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
procedureResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
}
}
}
}
Entry procedureEntry = newEntry(rand, bundle, procedureResource);
procedure.fullUrl = procedureEntry.getFullUrl();
return procedureEntry;
}
use of ca.uhn.fhir.model.dstu2.resource.Condition in project synthea by synthetichealth.
the class FhirDstu2 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle with the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR Bundle
* @param stopTime Time the simulation ended
* @return String containing a 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(BundleTypeEnum.TRANSACTION);
} else {
bundle.setType(BundleTypeEnum.COLLECTION);
}
Entry personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
Entry 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
encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
}
return bundle;
}
use of ca.uhn.fhir.model.dstu2.resource.Condition in project synthea by synthetichealth.
the class FhirDstu2 method condition.
/**
* Map the Condition into a FHIR Condition resource, and add it to the given Bundle.
*
* @param rand
* Source of randomness to use when generating ids etc
* @param personEntry
* The Entry for the Person
* @param bundle
* The Bundle to add to
* @param encounterEntry
* The current Encounter entry
* @param condition
* The Condition
* @return The added Entry
*/
private static Entry condition(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, HealthRecord.Entry condition) {
Condition conditionResource = new Condition();
conditionResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
conditionResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = condition.codes.get(0);
conditionResource.setCode(mapCodeToCodeableConcept(code, SNOMED_URI));
conditionResource.setCategory(ConditionCategoryCodesEnum.DIAGNOSIS);
conditionResource.setVerificationStatus(ConditionVerificationStatusEnum.CONFIRMED);
conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.ACTIVE);
conditionResource.setOnset(convertFhirDateTime(condition.start, true));
conditionResource.setDateRecorded(new DateDt(new Date(condition.start)));
if (condition.stop != 0) {
conditionResource.setAbatement(convertFhirDateTime(condition.stop, true));
conditionResource.setClinicalStatus(ConditionClinicalStatusCodesEnum.RESOLVED);
}
Entry conditionEntry = newEntry(rand, bundle, conditionResource);
condition.fullUrl = conditionEntry.getFullUrl();
return conditionEntry;
}
use of ca.uhn.fhir.model.dstu2.resource.Condition in project synthea by synthetichealth.
the class FhirDstu2 method medicationAdministration.
/**
* Add a MedicationAdministration if needed for the given medication.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the MedicationAdministration to
* @param encounterEntry Current Encounter entry
* @param medication The Medication
* @return The added Entry
*/
private static Entry medicationAdministration(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
MedicationAdministration medicationResource = new MedicationAdministration();
medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
medicationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = medication.codes.get(0);
String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
medicationResource.setEffectiveTime(new DateTimeDt(new Date(medication.start)));
medicationResource.setStatus(MedicationAdministrationStatusEnum.COMPLETED);
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
MedicationAdministration.Dosage dosage = new MedicationAdministration.Dosage();
// as_needed is true if present
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
SimpleQuantityDt dose = new SimpleQuantityDt();
dose.setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
dosage.setQuantity(dose);
if (rxInfo.has("instructions")) {
for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
JsonObject instruction = instructionElement.getAsJsonObject();
dosage.setText(instruction.get("display").getAsString());
}
}
}
medicationResource.setDosage(dosage);
}
if (!medication.reasons.isEmpty()) {
// Only one element in list
Code reason = medication.reasons.get(0);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodeableConceptDt coding = condition.getCode();
if (reason.code.equals(coding.getCodingFirstRep().getCode())) {
medicationResource.addReasonGiven(coding);
}
}
}
}
Entry medicationAdminEntry = newEntry(rand, bundle, medicationResource);
return medicationAdminEntry;
}
use of ca.uhn.fhir.model.dstu2.resource.Condition in project synthea by synthetichealth.
the class FhirDstu2 method careplan.
/**
* Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
*
* @param rand
* Source of randomness to use when generating ids etc
* @param personEntry
* The Entry for the Person
* @param bundle
* Bundle to add the CarePlan to
* @param encounterEntry
* Current Encounter entry
* @param carePlan
* The CarePlan to map to FHIR and add to the bundle
* @return The added Entry
*/
private static Entry careplan(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, CarePlan carePlan) {
ca.uhn.fhir.model.dstu2.resource.CarePlan careplanResource = new ca.uhn.fhir.model.dstu2.resource.CarePlan();
careplanResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
careplanResource.setContext(new ResourceReferenceDt(encounterEntry.getFullUrl()));
Code code = carePlan.codes.get(0);
careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
NarrativeDt narrative = new NarrativeDt();
narrative.setStatus(NarrativeStatusEnum.GENERATED);
narrative.setDiv(code.display);
careplanResource.setText(narrative);
CarePlanActivityStatusEnum activityStatus;
GoalStatusEnum goalStatus;
PeriodDt period = new PeriodDt().setStart(new DateTimeDt(new Date(carePlan.start)));
careplanResource.setPeriod(period);
if (carePlan.stop != 0L) {
period.setEnd(new DateTimeDt(new Date(carePlan.stop)));
careplanResource.setStatus(CarePlanStatusEnum.COMPLETED);
activityStatus = CarePlanActivityStatusEnum.COMPLETED;
goalStatus = GoalStatusEnum.ACHIEVED;
} else {
careplanResource.setStatus(CarePlanStatusEnum.ACTIVE);
activityStatus = CarePlanActivityStatusEnum.IN_PROGRESS;
goalStatus = GoalStatusEnum.IN_PROGRESS;
}
if (!carePlan.activities.isEmpty()) {
for (Code activity : carePlan.activities) {
Activity activityComponent = new Activity();
ActivityDetail activityDetailComponent = new ActivityDetail();
activityDetailComponent.setStatus(activityStatus);
activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
activityDetailComponent.setProhibited(new BooleanDt(false));
activityComponent.setDetail(activityDetailComponent);
careplanResource.addActivity(activityComponent);
}
}
if (!carePlan.reasons.isEmpty()) {
// Only one element in list
Code reason = carePlan.reasons.get(0);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodingDt coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
careplanResource.addAddresses().setReference(entry.getFullUrl());
}
}
}
}
for (JsonObject goal : carePlan.goals) {
Entry goalEntry = caregoal(rand, bundle, goalStatus, goal);
careplanResource.addGoal().setReference(goalEntry.getFullUrl());
}
return newEntry(rand, bundle, careplanResource);
}
Aggregations