Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consent #1

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 77 additions & 3 deletions src/main/java/org/mitre/synthea/export/FhirR4.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.awt.geom.Point2D;
import java.io.IOException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -113,8 +115,7 @@
import org.mitre.synthea.world.concepts.HealthRecord.Procedure;
import org.mitre.synthea.world.concepts.HealthRecord.Report;
import org.mitre.synthea.world.geography.Location;

import static com.oracle.truffle.js.builtins.math.MathBuiltins.Math.random;
import org.opencds.cqf.cql.engine.runtime.DateTime;

public class FhirR4 {
// HAPI FHIR warns that the context creation is expensive, and should be performed
Expand Down Expand Up @@ -358,6 +359,11 @@ public static Bundle convertToFHIR(Person person, long stopTime) {

BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);

if (shouldExport(Consent.class)) {
consentByPerson(person, bundle, personEntry,"");
consentByPerson(person, bundle, personEntry,"gina");
}

for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);

Expand Down Expand Up @@ -463,7 +469,7 @@ public static Bundle convertToFHIR(Person person, long stopTime) {

// add appointment to every encounter as well
if (shouldExport(org.hl7.fhir.r4.model.Appointment.class)) {
BundleEntryComponent apptEncounter = encounterAppointment(person, personEntry, bundle, encounter, encounterEntry);
encounterAppointment(person, personEntry, bundle, encounter, encounterEntry);
}
}

Expand All @@ -474,6 +480,74 @@ public static Bundle convertToFHIR(Person person, long stopTime) {
return bundle;
}

private static BundleEntryComponent consentByPerson(Person person, Bundle bundle, BundleEntryComponent personEntry, String type) {
org.hl7.fhir.r4.model.Consent consent = new Consent();

consent.setPatient(new Reference()
.setReference(personEntry.getFullUrl())
.setDisplay(person.attributes
.get(Person.FIRST_NAME).toString()
+
person.attributes.get(Person.LAST_NAME).toString()));
List<CodeableConcept> codingList = new ArrayList<>();
// set category
if (type.equals(new String(""))) {
CodeableConcept termsAndConditionsCC = new CodeableConcept();
termsAndConditionsCC.addCoding().setCode("terms_and_conditions")
.setDisplay("Terms and Conditions")
.setSystem("terms and conditions");
codingList.add(termsAndConditionsCC);
} else {
CodeableConcept ginaCC = new CodeableConcept();
ginaCC.addCoding().setCode("gina")
.setDisplay("GINA")
.setSystem("gina");
codingList.add(ginaCC);
}


consent.setCategory(codingList);

// status set
consent.setStatus(Consent.ConsentState.ACTIVE);

// date time
consent.setDateTime(Date.from(Instant.now()));

consent.setId(String.valueOf(UUID.randomUUID()));
if (type.equals(new String(""))) {
consent.setProvision(new Consent.provisionComponent().setType(Consent.ConsentProvisionType.PERMIT));
} else {
LocalDateTime now = LocalDateTime.now();
LocalDateTime end = now.plusDays(365);



consent.setProvision(new Consent.provisionComponent().setType(Consent.ConsentProvisionType.PERMIT)
.setPeriod(
new Period()
.setStart(java.sql.Timestamp.valueOf(now))
.setEnd(java.sql.Timestamp.valueOf(end))
)
);
}

// adding scope
CodeableConcept scopeCC = new CodeableConcept();
scopeCC.addCoding().setCode("active");
consent.setScope(scopeCC);

// policy rule Codeable Concept addition
CodeableConcept policyRuleCC = new CodeableConcept();
policyRuleCC.addCoding().setCode("policy rule").setDisplay("Policy Rule");
consent.setPolicyRule(policyRuleCC);



return newEntry(bundle, consent, consent.getId());
}


private static BundleEntryComponent encounterAppointment(Person person, BundleEntryComponent personEntry,
Bundle bundle, Encounter encounter,
BundleEntryComponent encounterEntry) {
Expand Down