Search in sources :

Example 61 with DateTimeType

use of org.hl7.fhir.r4.model.DateTimeType in project eCRNow by drajer-health.

the class CdaFhirUtilities method getXmlForTypeForValueIvlTsEffectiveTime.

public static String getXmlForTypeForValueIvlTsEffectiveTime(String elName, Type dt) {
    String val = "";
    if (dt != null) {
        if (dt instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) dt;
            val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
        } else if (dt instanceof Period) {
            Period pt = (Period) dt;
            val += getPeriodXml(pt, elName);
        } else if (dt instanceof Timing) {
            Timing t = (Timing) (dt);
            if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
                logger.debug("Found the bounds element for creating xml");
            }
        }
        logger.debug("Printing the class name {}", dt.getClass());
        return val;
    }
    return val;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) Timing(org.hl7.fhir.r4.model.Timing)

Example 62 with DateTimeType

use of org.hl7.fhir.r4.model.DateTimeType in project eCRNow by drajer-health.

the class CdaFhirUtilities method getActualDate.

public static Pair<Date, TimeZone> getActualDate(Type dt) {
    Date d = null;
    TimeZone t = null;
    if (dt instanceof DateTimeType) {
        DateTimeType d1 = (DateTimeType) dt;
        d = d1.getValue();
        t = d1.getTimeZone();
    } else if (dt instanceof Period) {
        logger.debug("Found an instance of period");
        Period d1 = (Period) dt;
        if (d1.getStartElement() != null) {
            d = d1.getStart();
            t = d1.getStartElement().getTimeZone();
        } else if (d1.getEndElement() != null) {
            d = d1.getEnd();
            t = d1.getEndElement().getTimeZone();
        }
    } else if (dt instanceof InstantType) {
        InstantType d1 = (InstantType) dt;
        d = d1.getValue();
        t = d1.getTimeZone();
    } else if (dt instanceof Timing) {
        logger.debug(" Found an instance of timing ");
        Timing tmg = (Timing) (dt);
        if (tmg.getRepeat() != null && tmg.getRepeat().getBounds() != null) {
            logger.debug(" Found the bounds element ");
            return getActualDate(tmg.getRepeat().getBounds());
        }
    }
    return new Pair<>(d, t);
}
Also used : TimeZone(java.util.TimeZone) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Period(org.hl7.fhir.r4.model.Period) Timing(org.hl7.fhir.r4.model.Timing) InstantType(org.hl7.fhir.r4.model.InstantType) Date(java.util.Date) Pair(org.javatuples.Pair)

Example 63 with DateTimeType

use of org.hl7.fhir.r4.model.DateTimeType in project eCRNow by drajer-health.

the class CdaFhirUtilities method getXmlForType.

public static String getXmlForType(Type dt, String elName, Boolean valFlag) {
    String val = "";
    if (dt != null) {
        if (dt instanceof Coding) {
            Coding cd = (Coding) dt;
            List<Coding> cds = new ArrayList<>();
            cds.add(cd);
            if (!valFlag)
                val += getCodingXml(cds, elName, "");
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof CodeableConcept) {
            CodeableConcept cd = (CodeableConcept) dt;
            List<Coding> cds = cd.getCoding();
            if (!valFlag)
                val += getCodingXml(cds, elName, "");
            else
                val += getCodingXmlForValue(cds, elName);
        } else if (dt instanceof Quantity) {
            Quantity qt = (Quantity) dt;
            val += getQuantityXml(qt, elName, valFlag);
        } else if (dt instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) dt;
            val += CdaGeneratorUtils.getXmlForEffectiveTime(elName, d.getValue(), d.getTimeZone());
        } else if (dt instanceof Period) {
            Period pt = (Period) dt;
            val += getPeriodXml(pt, elName);
        } else if (dt instanceof Timing) {
            Timing t = (Timing) (dt);
            if (t.getRepeat() != null && t.getRepeat().getBounds() != null) {
                logger.debug("Found the bounds element for creating xml");
                String v = getXmlForType(t.getRepeat().getBounds(), elName, valFlag);
                val += v;
            }
        } else if (dt instanceof CodeType) {
            CodeType cd = (CodeType) dt;
            if (!valFlag)
                val += CdaGeneratorUtils.getXmlForCD(elName, cd.getCode());
            else
                val += CdaGeneratorUtils.getXmlForValueString(cd.getCode());
        } else if (dt instanceof StringType) {
            StringType st = (StringType) dt;
            if (!valFlag)
                val += CdaGeneratorUtils.getXmlForText(elName, st.getValue());
            else
                val += CdaGeneratorUtils.getXmlForValueString(st.getValue());
        }
        logger.debug("Printing the class name {}", dt.getClass());
        return val;
    }
    if (!valFlag)
        val += CdaGeneratorUtils.getNFXMLForElement(elName, CdaGeneratorConstants.NF_NI);
    else
        val += CdaGeneratorUtils.getNFXmlForValueString(CdaGeneratorConstants.NF_NI);
    return val;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r4.model.Quantity) Period(org.hl7.fhir.r4.model.Period) CodeType(org.hl7.fhir.r4.model.CodeType) List(java.util.List) ArrayList(java.util.ArrayList) Timing(org.hl7.fhir.r4.model.Timing) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 64 with DateTimeType

use of org.hl7.fhir.r4.model.DateTimeType in project eCRNow by drajer-health.

the class CdaHeaderGenerator method getPatientDetails.

public static String getPatientDetails(Patient p, LaunchDetails details) {
    StringBuilder patientDetails = new StringBuilder();
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    List<Identifier> ids = CdaFhirUtilities.getIdentifierForType(p.getIdentifier(), CdaFhirEnumConstants.FHIR_ID_TYPE_MR);
    Boolean addOnce = true;
    if (ids != null && !ids.isEmpty()) {
        for (Identifier id : ids) {
            if (!StringUtils.isEmpty(id.getSystem()) && !StringUtils.isEmpty(id.getValue())) {
                logger.debug("Found Identifier with Type MR");
                String system = CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId());
                patientDetails.append(CdaGeneratorUtils.getXmlForII(system, id.getValue()));
            } else {
                logger.debug("Using Resource Identifier as id");
                if (addOnce) {
                    patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
                    addOnce = false;
                }
            }
        }
    } else {
        logger.debug("Using Resource Identifier as id");
        patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
    }
    // Add Address.
    patientDetails.append(CdaFhirUtilities.getAddressXml(p.getAddress()));
    // Add Telecom (Phone)
    patientDetails.append(CdaFhirUtilities.getTelecomXml(p.getTelecom(), false));
    // Add Telecom (Email)
    patientDetails.append(CdaFhirUtilities.getEmailXml(p.getTelecom()));
    // Add patient
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getNameXml(p.getName()));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getGenderXml(p.getGenderElement().getValue()));
    patientDetails.append(CdaFhirUtilities.getDateTypeXml(p.getBirthDateElement(), CdaGeneratorConstants.BIRTH_TIME_EL_NAME));
    if (p.getDeceased() == null || (p.getDeceased() != null && p.getDeceased().isEmpty())) {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_FALSE));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_TRUE));
        if (p.getDeceased() instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) p.getDeceased();
            patientDetails.append(CdaFhirUtilities.getDateTimeTypeXml(d, CdaGeneratorConstants.SDTC_DECEASED_TIME));
        } else {
            patientDetails.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.SDTC_DECEASED_TIME, CdaGeneratorConstants.NF_NI));
        }
    }
    Coding race = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_RACE_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (race != null && race.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, race.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, race.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    Coding ethnicity = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_ETHNICITY_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (ethnicity != null && ethnicity.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, ethnicity.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, ethnicity.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    // Adding Guardian
    if (p.getContact() != null && !p.getContact().isEmpty()) {
        ContactComponent guardianContact = CdaFhirUtilities.getGuardianContact(p.getContact());
        if (guardianContact != null) {
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
            // Add address if found
            if (guardianContact.getAddress() != null) {
                logger.debug("Adding Address for Guardian");
                List<Address> addrs = new ArrayList<>();
                addrs.add(guardianContact.getAddress());
                patientDetails.append(CdaFhirUtilities.getAddressXml(addrs));
            }
            // Add Telecom
            patientDetails.append(CdaFhirUtilities.getTelecomXml(guardianContact.getTelecom(), false));
            patientDetails.append(CdaFhirUtilities.getEmailXml(guardianContact.getTelecom()));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
            List<HumanName> names = new ArrayList<>();
            names.add(guardianContact.getName());
            patientDetails.append(CdaFhirUtilities.getNameXml(names));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
        }
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    Coding language = CdaFhirUtilities.getLanguageForCodeSystem(p.getCommunication(), CdaGeneratorConstants.FHIR_LANGUAGE_CODESYSTEM_URL);
    if (language != null && language.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, language.getCode()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    return patientDetails.toString();
}
Also used : Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) HumanName(org.hl7.fhir.r4.model.HumanName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) ContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent)

Example 65 with DateTimeType

use of org.hl7.fhir.r4.model.DateTimeType in project nia-patient-switching-standard-adaptor by NHSDigital.

the class MedicationStatementMapperTest method When_MappingPrescribeResourceWithNoOptionals_Expect_AllFieldsToBeMappedCorrectly.

@Test
public void When_MappingPrescribeResourceWithNoOptionals_Expect_AllFieldsToBeMappedCorrectly() {
    var ehrExtract = unmarshallEhrExtract("ehrExtract3.xml");
    var medicationStatement = unmarshallMedicationStatement("medicationStatementAuthoriseAllOptionals_MedicationStatement.xml");
    var authorise = medicationStatement.getComponent().stream().filter(RCMRMT030101UK04Component2::hasEhrSupplyAuthorise).map(RCMRMT030101UK04Component2::getEhrSupplyAuthorise).findFirst();
    when(medicationMapper.extractMedicationReference(any())).thenReturn(Optional.of(new Reference(new IdType(ResourceType.Medication.name(), MEDICATION_ID))));
    assertThat(authorise.isPresent()).isTrue();
    var medicationStatement1 = medicationStatementMapper.mapToMedicationStatement(ehrExtract, medicationStatement, authorise.get(), PRACTISE_CODE, new DateTimeType());
    var lastIssuedDate = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-MedicationStatementLastIssueDate-1");
    assertThat(lastIssuedDate.size()).isEqualTo(1);
    var dateTime = (DateTimeType) lastIssuedDate.get(0).getValue();
    assertThat(dateTime.getValue()).isEqualTo(DateFormatUtil.parseToDateTimeType("20060428").getValue());
    var prescribingAgency = medicationStatement1.getExtensionsByUrl("https://fhir.nhs.uk/STU3/StructureDefinition/Extension-CareConnect-GPC-PrescribingAgency-1");
    assertThat(prescribingAgency.size()).isEqualTo(1);
    assertThat(medicationStatement1.getBasedOnFirstRep().getReferenceElement().getIdPart()).isEqualTo(TEST_ID);
    assertThat(medicationStatement1.getStatus()).isEqualTo(ACTIVE);
    assertThat(medicationStatement1.getMedicationReference().getReferenceElement().getIdPart()).isEqualTo(MEDICATION_ID);
    assertThat(medicationStatement1.getTaken()).isEqualTo(UNK);
    assertThat(medicationStatement1.getDosageFirstRep().getText()).isEqualTo(TAKE_ONE_DAILY);
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Reference(org.hl7.fhir.dstu3.model.Reference) RCMRMT030101UK04Component2(org.hl7.v3.RCMRMT030101UK04Component2) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Aggregations

DateTimeType (org.hl7.fhir.r4.model.DateTimeType)65 Date (java.util.Date)28 Test (org.junit.Test)25 Coding (org.hl7.fhir.r4.model.Coding)23 DateTimeType (org.hl7.fhir.dstu3.model.DateTimeType)18 Period (org.hl7.fhir.r4.model.Period)18 ArrayList (java.util.ArrayList)17 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)17 Observation (org.hl7.fhir.r4.model.Observation)16 Test (org.junit.jupiter.api.Test)16 Patient (org.hl7.fhir.r4.model.Patient)14 DateTimeType (org.hl7.fhir.r4b.model.DateTimeType)14 HashMap (java.util.HashMap)13 DateTimeType (org.hl7.fhir.r5.model.DateTimeType)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 Reference (org.hl7.fhir.r4.model.Reference)12 List (java.util.List)11 Reference (org.hl7.fhir.dstu3.model.Reference)11 FHIRException (org.hl7.fhir.exceptions.FHIRException)11 Resource (org.hl7.fhir.r4.model.Resource)11