use of ca.uhn.fhir.model.dstu2.composite.PeriodDt 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.composite.PeriodDt in project synthea by synthetichealth.
the class FhirDstu2 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param person
* Patient at the encounter.
* @param personEntry
* Entry for the Person
* @param bundle
* The Bundle to add to
* @param encounter
* The current Encounter
* @return The added Entry
*/
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
encounterResource.setStatus(EncounterStateEnum.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));
}
EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
if (encounterClass == null) {
encounterClass = EncounterClassEnum.AMBULATORY;
}
encounterResource.setClassElement(encounterClass);
encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(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 ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
} else {
Entry providerOrganization = provider(bundle, provider);
encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
} else {
Entry practitioner = practitioner(bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
}
if (encounter.discharge != null) {
Hospitalization hospitalization = new Hospitalization();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
return newEntry(person, bundle, encounterResource);
}
use of ca.uhn.fhir.model.dstu2.composite.PeriodDt 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);
}
use of ca.uhn.fhir.model.dstu2.composite.PeriodDt in project eCRNow by drajer-health.
the class Dstu2CdaFhirUtilities method getIDataTypeXml.
public static String getIDataTypeXml(IDatatype dt, String elName, Boolean valFlag) {
if (dt != null) {
logger.info(" Printing the class name " + dt.getClass());
String val = "";
if (dt instanceof CodingDt) {
CodingDt cd = (CodingDt) dt;
List<CodingDt> cds = new ArrayList<CodingDt>();
cds.add(cd);
if (!valFlag)
val += getCodingXml(cds, elName);
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof CodeableConceptDt) {
CodeableConceptDt cd = (CodeableConceptDt) dt;
List<CodingDt> cds = cd.getCoding();
if (!valFlag)
val += getCodingXml(cds, elName);
else
val += getCodingXmlForValue(cds, elName);
} else if (dt instanceof QuantityDt) {
QuantityDt qt = (QuantityDt) dt;
val += getQuantityXml(qt, elName, valFlag);
} else if (dt instanceof DateTimeDt) {
DateTimeDt d = (DateTimeDt) dt;
val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
} else if (dt instanceof PeriodDt) {
PeriodDt pt = (PeriodDt) dt;
val += getPeriodXml(pt, elName);
} else if (dt instanceof CodeDt) {
CodeDt cd = (CodeDt) dt;
if (!valFlag)
val += CdaGeneratorUtils.getXmlForNullCD(elName, CdaGeneratorConstants.NF_NI);
else
val += CdaGeneratorUtils.getNFXMLForValue(CdaGeneratorConstants.NF_NI);
}
return val;
}
return CdaGeneratorConstants.UNKNOWN_VALUE;
}
use of ca.uhn.fhir.model.dstu2.composite.PeriodDt in project eCRNow by drajer-health.
the class LaunchController method setStartAndEndDates.
public void setStartAndEndDates(ClientDetails clientDetails, LaunchDetails launchDetails, IBaseResource encounter) {
String fhirVersion = launchDetails.getFhirVersion();
// This is explicitly set to null so that when we don't have the encounter
// period present, we can default it to launch immediately.
launchDetails.setStartDate(null);
launchDetails.setEndDate(null);
if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.R4.toString())) {
org.hl7.fhir.r4.model.Encounter r4Encounter = (org.hl7.fhir.r4.model.Encounter) encounter;
if (r4Encounter != null) {
Period r4Period = r4Encounter.getPeriod();
if (r4Period != null) {
if (r4Period.getStart() != null) {
launchDetails.setStartDate(r4Period.getStart());
} else {
launchDetails.setStartDate(getDate(clientDetails.getEncounterStartThreshold()));
}
if (r4Period.getEnd() != null) {
launchDetails.setEndDate(r4Period.getEnd());
} else {
launchDetails.setEndDate(getDate(clientDetails.getEncounterEndThreshold()));
}
}
}
return;
}
if (fhirVersion.equalsIgnoreCase(FhirVersionEnum.DSTU2.toString())) {
Encounter dstu2Encounter = (Encounter) encounter;
if (dstu2Encounter != null) {
PeriodDt dstu2Period = dstu2Encounter.getPeriod();
if (dstu2Period != null) {
if (dstu2Period.getStart() != null) {
launchDetails.setStartDate(dstu2Period.getStart());
} else {
launchDetails.setStartDate(getDate(clientDetails.getEncounterStartThreshold()));
}
if (dstu2Period.getEnd() != null) {
launchDetails.setEndDate(dstu2Period.getEnd());
} else {
launchDetails.setEndDate(getDate(clientDetails.getEncounterEndThreshold()));
}
}
}
}
}
Aggregations