Search in sources :

Example 16 with DateTimeType

use of org.hl7.fhir.r5.model.DateTimeType in project openmrs-module-fhir2 by openmrs.

the class PatientTranslatorImpl method toFhirResource.

@Override
public Patient toFhirResource(@Nonnull org.openmrs.Patient openmrsPatient) {
    notNull(openmrsPatient, "The Openmrs Patient object should not be null");
    Patient patient = new Patient();
    patient.setId(openmrsPatient.getUuid());
    patient.setActive(!openmrsPatient.getVoided());
    for (PatientIdentifier identifier : openmrsPatient.getActiveIdentifiers()) {
        patient.addIdentifier(identifierTranslator.toFhirResource(identifier));
    }
    for (PersonName name : openmrsPatient.getNames()) {
        patient.addName(nameTranslator.toFhirResource(name));
    }
    if (openmrsPatient.getGender() != null) {
        patient.setGender(genderTranslator.toFhirResource(openmrsPatient.getGender()));
    }
    patient.setBirthDateElement(birthDateTranslator.toFhirResource(openmrsPatient));
    if (openmrsPatient.getDead()) {
        if (openmrsPatient.getDeathDate() != null) {
            patient.setDeceased(new DateTimeType(openmrsPatient.getDeathDate()));
        } else {
            patient.setDeceased(new BooleanType(true));
        }
    } else {
        patient.setDeceased(new BooleanType(false));
    }
    for (PersonAddress address : openmrsPatient.getAddresses()) {
        patient.addAddress(addressTranslator.toFhirResource(address));
    }
    patient.setTelecom(getPatientContactDetails(openmrsPatient));
    patient.getMeta().setLastUpdated(openmrsPatient.getDateChanged());
    patient.addContained(provenanceTranslator.getCreateProvenance(openmrsPatient));
    patient.addContained(provenanceTranslator.getUpdateProvenance(openmrsPatient));
    return patient;
}
Also used : PersonName(org.openmrs.PersonName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) PersonAddress(org.openmrs.PersonAddress) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 17 with DateTimeType

use of org.hl7.fhir.r5.model.DateTimeType in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConditionBundleToDtoConverterBase method conditionInfoToDto.

protected T conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    T conditionDto = newConditionDtoImpl();
    Condition condition = conditionInfo.getCondition();
    conditionDto.setId(condition.getIdElement().getIdPart());
    conditionDto.setName(codeableConceptToStringConverter.convert(condition.getCode()));
    Coding categoryCoding = FhirUtil.findCoding(condition.getCategory(), SDOHMappings.getInstance().getSystem());
    // TODO remove this in future. Fow now two different categories might be used before discussed.
    if (categoryCoding == null) {
        categoryCoding = FhirUtil.findCoding(condition.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
    }
    if (categoryCoding == null) {
        conditionDto.getErrors().add("SDOH category is not found.");
    } else {
        conditionDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
    }
    Optional<Coding> icdCodeCodingOptional = findCode(condition.getCode(), System.ICD_10);
    if (icdCodeCodingOptional.isPresent()) {
        Coding icdCodeCoding = icdCodeCodingOptional.get();
        conditionDto.setIcdCode(new CodingDto(icdCodeCoding.getCode(), icdCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("ICD-10 code is not found.");
    }
    Optional<Coding> snomedCodeCodingOptional = findCode(condition.getCode(), System.SNOMED);
    if (snomedCodeCodingOptional.isPresent()) {
        Coding snomedCodeCoding = snomedCodeCodingOptional.get();
        conditionDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
    } else {
        conditionDto.getErrors().add("SNOMED-CT code is not found.");
    }
    QuestionnaireResponse questionnaireResponse = conditionInfo.getQuestionnaireResponse();
    if (questionnaireResponse != null) {
        conditionDto.setAssessmentDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
        Questionnaire questionnaire = conditionInfo.getQuestionnaire();
        if (questionnaire != null) {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaire.getTitle()));
        } else {
            conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaireResponse.getQuestionnaire()));
            conditionDto.getErrors().add("Based on QuestionnaireResponse doesn't have a matching Questionnaire to get a title from. Using URL " + "instead.");
        }
    } else {
        conditionDto.setBasedOn(new StringTypeDto(condition.getEvidenceFirstRep().getCodeFirstRep().getText()));
        Reference recorder = condition.getRecorder();
        conditionDto.setAuthoredBy(new ReferenceDto(recorder.getReferenceElement().getIdPart(), recorder.getDisplay()));
    }
    // abatement must be available for all resolved condition
    if (ConditionClinicalStatusCodes.RESOLVED.toCode().equals(condition.getClinicalStatus().getCodingFirstRep().getCode())) {
        if (condition.getAbatement() instanceof DateTimeType) {
            conditionDto.setResolutionDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getAbatement()));
        } else {
            conditionDto.getErrors().add("Condition is resolved but an abatement property is missing or not of a DateTimeType type.");
        }
    }
    return conditionDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 18 with DateTimeType

use of org.hl7.fhir.r5.model.DateTimeType in project Gravity-SDOH-Exchange-RI by FHIR.

the class ProblemBundleToDtoConverter method conditionInfoToDto.

@Override
protected ProblemDto conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    // TODO refactor this. Avoid manual casting. Refactor the design of a base class instead.
    Assert.isInstanceOf(ProblemInfoBundleExtractor.ProblemInfoHolder.class, conditionInfo, "conditionInfo must be a ProblemInfoHolder.");
    ProblemInfoBundleExtractor.ProblemInfoHolder probleminfo = (ProblemInfoBundleExtractor.ProblemInfoHolder) conditionInfo;
    Condition condition = probleminfo.getCondition();
    ProblemDto problemDto = super.conditionInfoToDto(probleminfo);
    // Onset must be available for the problem list items.
    if (condition.getOnset() != null) {
        problemDto.setStartDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getOnset()));
    } else {
        problemDto.getErrors().add("Condition is a problem-list-item but an onset property is missing or not of a DateTimeType " + "type.");
    }
    problemDto.getTasks().addAll(probleminfo.getTasks().stream().map(t -> new TaskInfoDto(t.getId(), t.getName(), t.getStatus())).collect(Collectors.toList()));
    problemDto.getGoals().addAll(probleminfo.getGoals().stream().map(t -> new GoalInfoDto(t.getId(), t.getName(), t.getStatus())).collect(Collectors.toList()));
    return problemDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) GoalInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalInfoDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) ProblemInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ProblemInfoBundleExtractor) ProblemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto)

Example 19 with DateTimeType

use of org.hl7.fhir.r5.model.DateTimeType in project integration-adaptor-111 by nhsconnect.

the class DateUtil method parse.

public static DateTimeType parse(String dateToParse) {
    DateFormat format = getFormat(dateToParse);
    SimpleDateFormat formatter = getFormatter(format);
    try {
        Date date = formatter.parse(dateToParse);
        return new DateTimeType(date, format.getPrecision(), TimeZone.getTimeZone(ZoneOffset.UTC));
    } catch (ParseException e) {
        throw new IllegalStateException(String.format(ERROR_MESSAGE, dateToParse), e);
    }
}
Also used : DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat) DateTimeParseException(java.time.format.DateTimeParseException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 20 with DateTimeType

use of org.hl7.fhir.r5.model.DateTimeType in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method execute.

private void execute(String base, String dest) throws IOException {
    CodeSystem cs = makeMMSCodeSystem();
    JsonObject version = fetchJson(Utilities.pathURL(base, "/icd/release/11/mms"));
    String[] p = version.get("latestRelease").getAsString().split("\\/");
    cs.setVersion(p[6]);
    JsonObject root = fetchJson(url(base, version.get("latestRelease").getAsString()));
    cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
    for (JsonElement child : root.getAsJsonArray("child")) {
        processMMSEntity(cs, base, child.getAsString(), cs.addConcept(), dest);
        System.out.println();
    }
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-mms.xml")), cs);
    makeFullVs(dest, cs);
    cs = makeEntityCodeSystem();
    root = fetchJson(Utilities.pathURL(base, "/icd/entity"));
    cs.setVersion(root.get("releaseId").getAsString());
    cs.setDateElement(new DateTimeType(root.get("releaseDate").getAsString()));
    cs.setTitle(readString(root, "title"));
    Set<String> ids = new HashSet<>();
    for (JsonElement child : root.getAsJsonArray("child")) {
        processEntity(cs, ids, base, tail(child.getAsString()), dest);
        System.out.println();
    }
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "icd-11-foundation.xml")), cs);
    makeFullVs2(dest, cs);
    System.out.println("finished");
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) JsonElement(com.google.gson.JsonElement) FileOutputStream(java.io.FileOutputStream) JsonObject(com.google.gson.JsonObject) HashSet(java.util.HashSet)

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