use of org.hl7.elm.r1.DateTime in project beneficiary-fhir-data by CMSgov.
the class BeneficiaryTransformerV2 method transform.
/**
* @param beneficiary the CCW {@link Beneficiary} to transform
* @param requestHeader {@link RequestHeaders} the holder that contains all supported resource
* request headers
* @return a FHIR {@link Patient} resource that represents the specified {@link Beneficiary}
*/
private static Patient transform(Beneficiary beneficiary, RequestHeaders requestHeader) {
Objects.requireNonNull(beneficiary);
Patient patient = new Patient();
/*
* Notify end users when they receive Patient records impacted by
* https://jira.cms.gov/browse/BFD-1566. See the documentation on
* LoadAppOptions.isFilteringNonNullAndNon2022Benes() for details.
*/
if (!beneficiary.getSkippedRifRecords().isEmpty()) {
patient.getMeta().addTag(TransformerConstants.CODING_SYSTEM_BFD_TAGS, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT, TransformerConstants.CODING_BFD_TAGS_DELAYED_BACKDATED_ENROLLMENT_DISPLAY);
}
// Required values not directly mapped
patient.getMeta().addProfile(ProfileConstants.C4BB_PATIENT_URL);
patient.setId(beneficiary.getBeneficiaryId());
// BENE_ID => patient.identifier
TransformerUtilsV2.addIdentifierSlice(patient, TransformerUtilsV2.createCodeableConcept(TransformerConstants.CODING_SYSTEM_HL7_IDENTIFIER_TYPE, null, TransformerConstants.PATIENT_MB_ID_DISPLAY, "MB"), Optional.of(beneficiary.getBeneficiaryId()), Optional.of(TransformerConstants.CODING_BBAPI_BENE_ID));
// Unhashed MBI
if (beneficiary.getMedicareBeneficiaryId().isPresent()) {
Period mbiPeriod = new Period();
if (beneficiary.getMbiEffectiveDate().isPresent()) {
TransformerUtilsV2.setPeriodStart(mbiPeriod, beneficiary.getMbiEffectiveDate().get());
}
if (beneficiary.getMbiObsoleteDate().isPresent()) {
TransformerUtilsV2.setPeriodEnd(mbiPeriod, beneficiary.getMbiObsoleteDate().get());
}
addUnhashedIdentifier(patient, beneficiary.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.CURRENT), mbiPeriod);
}
// Add lastUpdated
TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
/**
* The following logic attempts to distill {@link MedicareBeneficiaryIdHistory} data into only
* those records which have an endDate present. This is due to the fact that it includes the
* CURRENT MBI record which was handle previously. Also, the {@link
* MedicareBeneficiaryIdHistory} table appears to contain spurious records with the only
* difference is the generated surrogate key identifier.
*/
if (requestHeader.isMBIinIncludeIdentifiers()) {
HashMap<LocalDate, MedicareBeneficiaryIdHistory> mbiHistMap = new HashMap<LocalDate, MedicareBeneficiaryIdHistory>();
for (MedicareBeneficiaryIdHistory mbiHistory : beneficiary.getMedicareBeneficiaryIdHistories()) {
// and will have been previously provided as the CURRENT rcd.
if (mbiHistory.getMbiEndDate().isPresent()) {
mbiHistMap.put(mbiHistory.getMbiEndDate().get(), mbiHistory);
}
// would come in ascending order, so any rcd would have a later
// update date than prev rcd.
TransformerUtilsV2.updateMaxLastUpdated(patient, mbiHistory.getLastUpdated());
}
if (mbiHistMap.size() > 0) {
Extension historicalIdentifier = TransformerUtilsV2.createIdentifierCurrencyExtension(CurrencyIdentifier.HISTORIC);
for (MedicareBeneficiaryIdHistory mbi : mbiHistMap.values()) {
addUnhashedIdentifier(patient, mbi.getMedicareBeneficiaryId().get(), TransformerConstants.CODING_BBAPI_MEDICARE_BENEFICIARY_ID_UNHASHED, historicalIdentifier, null);
}
}
}
// support header includeAddressFields from downstream components e.g. BB2
// per requirement of BFD-379, BB2 always send header includeAddressFields = False
Boolean addrHdrVal = requestHeader.getValue(R4PatientResourceProvider.HEADER_NAME_INCLUDE_ADDRESS_FIELDS);
if (addrHdrVal != null && addrHdrVal) {
patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode()).setCity(beneficiary.getDerivedCityName().orElse(null)).addLine(beneficiary.getDerivedMailingAddress1().orElse(null)).addLine(beneficiary.getDerivedMailingAddress2().orElse(null)).addLine(beneficiary.getDerivedMailingAddress3().orElse(null)).addLine(beneficiary.getDerivedMailingAddress4().orElse(null)).addLine(beneficiary.getDerivedMailingAddress5().orElse(null)).addLine(beneficiary.getDerivedMailingAddress6().orElse(null));
} else {
patient.addAddress().setState(beneficiary.getStateCode()).setPostalCode(beneficiary.getPostalCode());
}
if (beneficiary.getBirthDate() != null) {
patient.setBirthDate(TransformerUtilsV2.convertToDate(beneficiary.getBirthDate()));
}
// "Patient.deceased[x]": ["boolean", "dateTime"],
if (beneficiary.getBeneficiaryDateOfDeath().isPresent()) {
patient.setDeceased(new DateTimeType(TransformerUtilsV2.convertToDate(beneficiary.getBeneficiaryDateOfDeath().get()), TemporalPrecisionEnum.DAY));
} else {
patient.setDeceased(new BooleanType(false));
}
char sex = beneficiary.getSex();
if (sex == Sex.MALE.getCode())
patient.setGender((AdministrativeGender.MALE));
else if (sex == Sex.FEMALE.getCode())
patient.setGender((AdministrativeGender.FEMALE));
else
patient.setGender((AdministrativeGender.UNKNOWN));
if (beneficiary.getRace().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.RACE, beneficiary.getRace().get()));
// for race category, v2 will just treat all race codes as Unknown (UNK);
// thus we'll simply pass in the Unknown race code .
RaceCategory raceCategory = TransformerUtilsV2.getRaceCategory('0');
Extension raceChildOMBExt1 = new Extension().setValue(new Coding().setCode(raceCategory.toCode()).setSystem(raceCategory.getSystem()).setDisplay(raceCategory.getDisplay())).setUrl("ombCategory");
Extension raceChildOMBExt2 = new Extension().setValue(new StringType().setValue(raceCategory.getDisplay())).setUrl("text");
Extension parentOMBRace = new Extension().setUrl(TransformerConstants.CODING_RACE_US);
parentOMBRace.addExtension(raceChildOMBExt1);
parentOMBRace.addExtension(raceChildOMBExt2);
patient.addExtension(parentOMBRace);
}
HumanName name = patient.addName().addGiven(beneficiary.getNameGiven()).setFamily(beneficiary.getNameSurname()).setUse(HumanName.NameUse.USUAL);
if (beneficiary.getNameMiddleInitial().isPresent()) {
name.addGiven(String.valueOf(beneficiary.getNameMiddleInitial().get()));
}
// The reference year of the enrollment data
if (beneficiary.getBeneEnrollmentReferenceYear().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionDate(CcwCodebookVariable.RFRNC_YR, beneficiary.getBeneEnrollmentReferenceYear()));
}
// Monthly Medicare-Medicaid dual eligibility codes
if (beneficiary.getMedicaidDualEligibilityJanCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_01, beneficiary.getMedicaidDualEligibilityJanCode()));
}
if (beneficiary.getMedicaidDualEligibilityFebCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_02, beneficiary.getMedicaidDualEligibilityFebCode()));
}
if (beneficiary.getMedicaidDualEligibilityMarCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_03, beneficiary.getMedicaidDualEligibilityMarCode()));
}
if (beneficiary.getMedicaidDualEligibilityAprCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_04, beneficiary.getMedicaidDualEligibilityAprCode()));
}
if (beneficiary.getMedicaidDualEligibilityMayCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_05, beneficiary.getMedicaidDualEligibilityMayCode()));
}
if (beneficiary.getMedicaidDualEligibilityJunCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_06, beneficiary.getMedicaidDualEligibilityJunCode()));
}
if (beneficiary.getMedicaidDualEligibilityJulCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_07, beneficiary.getMedicaidDualEligibilityJulCode()));
}
if (beneficiary.getMedicaidDualEligibilityAugCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_08, beneficiary.getMedicaidDualEligibilityAugCode()));
}
if (beneficiary.getMedicaidDualEligibilitySeptCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_09, beneficiary.getMedicaidDualEligibilitySeptCode()));
}
if (beneficiary.getMedicaidDualEligibilityOctCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_10, beneficiary.getMedicaidDualEligibilityOctCode()));
}
if (beneficiary.getMedicaidDualEligibilityNovCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_11, beneficiary.getMedicaidDualEligibilityNovCode()));
}
if (beneficiary.getMedicaidDualEligibilityDecCode().isPresent()) {
patient.addExtension(TransformerUtilsV2.createExtensionCoding(patient, CcwCodebookVariable.DUAL_12, beneficiary.getMedicaidDualEligibilityDecCode()));
}
// Last Updated => Patient.meta.lastUpdated
TransformerUtilsV2.setLastUpdated(patient, beneficiary.getLastUpdated());
return patient;
}
use of org.hl7.elm.r1.DateTime in project kindling by HL7.
the class JsonLDDefinitionsGenerator method generate.
// private String genDate;
// private String version;
// private BuildWorkerContext workerContext;
public void generate(Definitions definitions, IniFile ini, String tmpResDir, String dstDir, String srcDir, FHIRVersion version, String genDate, BuildWorkerContext workerContext) throws Exception {
// this.genDate = genDate;
// this.version = version;
// this.workerContext = workerContext;
JsonObject defn = new JsonObject();
JsonObject context = new JsonObject();
defn.add("@context", context);
defn.addProperty("@id", "http://hl7.org/fhir/");
context.addProperty("fhir", "http://hl7.org/fhir/");
context.addProperty("xsd", "http://www.w3.org/2001/XMLSchema#");
// properties for primitives, helpers, format features
addProperty(context, "value", "fhir:value", "xsd:string");
addProperty(context, "decimal", "fhir:value", "xsd:decimal");
addProperty(context, "integer", "fhir:value", "xsd:integer");
if (!version.isR4B()) {
addProperty(context, "integer64", "fhir:value", "xsd:string");
}
addProperty(context, "boolean", "fhir:value", "xsd:boolean");
addProperty(context, "binary", "fhir:value", "xsd:base64Binary");
addProperty(context, "date", "fhir:value", "xsd:date");
addProperty(context, "dateTime", "fhir:value", "xsd:dateTime");
addProperty(context, "gYearMonth", "fhir:value", "xsd:gYearMonth");
addProperty(context, "gYear", "fhir:value", "xsd:gYear");
addProperty(context, "link", "fhir:link", "@id");
addProperty(context, "concept", "fhir:concept", "@id");
addProperty(context, "index", "fhir:index", "xsd:integer");
addProperty(context, "role", "fhir:nodeRole", "@id");
// elements defined in FHIR:
for (TypeRef tr : definitions.getKnownTypes()) {
if (!definitions.hasPrimitiveType(tr.getName()) && !tr.getName().equals("SimpleQuantity") && !tr.getName().equals("MoneyQuantity")) {
TypeDefn root = definitions.getElementDefn(tr.getName());
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root, version, genDate);
}
}
List<String> names = new ArrayList<String>();
names.addAll(definitions.getResources().keySet());
names.addAll(definitions.getBaseResources().keySet());
names.add("Parameters");
Collections.sort(names);
for (String name : names) {
ResourceDefn root = definitions.getResourceByName(name);
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root.getRoot(), version, genDate);
}
save(defn, dstDir + "fhir.jsonld");
}
use of org.hl7.elm.r1.DateTime in project kindling by HL7.
the class FhirTurtleGenerator method genPrimitiveType.
/* ==============================================
Generators for various FHIR types
* ============================================== */
/**
* PrimitiveType Generator
*
* @param pt FHIR Primitive Type (e.g. int, string, dateTime)
*/
// Note: For unknown reasons, getPrimitives returns DefinedCodes, not PrimitiveTypes...
private void genPrimitiveType(DefinedCode pt) {
String ptName = pt.getCode();
FHIRResource ptRes = fact.fhir_class(ptName, "Primitive").addDefinition(pt.getDefinition());
Resource rdfType = RDFTypeMap.xsd_type_for(ptName, owlTarget);
if (rdfType != null)
ptRes.restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(rdfType).resource, 1, 1));
}
use of org.hl7.elm.r1.DateTime in project hl7v2-fhir-converter by LinuxForHealth.
the class InputTimeZoneIdTest method validateTimeZoneIdSettingViaOption.
@Test
void validateTimeZoneIdSettingViaOption() {
// NOTE: This simple Condition (PRB) segment is used for testing time because it has both
// standard DateTime conversions (abatementDateTime, recordedDate) and value conversions (extension).
String hl7message = "MSH|^~\\&|||||20040629164652|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.16 to onsetDateTime (check time ZoneId)
"PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956|||20070707070000||20090909090000|||||||20160616160000\r";
// FIRST test with city based ZoneId passed through options
ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("America/Chicago").build();
// "America/Chicago" will become -06:00 in winter (CST) -05:00 in spring/summer/fall (CDT). This is expected.
List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
Condition condition = (Condition) conditionResource.get(0);
// PRB.2 Chicago Central STANDARD Time
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00-06:00");
// PRB.9 Chicago Central DAYLIGHT Time
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00-05:00");
// PRB.16 Chicago CDT
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00-05:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7 Chicago CDT
"2007-07-07T07:00:00-05:00");
// SECOND test with fixed ZoneId passed through options
customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().withZoneIdText("+03:00").build();
e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
condition = (Condition) conditionResource.get(0);
// PRB.2 fixed ZoneId
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+03:00");
// PRB.9
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+03:00");
// PRB.16
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+03:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
"2007-07-07T07:00:00+03:00");
// THIRD test with no ZoneId passed through options, so it uses the config.properties ZoneId
customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
// Find the condition from the FHIR bundle.
conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
assertThat(conditionResource).hasSize(1);
condition = (Condition) conditionResource.get(0);
// PRB.2 config.properties ZoneId
assert (condition.getRecordedDateElement().getValueAsString()).contains("2002-02-02T02:00:00+08:00");
// PRB.9
assert (condition.getAbatementDateTimeType().getValueAsString()).contains("2009-09-09T09:00:00+08:00");
// PRB.16
assert (condition.getOnsetDateTimeType().getValueAsString()).contains("2016-06-16T16:00:00+08:00");
assert (condition.getExtensionByUrl("http://hl7.org/fhir/StructureDefinition/condition-assertedDate").getValueAsPrimitive().getValueAsString()).contains(// PRB.7
"2007-07-07T07:00:00+08:00");
}
use of org.hl7.elm.r1.DateTime in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveActivityDefinition.
// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
Resource result = newResource(activityDefinition.getKind().toCode());
switch(result.fhirType()) {
case "ServiceRequest":
result = resolveServiceRequest(activityDefinition, patientId, practitionerId, organizationId);
break;
case "MedicationRequest":
result = resolveMedicationRequest(activityDefinition, patientId);
break;
case "SupplyRequest":
result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
break;
case "Procedure":
result = resolveProcedure(activityDefinition, patientId);
break;
case "DiagnosticReport":
result = resolveDiagnosticReport(activityDefinition, patientId);
break;
case "Communication":
result = resolveCommunication(activityDefinition, patientId);
break;
case "CommunicationRequest":
result = resolveCommunicationRequest(activityDefinition, patientId);
break;
case "Task":
result = resolveTask(activityDefinition, patientId);
break;
}
for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
// ActivityDefinition apply operation does not fail.
try {
if (dynamicValue.getExpression() != null) {
// Special case for setting a Patient reference
if ("Patient".equals(dynamicValue.getExpression().getExpression())) {
this.modelResolver.setValue(result, dynamicValue.getPath(), new Reference(patientId));
} else {
/*
* TODO: Passing the activityDefinition as context here because that's what will
* have the libraries, but perhaps the "context" here should be the result
* resource?
*/
Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression().getExpression(), patientId, theRequest);
if (value != null) {
logger.debug("dynamicValue value: {}", value);
if (value instanceof Boolean) {
value = new BooleanType((Boolean) value);
} else if (value instanceof DateTime) {
value = Date.from(((DateTime) value).getDateTime().toInstant());
} else if (value instanceof String) {
value = new StringType((String) value);
}
this.modelResolver.setValue(result, dynamicValue.getPath(), value);
} else {
logger.warn("WARNING: ActivityDefinition has null value for path: {}", dynamicValue.getPath());
}
}
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition dynamicValue {} could not be applied and threw exception {}", dynamicValue.getPath(), e.toString());
logger.error(e.toString());
}
}
return result;
}
Aggregations