use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project synthea by synthetichealth.
the class FhirR4 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param personEntry Entry for the Person
* @param bundle The Bundle to add to
* @param encounter The current Encounter
* @return The added Entry
*/
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
org.hl7.fhir.r4.model.Encounter encounterResource = new org.hl7.fhir.r4.model.Encounter();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-encounter");
encounterResource.setMeta(meta);
} else if (USE_SHR_EXTENSIONS) {
encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
encounterResource.addExtension(performedContext);
}
Patient patient = (Patient) personEntry.getResource();
encounterResource.setSubject(new Reference().setReference(personEntry.getFullUrl()).setDisplay(patient.getNameFirstRep().getNameAsSingleString()));
encounterResource.setStatus(EncounterStatus.FINISHED);
if (encounter.codes.isEmpty()) {
// wellness encounter
encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
} else {
Code code = encounter.codes.get(0);
encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
}
Coding classCode = new Coding();
classCode.setCode(EncounterType.fromString(encounter.type).code());
classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
encounterResource.setClass_(classCode);
encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
if (encounter.reason != null) {
encounterResource.addReasonCode().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
}
Provider provider = encounter.provider;
if (provider == null) {
// no associated provider, patient goes to wellness provider
provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
}
if (TRANSACTION_BUNDLE) {
encounterResource.setServiceProvider(new Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new Reference(providerFullUrl));
} else {
BundleEntryComponent providerOrganization = provider(person, bundle, provider);
encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (USE_US_CORE_IG) {
String referenceUrl;
String display;
if (TRANSACTION_BUNDLE) {
if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
referenceUrl = ExportHelper.buildFhirSearchUrl("Location", FhirR4PatientHome.getPatientHome().getId());
display = "Patient's Home";
} else {
referenceUrl = ExportHelper.buildFhirSearchUrl("Location", provider.getResourceLocationID());
display = provider.name;
}
} else {
if (encounter.type.equals(EncounterType.VIRTUAL.toString())) {
referenceUrl = addPatientHomeLocation(bundle);
display = "Patient's Home";
} else {
referenceUrl = findLocationUrl(provider, bundle);
display = provider.name;
}
}
encounterResource.addLocation().setLocation(new Reference().setReference(referenceUrl).setDisplay(display));
}
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
} else {
BundleEntryComponent practitioner = practitioner(person, bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
encounterResource.getParticipantFirstRep().addType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/v3-ParticipationType", "PPRF", "primary performer"), null));
encounterResource.getParticipantFirstRep().setPeriod(encounterResource.getPeriod());
}
if (encounter.discharge != null) {
EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
BundleEntryComponent entry = newEntry(person, bundle, encounterResource);
if (USE_US_CORE_IG) {
// US Core Encounters should have an identifier to support the required
// Encounter.identifier search parameter
encounterResource.addIdentifier().setUse(IdentifierUse.OFFICIAL).setSystem(SYNTHEA_IDENTIFIER).setValue(encounterResource.getId());
}
return entry;
}
use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project synthea by synthetichealth.
the class FhirR4 method provenance.
/**
* Create a Provenance entry at the end of this Bundle that
* targets all the entries in the Bundle.
*
* @param bundle The finished complete Bundle.
* @param person The person.
* @param stopTime The time the simulation stopped.
* @return BundleEntryComponent containing a Provenance resource.
*/
private static BundleEntryComponent provenance(Bundle bundle, Person person, long stopTime) {
Provenance provenance = new Provenance();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-provenance");
provenance.setMeta(meta);
}
for (BundleEntryComponent entry : bundle.getEntry()) {
provenance.addTarget(new Reference(entry.getFullUrl()));
}
provenance.setRecorded(new Date(stopTime));
// Provenance sources...
int index = person.record.encounters.size() - 1;
Clinician clinician = null;
while (index >= 0 && clinician == null) {
clinician = person.record.encounters.get(index).clinician;
index--;
}
String clinicianDisplay = null;
if (clinician != null) {
clinicianDisplay = clinician.getFullname();
}
String practitionerFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirNpiSearchUrl(clinician) : findPractitioner(clinician, bundle);
Provider providerOrganization = person.record.provider;
if (providerOrganization == null) {
providerOrganization = person.getProvider(EncounterType.WELLNESS, stopTime);
}
String organizationFullUrl = TRANSACTION_BUNDLE ? ExportHelper.buildFhirSearchUrl("Organization", providerOrganization.getResourceID()) : findProviderUrl(providerOrganization, bundle);
// Provenance Author...
ProvenanceAgentComponent agent = provenance.addAgent();
agent.setType(mapCodeToCodeableConcept(new Code("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "author", "Author"), null));
agent.setWho(new Reference().setReference(practitionerFullUrl).setDisplay(clinicianDisplay));
agent.setOnBehalfOf(new Reference().setReference(organizationFullUrl).setDisplay(providerOrganization.name));
// Provenance Transmitter...
agent = provenance.addAgent();
agent.setType(mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/us/core/CodeSystem/us-core-provenance-participant-type", "transmitter", "Transmitter"), null));
agent.setWho(new Reference().setReference(practitionerFullUrl).setDisplay(clinicianDisplay));
agent.setOnBehalfOf(new Reference().setReference(organizationFullUrl).setDisplay(providerOrganization.name));
return newEntry(person, bundle, provenance);
}
use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project synthea by synthetichealth.
the class FhirStu3 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param personEntry Entry for the Person
* @param bundle The Bundle to add to
* @param encounter The current Encounter
* @return The added Entry
*/
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
org.hl7.fhir.dstu3.model.Encounter encounterResource = new org.hl7.fhir.dstu3.model.Encounter();
encounterResource.setSubject(new Reference(personEntry.getFullUrl()));
encounterResource.setStatus(EncounterStatus.FINISHED);
if (encounter.codes.isEmpty()) {
// wellness encounter
encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
} else {
Code code = encounter.codes.get(0);
encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
}
Coding classCode = new Coding();
classCode.setCode(EncounterType.fromString(encounter.type).code());
classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
encounterResource.setClass_(classCode);
encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(new Date(encounter.stop)));
if (encounter.reason != null) {
encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
}
Provider provider = encounter.provider;
if (provider == null) {
// no associated provider, patient goes to wellness provider
provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
}
if (TRANSACTION_BUNDLE) {
encounterResource.setServiceProvider(new Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new Reference(providerFullUrl));
} else {
BundleEntryComponent providerOrganization = provider(bundle, provider);
encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
} else {
BundleEntryComponent practitioner = practitioner(bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
}
if (encounter.discharge != null) {
EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
if (USE_SHR_EXTENSIONS) {
encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
// required fields for this profile are status & action-PerformedContext-extension
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
encounterResource.addExtension(performedContext);
}
return newEntry(person, bundle, encounterResource);
}
use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project cqf-ruler by DBCG.
the class CodeSystemProviderIT method testDSTU3RxNormCodeSystemUpdateById.
@Test
@Order(3)
public void testDSTU3RxNormCodeSystemUpdateById() throws IOException {
log.info("Beginning Test DSTU3 RxNorm CodeSystemUpdate");
ValueSet vs = (ValueSet) loadResource("org/opencds/cqf/ruler/devtools/dstu3/valueset/AntithromboticTherapy.json");
assertEquals(0, performCodeSystemSearchByUrl(rxNormUrl).size());
OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement());
for (OperationOutcomeIssueComponent issue : outcome.getIssue()) {
assertEquals(OperationOutcome.IssueSeverity.INFORMATION, issue.getSeverity());
assertTrue(issue.getDetails().getText().startsWith("Successfully updated the following CodeSystems: "));
assertTrue(issue.getDetails().getText().contains("rxnorm"));
}
assertEquals(1, performCodeSystemSearchByUrl(rxNormUrl).size());
log.info("Finished Test DSTU3 RxNorm CodeSystemUpdate");
}
use of org.hl7.fhir.dstu3.model.Encounter.EncounterStatus.FINISHED in project cqf-ruler by DBCG.
the class CodeSystemProviderIT method testDSTU3ICD10PerformCodeSystemUpdateByList.
@Test
@Order(4)
public void testDSTU3ICD10PerformCodeSystemUpdateByList() throws IOException {
log.info("Beginning Test DSTU3 ICD10 CodeSystemUpdate");
BufferedReader reader = new BufferedReader(new InputStreamReader(CodeSystemProviderIT.class.getResourceAsStream("valueset" + "/" + "AllPrimaryandSecondaryCancer.json")));
String resourceString = reader.lines().collect(Collectors.joining(System.lineSeparator()));
reader.close();
ValueSet vs = (ValueSet) loadResource("json", resourceString);
assertEquals(0, performCodeSystemSearchByUrl(icd10).size());
codeSystemUpdateProvider.performCodeSystemUpdate(Arrays.asList(vs));
OperationOutcome outcome = codeSystemUpdateProvider.updateCodeSystems(vs.getIdElement());
for (OperationOutcomeIssueComponent issue : outcome.getIssue()) {
assertEquals(OperationOutcome.IssueSeverity.INFORMATION, issue.getSeverity());
assertTrue(issue.getDetails().getText().startsWith("Successfully updated the following CodeSystems: "));
assertTrue(issue.getDetails().getText().contains("icd-10"));
}
assertEquals(1, performCodeSystemSearchByUrl(icd10).size());
log.info("Finished Test DSTU3 ICD10 CodeSystemUpdate");
}
Aggregations