use of ca.uhn.fhir.model.dstu2.resource.Patient.Contact in project eCRNow by drajer-health.
the class Dstu2CdaHeaderGenerator method getPatientDetails.
public static String getPatientDetails(Dstu2FhirData data, 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));
IdentifierDt id = Dstu2CdaFhirUtilities.getIdentifierForType(p.getIdentifier(), IdentifierTypeCodesEnum.MR);
if (id != null) {
if (!StringUtils.isEmpty(id.getSystem()) && !StringUtils.isEmpty(id.getValue())) {
logger.info(" Found Identifier with Type MR ");
String system = CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId());
patientDetails.append(CdaGeneratorUtils.getXmlForII(system, id.getValue()));
} else {
logger.info(" Using Resource Identifier as id ");
;
patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId().toString()));
}
} else {
logger.info(" Using Resource Identifier as id ");
;
patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId().toString()));
}
// Add Address.
patientDetails.append(Dstu2CdaFhirUtilities.getAddressXml(p.getAddress()));
// Add Telecom
patientDetails.append(Dstu2CdaFhirUtilities.getTelecomXml(p.getTelecom()));
// Add patient
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_EL_NAME));
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
patientDetails.append(Dstu2CdaFhirUtilities.getNameXml(p.getName()));
patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
patientDetails.append(Dstu2CdaFhirUtilities.getGenderXml(p.getGenderElement()));
patientDetails.append(Dstu2CdaFhirUtilities.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 DateTimeDt) {
DateTimeDt d = (DateTimeDt) p.getDeceased();
patientDetails.append(CdaGeneratorUtils.getXmlForEffectiveTime(CdaGeneratorConstants.SDTC_DECEASED_TIME, d.getValue().toString()));
} else {
patientDetails.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.SDTC_DECEASED_TIME, CdaGeneratorConstants.NF_NI));
}
}
CodingDt race = Dstu2CdaFhirUtilities.getCodingExtension(p.getUndeclaredExtensions(), CdaGeneratorConstants.FHIR_ARGO_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));
}
CodingDt ethnicity = Dstu2CdaFhirUtilities.getCodingExtension(p.getUndeclaredExtensions(), CdaGeneratorConstants.FHIR_ARGO_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 details for patient
if (p.getContact() != null && p.getContact().size() > 0) {
// Add Guardian element
Contact guardianContact = Dstu2CdaFhirUtilities.getGuardianContact(p.getContact());
if (guardianContact != null) {
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
// Add Telecom
patientDetails.append(Dstu2CdaFhirUtilities.getTelecomXml(guardianContact.getTelecom()));
patientDetails.append(Dstu2CdaFhirUtilities.getEmailXml(guardianContact.getTelecom()));
// Add Name
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
patientDetails.append(Dstu2CdaFhirUtilities.getNameXml(guardianContact.getName()));
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));
}
}
// Add language communication
patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
CodingDt language = Dstu2CdaFhirUtilities.getLanguage(p.getCommunication());
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();
}
Aggregations