fixed bug with uk zip code and add retrieved timestamp for dewars at the beamline
This commit is contained in:
parent
fd17c0e672
commit
6c88ff9651
@ -142,6 +142,7 @@ async def get_all_slots(db: Session = Depends(get_db)):
|
|||||||
slots_with_refill_time = []
|
slots_with_refill_time = []
|
||||||
|
|
||||||
for slot in slots:
|
for slot in slots:
|
||||||
|
# Initialize variables for slot-related data
|
||||||
time_until_refill = None
|
time_until_refill = None
|
||||||
retrievedTimestamp = None
|
retrievedTimestamp = None
|
||||||
beamlineLocation = None
|
beamlineLocation = None
|
||||||
@ -165,42 +166,35 @@ async def get_all_slots(db: Session = Depends(get_db)):
|
|||||||
else:
|
else:
|
||||||
time_until_refill = -1
|
time_until_refill = -1
|
||||||
|
|
||||||
# Get last retrieved timestamp
|
# Fetch the latest beamline event
|
||||||
last_retrieved_event = db.query(LogisticsEventModel) \
|
last_beamline_event = db.query(LogisticsEventModel) \
|
||||||
.join(DewarModel, DewarModel.id == LogisticsEventModel.dewar_id) \
|
.join(DewarModel, DewarModel.id == LogisticsEventModel.dewar_id) \
|
||||||
.filter(
|
.filter(
|
||||||
DewarModel.unique_id == slot.dewar.unique_id,
|
DewarModel.unique_id == slot.dewar.unique_id,
|
||||||
LogisticsEventModel.event_type == "retrieved"
|
LogisticsEventModel.event_type == "beamline"
|
||||||
) \
|
) \
|
||||||
.order_by(LogisticsEventModel.timestamp.desc()) \
|
.order_by(LogisticsEventModel.timestamp.desc()) \
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
if last_retrieved_event:
|
if last_beamline_event:
|
||||||
retrievedTimestamp = last_retrieved_event.timestamp.isoformat()
|
# Set retrievedTimestamp to the timestamp of the beamline event
|
||||||
retrieved = True
|
retrievedTimestamp = last_beamline_event.timestamp.isoformat()
|
||||||
|
|
||||||
# Determine the last event excluding refills
|
# Fetch the associated slot's label for beamlineLocation
|
||||||
last_event = db.query(LogisticsEventModel) \
|
associated_slot = db.query(SlotModel).filter(SlotModel.id == last_beamline_event.slot_id).first()
|
||||||
.join(DewarModel, DewarModel.id == LogisticsEventModel.dewar_id) \
|
|
||||||
.filter(
|
|
||||||
DewarModel.unique_id == slot.dewar.unique_id,
|
|
||||||
LogisticsEventModel.event_type != "refill"
|
|
||||||
) \
|
|
||||||
.order_by(LogisticsEventModel.timestamp.desc()) \
|
|
||||||
.first()
|
|
||||||
|
|
||||||
if last_event:
|
|
||||||
associated_slot = db.query(SlotModel).filter(SlotModel.id == last_event.slot_id).first()
|
|
||||||
beamlineLocation = associated_slot.label if associated_slot else None
|
beamlineLocation = associated_slot.label if associated_slot else None
|
||||||
at_beamline = last_event.event_type == "beamline"
|
|
||||||
|
|
||||||
# Corrected the contact_person assignment
|
# Mark as being at a beamline
|
||||||
|
at_beamline = True
|
||||||
|
|
||||||
|
# Correct the contact_person assignment
|
||||||
contact_person = None
|
contact_person = None
|
||||||
if slot.dewar and slot.dewar.contact_person:
|
if slot.dewar and slot.dewar.contact_person:
|
||||||
first_name = slot.dewar.contact_person.firstname
|
first_name = slot.dewar.contact_person.firstname
|
||||||
last_name = slot.dewar.contact_person.lastname
|
last_name = slot.dewar.contact_person.lastname
|
||||||
contact_person = f"{first_name} {last_name}"
|
contact_person = f"{first_name} {last_name}"
|
||||||
|
|
||||||
|
# Prepare the slot data for the response
|
||||||
slot_data = SlotSchema(
|
slot_data = SlotSchema(
|
||||||
id=slot.id,
|
id=slot.id,
|
||||||
qr_code=slot.qr_code,
|
qr_code=slot.qr_code,
|
||||||
@ -212,20 +206,19 @@ async def get_all_slots(db: Session = Depends(get_db)):
|
|||||||
dewar_name=slot.dewar.dewar_name if slot.dewar else None,
|
dewar_name=slot.dewar.dewar_name if slot.dewar else None,
|
||||||
time_until_refill=time_until_refill,
|
time_until_refill=time_until_refill,
|
||||||
at_beamline=at_beamline,
|
at_beamline=at_beamline,
|
||||||
retrieved=retrieved,
|
|
||||||
retrievedTimestamp=retrievedTimestamp,
|
retrievedTimestamp=retrievedTimestamp,
|
||||||
beamlineLocation=beamlineLocation,
|
beamlineLocation=beamlineLocation,
|
||||||
shipment_name=slot.dewar.shipment.shipment_name if slot.dewar and slot.dewar.shipment else None,
|
shipment_name=slot.dewar.shipment.shipment_name if slot.dewar and slot.dewar.shipment else None,
|
||||||
contact_person=contact_person,
|
contact_person=contact_person,
|
||||||
local_contact='local contact placeholder'
|
local_contact="local contact placeholder",
|
||||||
)
|
)
|
||||||
logger.info(f"Dewar retrieved: {retrieved}")
|
# Add updated slot data to the response list
|
||||||
logger.info(f"Dewar at: {beamlineLocation}")
|
|
||||||
slots_with_refill_time.append(slot_data)
|
slots_with_refill_time.append(slot_data)
|
||||||
|
|
||||||
return slots_with_refill_time
|
return slots_with_refill_time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.post("/dewar/refill", response_model=dict)
|
@router.post("/dewar/refill", response_model=dict)
|
||||||
async def refill_dewar(qr_code: str, db: Session = Depends(get_db)):
|
async def refill_dewar(qr_code: str, db: Session = Depends(get_db)):
|
||||||
logger.info(f"Refilling dewar with QR code: {qr_code}")
|
logger.info(f"Refilling dewar with QR code: {qr_code}")
|
||||||
|
@ -310,6 +310,7 @@ class SlotSchema(BaseModel):
|
|||||||
dewar_name: Optional[str]
|
dewar_name: Optional[str]
|
||||||
time_until_refill: Optional[int]
|
time_until_refill: Optional[int]
|
||||||
at_beamline: Optional[bool]
|
at_beamline: Optional[bool]
|
||||||
|
retrievedTimestamp: Optional[str]
|
||||||
beamlineLocation: Optional[str]
|
beamlineLocation: Optional[str]
|
||||||
shipment_name: Optional[str]
|
shipment_name: Optional[str]
|
||||||
contact_person: Optional[str]
|
contact_person: Optional[str]
|
||||||
|
@ -78,7 +78,11 @@ const ShipmentForm: React.FC<ShipmentFormProps> = ({ sx = {}, onCancel, refreshS
|
|||||||
|
|
||||||
const validateEmail = (email: string) => /\S+@\S+\.\S+/.test(email);
|
const validateEmail = (email: string) => /\S+@\S+\.\S+/.test(email);
|
||||||
const validatePhoneNumber = (phone: string) => /^\+?[1-9]\d{1,14}$/.test(phone);
|
const validatePhoneNumber = (phone: string) => /^\+?[1-9]\d{1,14}$/.test(phone);
|
||||||
const validateZipCode = (zipcode: string) => /^\d{5}(?:[-\s]\d{4})?$/.test(zipcode);
|
const validateZipCode = (zipcode: string) => {
|
||||||
|
const usZipCodeRegex = /^\d{4,5}(?:[-\s]\d{4})?$/;
|
||||||
|
const ukPostCodeRegex = /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i;
|
||||||
|
return usZipCodeRegex.test(zipcode) || ukPostCodeRegex.test(zipcode);
|
||||||
|
};
|
||||||
|
|
||||||
const isContactFormValid = () => {
|
const isContactFormValid = () => {
|
||||||
const { firstname, lastname, phone_number, email } = newContactPerson;
|
const { firstname, lastname, phone_number, email } = newContactPerson;
|
||||||
|
@ -51,19 +51,6 @@ const Storage: React.FC<StorageProps> = ({ name, selectedSlot, slotsData, onSele
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</StorageWrapper>
|
</StorageWrapper>
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
onClick={() => {
|
|
||||||
const selectedSlotData = slotsData.find(slot => slot.qr_code === selectedSlot);
|
|
||||||
if (selectedSlotData) {
|
|
||||||
onRefillDewar(selectedSlotData);
|
|
||||||
} else {
|
|
||||||
alert('Please select a slot to refill its dewar.');
|
|
||||||
}
|
|
||||||
}}>
|
|
||||||
Refill Dewar
|
|
||||||
</Button>
|
|
||||||
</StorageContainer>
|
</StorageContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -351,28 +351,6 @@ const LogisticsView: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRetrieve = async () => {
|
|
||||||
if (!retrievedDewar) {
|
|
||||||
alert('No dewar selected for retrieval.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await LogisticsService.retrieveDewarLogisticsDewarsRetrievePost({
|
|
||||||
dewar_qr_code: retrievedDewar,
|
|
||||||
location_qr_code: '',
|
|
||||||
transaction_type: 'retrieved',
|
|
||||||
});
|
|
||||||
|
|
||||||
alert(`Dewar ${retrievedDewar} retrieved successfully.`);
|
|
||||||
setRetrievedDewar(null);
|
|
||||||
fetchDewarsAndSlots();
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
alert('Error retrieving dewar');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOutgoing = async () => {
|
const handleOutgoing = async () => {
|
||||||
if (!dewarQr) {
|
if (!dewarQr) {
|
||||||
alert('Scan a dewar QR code first.');
|
alert('Scan a dewar QR code first.');
|
||||||
@ -451,9 +429,6 @@ const LogisticsView: React.FC = () => {
|
|||||||
<Button variant="contained" color="secondary" onClick={() => handleRefillDewar()}>
|
<Button variant="contained" color="secondary" onClick={() => handleRefillDewar()}>
|
||||||
Refill Dewar
|
Refill Dewar
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="outlined" color="warning" onClick={handleRetrieve} sx={{ mb: 2 }}>
|
|
||||||
Retrieved
|
|
||||||
</Button>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user