package com.smartor.yiwudataanalysis;
|
|
import ca.uhn.hl7v2.HL7Exception;
|
import ca.uhn.hl7v2.model.Message;
|
import ca.uhn.hl7v2.model.Structure;
|
import ca.uhn.hl7v2.model.v24.datatype.*;
|
import ca.uhn.hl7v2.model.v24.segment.DG1;
|
import ca.uhn.hl7v2.model.v24.segment.PID;
|
import ca.uhn.hl7v2.model.v24.segment.PV1;
|
import ca.uhn.hl7v2.model.v24.segment.PV2;
|
import com.ruoyi.common.enums.AdmTypeEnum;
|
import com.ruoyi.common.enums.LevelHospEnum;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.smartor.domain.HospitalRecord;
|
import com.smartor.domain.HospitalUserinfo;
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.time.Year;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
//入院数据
|
public class ADT_A01 {
|
//解析PID
|
public List<Object> explainPID(Message message, String dataInfo) throws HL7Exception {
|
//解析PID(患者基本信息)
|
PID pid = (PID) message.get("PID");
|
|
//患者主索引信息
|
CX pid2_patientID = pid.getPid2_PatientID();
|
//患者全院唯一标识(患者主索引/ID)
|
String patientID = pid2_patientID.getID().encode();
|
//VIP-先诊疗后付费标志(0/1)
|
String cd = pid2_patientID.getCheckDigit().encode();
|
|
//患者相关 ID^^^授权机构
|
CX[] pid3_patientIdentifierList = pid.getPid3_PatientIdentifierList();
|
if (pid3_patientIdentifierList != null && pid3_patientIdentifierList.length > 0) {
|
for (CX cx : pid3_patientIdentifierList) {
|
//患者相关ID
|
String hzxgID = cx.getID().encode();
|
//分配患者 ID 机构
|
String patiendOrgan = cx.getAssigningAuthority().encode();
|
}
|
}
|
|
//门诊不填,住院必填
|
CX[] pid4_alternatePatientIDPID = pid.getPid4_AlternatePatientIDPID();
|
if (pid4_alternatePatientIDPID != null && pid4_alternatePatientIDPID.length > 0) {
|
for (CX cx : pid4_alternatePatientIDPID) {
|
//非婴儿 0 婴儿 1
|
String s = cx.getID().encode();
|
// 0/空-不需要保密; 1-保密
|
String s1 = cx.getIdentifierTypeCode().encode();
|
}
|
}
|
|
//患者姓名
|
XPN[] pid5_patientName = pid.getPid5_PatientName();
|
String patientName = "";
|
String pinyin = "";
|
if (pid5_patientName != null && pid5_patientName.length > 0) {
|
for (XPN xpn : pid5_patientName) {
|
//拼音
|
pinyin = xpn.getFamilyName().encode();
|
//患者姓名
|
patientName = xpn.getGivenName().encode();
|
}
|
}
|
|
|
//出生日期
|
String birthday = pid.getPid7_DateTimeOfBirth().encode();
|
SimpleDateFormat inputFormatt = new SimpleDateFormat("yyyyMMddHHmmss"); // 输入日期格式
|
Date date = null; // 解析为Date对象
|
try {
|
date = inputFormatt.parse(birthday);
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
SimpleDateFormat outputFormatt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 输出日期格式
|
String birthdatTime = outputFormatt.format(date);
|
|
|
//性别 1男 2女
|
String xb = pid.getPid8_AdministrativeSex().encode();
|
|
//血型信息
|
CE[] pid10_race = pid.getPid10_Race();
|
String xxdm = "";
|
String xxmc = "";
|
String rhxxdm = "";
|
String rhxxmc = "";
|
if (pid10_race != null && pid10_race.length > 0) {
|
for (CE ce : pid10_race) {
|
//血型代码
|
xxdm = ce.getCe1_Identifier().encode();
|
//血型名称
|
xxmc = ce.getCe2_Text().encode();
|
//rh血型代码
|
rhxxdm = ce.getCe4_AlternateIdentifier().encode();
|
//rh血型名称
|
rhxxmc = ce.getCe5_AlternateText().encode();
|
}
|
}
|
//地址信息
|
XAD[] pid11_patientAddress = pid.getPid11_PatientAddress();
|
String xxdzxx = null;
|
String streetName = null;
|
String dwellingNumber = null;
|
String otherDesignation = null;
|
String city = null;
|
String province = null;
|
if (pid11_patientAddress != null && pid11_patientAddress.length > 0) {
|
for (XAD xad : pid11_patientAddress) {
|
//详细地址信息
|
xxdzxx = xad.getXad1_StreetAddress().getSad1_StreetOrMailingAddress().encode();
|
//街道信息(村/街/道)
|
streetName = xad.getXad1_StreetAddress().getStreetName().encode();
|
//门牌号码
|
dwellingNumber = xad.getXad1_StreetAddress().getDwellingNumber().encode();
|
//县地区(县)
|
otherDesignation = xad.getXad2_OtherDesignation().encode();
|
//城市(市)
|
city = xad.getXad3_City().encode();
|
//省
|
province = xad.getXad4_StateOrProvince().encode();
|
//地址类型(参考字典)
|
String addressType = xad.getXad7_AddressType().encode();
|
//乡镇信息
|
String designation = xad.getXad8_OtherGeographicDesignation().encode();
|
//县地区编码
|
String parishCode = xad.getXad9_CountyParishCode().encode();
|
//街道标准编码(保留)
|
String censusTract = xad.getXad10_CensusTract().encode();
|
}
|
}
|
|
//个人电话
|
XTN[] pid13_phoneNumberHome = pid.getPid13_PhoneNumberHome();
|
String phone = null;
|
if (pid13_phoneNumberHome != null && pid13_phoneNumberHome.length > 0) {
|
for (XTN xtn : pid13_phoneNumberHome) {
|
//电话类型代码(参考字典)
|
String lxdm = xtn.getTelecommunicationEquipmentType().encode();
|
//电话号码
|
phone = xtn.getPhoneNumber().encode();
|
}
|
}
|
|
//工作电话
|
XTN[] pid14_phoneNumberBusiness = pid.getPid14_PhoneNumberBusiness();
|
String phoneNumberWork = "";
|
if (pid14_phoneNumberBusiness != null && pid14_phoneNumberBusiness.length > 0) {
|
for (XTN xtn : pid14_phoneNumberBusiness) {
|
//工作电话
|
phoneNumberWork = xtn.getPhoneNumber().encode();
|
}
|
}
|
|
//婚姻状况代码
|
String identifier = pid.getPid16_MaritalStatus().getIdentifier().encode();
|
//婚姻状况名称
|
String text = pid.getPid16_MaritalStatus().getText().encode();
|
|
//证件号码
|
String id = pid.getPid18_PatientAccountNumber().getID().encode();
|
//证件类型(参考字典)
|
String assigningAuthority = pid.getPid18_PatientAccountNumber().getAssigningAuthority().encode();
|
//证件不详原因
|
HD assigningFacility = pid.getPid18_PatientAccountNumber().getAssigningFacility();
|
//原因代码
|
String namespaceID = assigningFacility.getNamespaceID().encode();
|
//原因名称
|
String universalID = assigningFacility.getUniversalID().encode();
|
|
//身份证号
|
String SSNNumberPatient = pid.getPid19_SSNNumberPatient().encode();
|
|
CX[] pid21_motherSIdentifier = pid.getPid21_MotherSIdentifier();
|
String mqid = "";
|
if (pid21_motherSIdentifier != null && pid21_motherSIdentifier.length > 0) {
|
for (CX cx : pid21_motherSIdentifier) {
|
//母亲住院 ID(门诊不填,住院必填)
|
mqid = cx.getID().encode();
|
}
|
}
|
|
//民族
|
CE[] pid22_ethnicGroup = pid.getPid22_EthnicGroup();
|
String mztext = null;
|
if (pid22_ethnicGroup != null && pid22_ethnicGroup.length > 0) {
|
for (CE ce : pid22_ethnicGroup) {
|
//民族 ID
|
String Identifier = ce.getIdentifier().encode();
|
//民族名称
|
mztext = ce.getText().encode();
|
}
|
}
|
|
//出生地
|
String encode = pid.getPid23_BirthPlace().encode();
|
|
//职业
|
CE[] citizenship = pid.getPid26_Citizenship();
|
String zytext = "";
|
String Identifier = "";
|
if (citizenship != null && citizenship.length > 0) {
|
for (CE ce : citizenship) {
|
//职业代码
|
Identifier = ce.getIdentifier().encode();
|
//职业名称
|
zytext = ce.getText().encode();
|
}
|
}
|
|
//国籍代码
|
String Identifier2 = pid.getPid28_Nationality().getIdentifier().encode();
|
//国籍名称
|
String gjtext = pid.getPid28_Nationality().getText().encode();
|
|
//死胎标志 默认是 0/空,1-死胎
|
String patientDeathIndicator = pid.getPid30_PatientDeathIndicator().encode();
|
|
//黑名单病人
|
IS[] pid32_identityReliabilityCode = pid.getPid32_IdentityReliabilityCode();
|
|
//患者属性 (参考字典)
|
//格式如:0101000
|
//说明:由多位组成,第一
|
//位表示属性 1 的值,
|
// 第二位表示属性 2 的值。
|
String hzIdentifier = pid.getPid38_ProductionClassCode().getIdentifier().encode();
|
|
//--------------------------------------------------------------
|
//解析 PV1(患者访问信息)
|
PV1 pv1 = (PV1) message.get("PV1");
|
|
//挂号序号或住院次数
|
String xh = pv1.getPv11_SetIDPV1().encode();
|
|
//患者分类 E:急诊; I:住院; O:门诊;T:体检
|
String patientClass = pv1.getPv12_PatientClass().encode();
|
|
//患者位置信息
|
PL pv13_assignedPatientLocation = pv1.getPv13_AssignedPatientLocation();
|
//当前病区
|
String bq = pv13_assignedPatientLocation.getPointOfCare().encode();
|
//当前病房
|
String room = pv13_assignedPatientLocation.getRoom().encode();
|
//当前病床
|
String bad = pv13_assignedPatientLocation.getBed().encode();
|
//当前科室 ID
|
String namespaceID1 = pv13_assignedPatientLocation.getFacility().getNamespaceID().encode();
|
//当前科室名称
|
String ksuniversalID = pv13_assignedPatientLocation.getFacility().getUniversalID().encode();
|
//当前床位名称
|
String locationStatus = pv13_assignedPatientLocation.getLocationStatus().encode();
|
//当前病区名称
|
String personLocationType = pv13_assignedPatientLocation.getPersonLocationType().encode();
|
|
//入院类型 R:常规 E:紧急 W:留观 其余见 HL7 约定
|
String admissionType = pv1.getPv14_AdmissionType().encode();
|
|
//转前位置信息
|
//转前病区
|
String pointOfCare = pv1.getPv16_PriorPatientLocation().getPointOfCare().encode();
|
//转前病房
|
String room1 = pv1.getPv16_PriorPatientLocation().getRoom().encode();
|
//转前病床
|
String bed = pv1.getPv16_PriorPatientLocation().getBed().encode();
|
//转前科室
|
HD facility = pv1.getPv16_PriorPatientLocation().getFacility();
|
//转前科室 ID
|
String namespaceID2 = facility.getNamespaceID().encode();
|
//转前科室名称
|
String universalID1 = facility.getUniversalID().encode();
|
//转前床位名称
|
String locationStatus1 = pv1.getPv16_PriorPatientLocation().getLocationStatus().encode();
|
//转前病区名称
|
String personLocationType1 = pv1.getPv16_PriorPatientLocation().getPersonLocationType().encode();
|
|
//门诊为就诊医生
|
XCN[] pv17_attendingDoctor = pv1.getPv17_AttendingDoctor();
|
String IDNumber = null;
|
String givenName = null;
|
if (pv17_attendingDoctor != null && pv17_attendingDoctor.length > 0) {
|
for (XCN xcn : pv17_attendingDoctor) {
|
//主治医生 ID
|
IDNumber = xcn.getIDNumber().encode();
|
//主治医生姓名
|
givenName = xcn.getGivenName().encode();
|
//医疗组信息
|
HD xcn14_assigningFacility = xcn.getXcn14_AssigningFacility();
|
//医疗组名称
|
String universalID2 = xcn14_assigningFacility.getNamespaceID().encode();
|
//收治医生 ID
|
String universalID3 = xcn14_assigningFacility.getUniversalID().encode();
|
}
|
}
|
|
//挂号类别 1-普通;2-急诊 4-专家;6-老教授
|
String pv110_hospitalService = pv1.getPv110_HospitalService().encode();
|
|
//预收入院检验标识 默认为空 0-否;1-是
|
String pv112_preadmitTestIndicator = pv1.getPv112_PreadmitTestIndicator().encode();
|
|
//再次入院标志 默认为空, “R”表示再入院
|
String pv113_reAdmissionIndicator = pv1.getPv113_ReAdmissionIndicator().encode();
|
|
//入院途径
|
String pv114_admitSource = pv1.getPv114_AdmitSource().encode();
|
|
//入院医生
|
XCN[] pv117_admittingDoctor = pv1.getPv117_AdmittingDoctor();
|
if (pv117_admittingDoctor != null && pv117_admittingDoctor.length > 0) {
|
for (XCN xcn : pv117_admittingDoctor) {
|
//员工号
|
String idNumber = xcn.getIDNumber().encode();
|
//姓名
|
String givenName2 = xcn.getGivenName().encode();
|
}
|
}
|
|
//费用类别
|
String pv118_patientType = pv1.getPv118_PatientType().encode();
|
|
//就诊 ID 或者患者住院 ID
|
String id1 = pv1.getPv119_VisitNumber().getID().encode();
|
|
//优惠类别
|
FC[] pv120_financialClass = pv1.getPv120_FinancialClass();
|
String financialClass = "";
|
if (pv120_financialClass != null && pv120_financialClass.length > 0) {
|
for (FC fc : pv120_financialClass) {
|
financialClass = fc.getFinancialClass().encode();
|
}
|
}
|
|
//费用性质
|
String pv121_chargePriceIndicator = pv1.getPv121_ChargePriceIndicator().encode();
|
|
//入科日期
|
DT[] pv125_contractEffectiveDate = pv1.getPv125_ContractEffectiveDate();
|
String rkdate = null;
|
if (pv125_contractEffectiveDate != null && pv125_contractEffectiveDate.length > 0) {
|
for (DT dt : pv125_contractEffectiveDate) {
|
|
SimpleDateFormat inputFormattt = new SimpleDateFormat("yyyyMMdd"); // 输入日期格式
|
Date date22 = null; // 解析为Date对象
|
try {
|
date22 = inputFormattt.parse(dt.encode());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
SimpleDateFormat outputFormat2 = new SimpleDateFormat("yyyy-MM-dd"); // 输出日期格式
|
rkdate = outputFormat2.format(date22);
|
}
|
}
|
|
//账户冻结建议
|
String pv128_interestCode = pv1.getPv128_InterestCode().encode();
|
|
//欠费冻结标识 默认是 0/空 1:冻结;2:永不冻结
|
String pv129_transferToBadDebtCode = pv1.getPv129_TransferToBadDebtCode().encode();
|
|
//冻结日期
|
String pv130_transferToBadDebtDate = pv1.getPv130_TransferToBadDebtDate().encode();
|
|
//解冻日期
|
String pv135_deleteAccountDate = pv1.getPv135_DeleteAccountDate().encode();
|
|
//离院去向/转归
|
String pv136_dischargeDisposition = pv1.getPv136_DischargeDisposition().encode();
|
|
//离院去往位置
|
String pv137_dischargedToLocation = pv1.getPv137_DischargedToLocation().getDischargeLocation().encode();
|
|
//饮食类型ID
|
String identifier1 = pv1.getPv138_DietType().getIdentifier().encode();
|
//饮食类型名称
|
String text1 = pv1.getPv138_DietType().getText().encode();
|
|
//挂号的上下午标志 0-上午;1-下午;2-晚上
|
String pv139_servicingFacility = pv1.getPv139_ServicingFacility().encode();
|
|
//科室 ID^^^院区 ID
|
PL pv142_pendingLocation = pv1.getPv142_PendingLocation();
|
//门诊就诊科室 ID
|
String mzpointOfCare = pv142_pendingLocation.getPointOfCare().encode();
|
//住院院区 ID
|
String namespaceID3 = pv142_pendingLocation.getFacility().getNamespaceID().encode();
|
//应用 ID
|
String universalIDType = pv142_pendingLocation.getFacility().getUniversalIDType().encode();
|
//医疗机构代码
|
String personLocationType2 = pv142_pendingLocation.getPersonLocationType().encode();
|
//医疗机构名称
|
String building = pv142_pendingLocation.getBuilding().encode();
|
|
//就诊/住院时间
|
String pv144_admitDateTime = pv1.getPv144_AdmitDateTime().encode();
|
|
//出院时间 A03 消息必填
|
TS[] pv145_dischargeDateTime = pv1.getPv145_DischargeDateTime();
|
String dischargeDateTime = null;
|
if (pv145_dischargeDateTime != null && pv145_dischargeDateTime.length > 0) {
|
TS ts = pv145_dischargeDateTime[0];
|
// Date date2 = new Date(Long.valueOf(ts.encode()));
|
// SimpleDateFormat sdff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
// String dischargeDateTime = sdff.format(date2);
|
|
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss"); // 输入日期格式
|
Date date2 = null; // 解析为Date对象
|
try {
|
date2 = inputFormat.parse(ts.encode());
|
} catch (ParseException e) {
|
e.printStackTrace();
|
}
|
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 输出日期格式
|
dischargeDateTime = outputFormat.format(date2);
|
}
|
//访问标示
|
String visitIndicator = pv1.getPv151_VisitIndicator().encode();
|
|
//操作人信息
|
XCN[] pv152_otherHealthcareProvider = pv1.getPv152_OtherHealthcareProvider();
|
if (pv152_otherHealthcareProvider != null && pv152_otherHealthcareProvider.length > 0) {
|
for (XCN xcn : pv152_otherHealthcareProvider) {
|
//员工号
|
String IDNumber2 = xcn.getIDNumber().encode();
|
//姓名
|
String givenName3 = xcn.getGivenName().encode();
|
}
|
}
|
//-----------------------------
|
PV2 pv2 = (PV2) message.get("PV2");
|
//实际住院天数
|
String pv211_actualLengthOfInpatientStay = pv2.getPv211_ActualLengthOfInpatientStay().encode();
|
|
//------------------------------------------
|
Structure[] dg1s = message.getAll("DG1");
|
String dg12_diagnosisCodingMethod = null;
|
String dg14_diagnosisDescription = null;
|
if (dg1s != null && dg1s.length > 0) {
|
for (Structure structure : dg1s) {
|
DG1 dg11 = (DG1) structure;
|
//序号
|
String dg1xh = dg11.getDg11_SetIDDG1().encode();
|
//诊断代码
|
dg12_diagnosisCodingMethod = dg11.getDg12_DiagnosisCodingMethod().encode();
|
//诊断名称
|
dg14_diagnosisDescription = dg11.getDg14_DiagnosisDescription().encode();
|
//诊断类型
|
String dg16_diagnosisType = dg11.getDg16_DiagnosisType().encode();
|
System.out.println(dg11);
|
|
}
|
}
|
|
//数据入库
|
HospitalRecord hospitalRecord = new HospitalRecord();
|
hospitalRecord.setCreateTime(new Date());
|
// hospitalRecord.setPatientID(patientID);
|
hospitalRecord.setPatientID(id1);
|
hospitalRecord.setOpreationTime(new Date());
|
//就诊号
|
hospitalRecord.setOutMedNO(id1);
|
//就诊类型描述(门诊、住院...)
|
hospitalRecord.setAdmTypeDesc(AdmTypeEnum.getDescByCode(patientClass));
|
//IMP 住院
|
hospitalRecord.setAdmTypeCode("IMP");
|
hospitalRecord.setAdmStatus("患者入院");
|
hospitalRecord.setEncOuthostype(LevelHospEnum.getDescByCode(pv136_dischargeDisposition));
|
hospitalRecord.setAdmDate(dischargeDateTime);
|
hospitalRecord.setEncPatName(patientName);
|
if (StringUtils.isNotEmpty(xb)) {
|
hospitalRecord.setEncPatGender(xb.equals(1) ? "男" : "女");
|
}
|
hospitalRecord.setEncPatBirthDate(birthdatTime);
|
//获取年龄
|
int currentYear = Year.now().getValue();
|
Integer integer = Integer.valueOf(birthdatTime.substring(0, 4));
|
Integer age = currentYear - integer;
|
hospitalRecord.setEncAgeValue(age.toString());
|
|
//主治医生编号
|
hospitalRecord.setDirectorCode(IDNumber);
|
//主治医生姓名
|
hospitalRecord.setDirectorName(givenName);
|
hospitalRecord.setEncAdmLocCode(namespaceID1);
|
hospitalRecord.setEncAdmLocName(ksuniversalID);
|
hospitalRecord.setEncDiagnosisCode(dg12_diagnosisCodingMethod);
|
hospitalRecord.setEncDiagnosisDesc(dg14_diagnosisDescription);
|
|
List<Object> objectList = new ArrayList<>();
|
// objectList.add(hospitalRecord);
|
|
HospitalUserinfo hospitalUserinfo = new HospitalUserinfo();
|
// hospitalUserinfo.setCreateTime(null);
|
// hospitalUserinfo.setPatientID(patientID);
|
hospitalUserinfo.setPatientID(id1);
|
hospitalUserinfo.setRegDate(rkdate);
|
hospitalUserinfo.setIdentityID(SSNNumberPatient);
|
hospitalUserinfo.setPatName(patientName);
|
hospitalUserinfo.setPhone(phone);
|
if (StringUtils.isNotEmpty(xb)) {
|
hospitalUserinfo.setPatSex(xb.equals(1) ? "男" : "女");
|
}
|
hospitalUserinfo.setBirthDate(birthdatTime);
|
hospitalUserinfo.setAddress(xxdzxx);
|
hospitalUserinfo.setAddProvince(province);
|
hospitalUserinfo.setAddCity(city);
|
hospitalUserinfo.setAddCounty(otherDesignation);
|
hospitalUserinfo.setAddTown(streetName);
|
hospitalUserinfo.setCountry(gjtext);
|
hospitalUserinfo.setNation(mztext);
|
hospitalUserinfo.setConPerPhone(phone);
|
hospitalUserinfo.setRegOrgDesc("义乌市第二人民医院");
|
hospitalUserinfo.setEncAdmSource(AdmTypeEnum.getDescByCode(patientClass));
|
objectList.add(hospitalRecord);
|
objectList.add(hospitalUserinfo);
|
|
return objectList;
|
|
}
|
}
|